Analyzing Pseudocode WTW 152
Analyzing Pseudocode WTW 152
These exercises are for your own practice. These will not be handed in or marked.
These exercises are intended to be done by hand with pencil and paper. Their purpose is to gain
experience in how computers follow instructions: Computers do exactly what the instruction says
in that order.
Because humans make mistakes in devising and implementing algorithms, it is vitally important
to be able to perform analyses of algorithms by hand to be able to diagnose errors.
When you are done with analyzing them by hand, try to write code in Python3 that will execute
the given pseudocode.
Question 1.
What is the final length of the list ’L’ if all of the following pseudocode is executed?
- - - - -- - - -- - - -- - -- - - -- - - -- - - -- - -- -- - - - -- - -
Set the list ’L’ to be [1 , 2].
Set the variable ’N’ to have the value 3.
- - - - -- - - -- - - -- - -- - - -- - - -- - - -- - -- -- - - - -- - -
16
Question 2.
How many times will ”step” be printed if the following of pseudocode is executed?
- - - - -- - - -- - - -- - -- - - -- - - -- - - -- - -- -- - - - -- - -
- - - - -- - - -- - - -- - -- - - -- - - -- - - -- - -- -- - - - -- - -
182
2
Question 3.
How many times will ”step” be printed if the following pseudocode is executed?
- - - - -- - - -- - - -- - -- - - -- - - -- - - -- - -- -- - - - -- - -
- - - - -- - - -- - - -- - -- - - -- - - -- - - -- - -- -- - - - -- - -
36
Question 4.
How many times will ”step” be printed if the following pseudocode is executed?
- - - - -- - - -- - - -- - -- - - -- - - -- - - -- - -- -- - - - -- - -
- - - - -- - - -- - - -- - -- - - -- - - -- - - -- - -- -- - - - -- - -
55
Question 5.
What is the final value of the variable x12 if all of the following pseudocode is
executed?
- - - - -- - - -- - - -- - -- - - -- - - -- - - -- - -- -- - - - -- - -
Set the variable x0 to have the value 3.
Set the variable x1 to have the value 2.
Set the variable x2 to have the value 1.
- - - - -- - - -- - - -- - -- - - -- - - -- - - -- - -- -- - - - -- - -
1181
3
Question 6.
What is the final value of the variable p if the pseudocode is executed?
What is the value of 2p (2 to the power p) after pseudocode is executed?
How many times will “step” be printed if t h e pseudocode is executed?
- - - - -- - - -- - - -- - -- - - -- - - -- - - -- - -- -- - - - -- - -
Set the variable p to have the value 0
- - - - - -- - -- - - -- - - -- - - -- - -- - - -- - -- - - - -- - - - -
14, 16384, 14
Question 7.
What is the final value of the variable n if the pseudocode is executed?
How many times will “step” be printed?
- - - - - -- - - -- - -- - - -- - - -- - - -- - -- - -- - - - -- - - - -
Set the variable n to have the value 96
- - - - - -- - - -- - -- - - -- - - -- - - -- - -- - -- - - - -- - - - -
3, 5
Question 8.
- - - - -- - - -- - - -- - -- - - -- - - -- - - -- - -- -- - - - -- - -
29, 1, 2, 13