Algorithm Design and Problem Solving · 4 question types
Past paper frequency (2018 to 2024)
This topic accounts for approximately 11% of your exam marks.
The most marks-dense topic. Both papers test pseudocode writing and trace tables every sitting.
A trace table is a table used to record the value of each variable at every step of an algorithm, so that the algorithm can be hand-executed and checked for correctness.
Trace tables are essential for finding logic errors, where a program runs without crashing but produces the wrong output. By stepping through the algorithm with specific test data, the programmer can spot the exact step where the variables go wrong.
OUTPUT statement is reached.Highest does not update when it should, the trace table reveals the exact step where the bug is.Complete the trace table for this algorithm
The algorithm below reads four numbers one at a time and accumulates a running total. Complete the trace table for the inputs 3, 7, 2, 8 in that order.
total ← 0
FOR i ← 1 TO 4
INPUT num
total ← total + num
NEXT i
OUTPUT total
Solution:
| i | num | total | OUTPUT |
|---|---|---|---|
| — | — |
| 0 |
| 1 | 3 | 3 |
| 2 | 7 | 10 |
| 3 | 2 | 12 |
| 4 | 8 | 20 |
| — | — | — | 20 |
Key points when filling in a trace table:
OUTPUT statement is reached (after the loop ends here).i updates at the start of each iteration; num and total update in that same pass through the loop body.