Mon 3 Mar
You have up to 25 minutes. You may use a standard calculator if necessary, but no text book or notes.
This problem is about the concept of a variable in an algorithm. Recall that a variable is a named storage location. Trace the values of X, Y, and Z through the following instructions.
1. Set X to 3
2. Set Y to X + 2
3. Set Z to Y * Y (multiply)
4. Set Y to X + 5
This problem is like the previous one, but we add one conditional statement, which executes or doesn’t depending on a Boolean condition.
1. Set J to 5
2. Set K to J + 2
3. If K > 8 then Set J to J - 2
4. Set K to K + 1
The condition K>8 is false when we encounter it, so the rest of step 3 is skipped.
Carefully trace the following algorithm. What does it output?
1. Set A to 1.
2. Set B to 1.
3. Output A
4. Output B
5. If B > 8 then stop.
6. Set X to A + B
7. Copy B to A
8. Copy X to B
9. Go back to step 4.
This algorithm produces a sequence called the Fibonacci numbers. The sequence starts with 1, 1, and then each subsequent number is the sum of the previous two. The sequence has lots of interesting properties.
The following statements are about pseudo-code. Mark each as true or false.
Pseudo-code is based on English, but used in a very precise way to avoid ambiguity. TRUE
Compared to a programming language, pseudo-code can be understood more easily by humans. TRUE
Pseudo-code can also be executed by a computer. FALSE
We call it pseudo code because it is very fast. FALSE