How to Complete a Trace Table: Step-by-Step Guide & Worked Examples
In Cambridge Computer Science exams (Paper 2), trace tables are worth up to 20% of your practical problem-solving mark. A trace table allows you to "dry run" an algorithm line-by-line, tracking how variable values change as loops execute and conditions are evaluated.
🎯 What You Will Learn in This Guide:
- The 3 golden rules of Cambridge trace table scoring.
- How to structure trace table column headers (Variables, Conditions, Outputs).
- 3 step-by-step worked examples (Counter loops, Array searches, Nested loops).
- How to practice with interactive trace table auto-grading online.
The 3 Golden Rules of Trace Tables
Examiners grade trace tables using a strict line-by-line mark scheme. To get full marks every time, strictly follow these rules:
- Only record a value when it changes: Do NOT repeat the previous value in subsequent rows if a variable hasn't changed. Leave that cell empty!
- Follow exact execution order: Write values row-by-row as each instruction executes. Do not skip lines or jump ahead.
- Log output exactly: Write strings, numbers, or prompt outputs in the
OUTPUTcolumn precisely as printed by the algorithm.
Example 1: Tracing a FOR Loop (Counter & Accumulator)
Consider this simple pseudocode algorithm that calculates the sum of numbers from 1 to 4:
Completed Trace Table Solution:
| Line # | Count | Sum | OUTPUT |
|---|---|---|---|
| 2 | 0 | ||
| 3 | 1 | ||
| 4 | 1 | ||
| 5 (Iteration 2) | 2 | 3 | |
| 5 (Iteration 3) | 3 | 6 | |
| 5 (Iteration 4) | 4 | 10 | |
| 6 | Total Sum = 10 |
💡 Notice how cell values are only filled when Sum or Count is modified!
Example 2: Tracing an Array Search with WHILE Loop
This algorithm searches an array Scores[1:4] containing [12, 45, 8, 90] to count how many scores are greater than 20:
Completed Trace Table Solution:
| Index | HighCount | Scores[Index] > 20 | OUTPUT |
|---|---|---|---|
| 1 | 0 | FALSE (12) | |
| 2 | 1 | TRUE (45) | |
| 3 | FALSE (8) | ||
| 4 | 2 | TRUE (90) | |
| 5 | High Scores: 2 |
Practice Trace Tables Online
Use our interactive trace table generator with automated step-by-step validation.
Example 3: Tracing a REPEAT...UNTIL Post-Condition Loop
In a post-condition loop, the loop body always executes at least once before the condition is checked.
Completed Trace Table Solution:
| Num | Product | Product > 20 | OUTPUT |
|---|---|---|---|
| 2 | 1 | ||
| 5 | 2 | FALSE (2) | |
| 8 | 10 | FALSE (10) | |
| 11 | 80 | TRUE (80) | |
| 80 |
Common Mistakes to Avoid in Cambridge Exams
- Mistake 1: Filling values in empty cells when variables haven't changed.
- Mistake 2: Forgetting the final value of loop counter when loop terminates (e.g., in a
FOR i ← 1 TO 5loop,iequals 6 after loop ends). - Mistake 3: Omitting variable quotes in text outputs or misinterpreting operator precedence like
MODandDIV.