Trace Tables
We use Trace Tables to track and monitor the values in an algorithm. A trace table is used to test an algorithm and predict step by step how the computer will run the algorithm. It can be used to to identify potential logic errors
(when the program compiles but does not produce the expected output).
It is probably easier to explain with an example.
iteration (loop) | count | a |
starting condition | 0 | 2 |
1 | 0 | 4 (2*2) |
2 | 1 | 8 (4*2) |
3 | 2 | 16 |
4 | 3 | 32 |
5 | 4 | 64 |
6 | 5 | 128 |
The algorithm keeps looping until the count is = 5 then it stops . The table traces (tracks) the number of loops, the value of count and the value of a.
A common exam question on trace tables is how many times would this algoirthm run. The answer is 6, the table makes it easy to figure this out. This links in with Logic Gates too.