CS 3304 Homework Assignment 4

25 Points
Due: 10/04 at the start of class

Note: The following instructions are repeated from the Homework Dates/Guidelines page:

Your solutions for each homework assignment must be prepared with a word processor (e.g., LaTeX or Word), and are due at the beginning of class on the due date specified unless otherwise noted on the assignment itself.

Note that all homework problems taken from the text are in the Problem Sets. Do not turn in solutions to Review Questions by mistake!

Complete each of the following problems:

  1. Find the weakest precondition for the following code segment, where A is a Pascal-style array declared as array [1..100] of integer:
        max := 0;
        i := 1;
        while i <= 100 do
        begin
            if A[i] >= max then
                max := A[i];
            i := i + 1;
        end;
        { max = largest element in A }
    
    Note: Coming up with the proper loop invariant will probably require you to devise your own formula that describes the postcondition in mathematical terms.

  2. Chapter 15, Problem 5 (p. 627 of 5E text, in 4E: Chapter 14, Problem 12 on p. 603)

  3. Chapter 15, Problem 4 (p. 627 of 5E text, in 4E: Chapter 14, Problem 12 on p. 603)