Interpreting, correcting and completing algorithms Flashcards
What are dry runs, how are they used, and why are they helpful?l
A method used to investigate the functioning of an algorithm
Mental or pen/paper run through of an algorithm that does one step at a time
The following are examined at each step:
- inputs needed
- data processed
- outputs
A dry run helps you to understand an algorithm and find any errors
What are trace tables, how are they used and why?
A trace table is used while the dry run is being worked through to write down the values of each variable, input, output and how they change as the program is running
There are columns for each variable and rows for each step in the algorithm
It is helpful as it makes it easy to keep track
Create a trace table for the following algorithm.
number = 3 for index = 1 to 3 number = number + index print(number) next index
[4]
Number index output
3
4 1 4
6 2 6
9 3 9
Investigate the following algorithm and create a trace table using these values.
At the start of the following algorithm, X = 2 and Y = 3
Z = X + Y while X < Z X = X + 1 Y = Y + X endwhile print(Y)
(Each section is one row of the table)
Z: 5
X: 3
Y: 6
Output:
Z: 5
X: 4
Y: 10
Output:
Z: 5
X: 5
Y: 15
Output:
Z:
X:
Y:
Output: 15
Create a trace table for the following algorithm
number = 3 print(number) for index = 1 to 3 number = number + 6 print(number) next x
(Each section is one row of the table)
number: 3
index:
output: 3
number: 9
index: 1
output: 9
number: 15
index: 2
output: 15
number: 21
index: 3
output: 21