Quiz 3

You have up to 25 minutes. You may use a calculator, but no text book or notes.

  1. Carefully trace the following algorithm. What does it output? Be sure to mark a section of your answer as the output, separate from your scratch work.

    step 1. Let N be 8
    step 2. Set I to 1
    step 3. If I > N then stop.
    step 4. If I < 4 or I is odd, then output I
    step 5. Set I to I+1
    step 6. Go back to step 3.

  2. For each type of statement below, indicate which step(s) from the algorithm in question 1 contain that type of statement.

    1. Output:
    2. Variable assignment:
    3. Conditional:
    4. Loop:

  3. Below is an illustration of an array and two other variables. What are the values of each of the following expressions?

    1. A[0] =
    2. A[X] =
    3. A[Y]+1 =
    4. A[X+1] =
    5. A[A[2]] =