Phase 1: Prepare
Step 1 Warm-up recall
From M1.L2: list the four properties of an algorithm.
Private: nothing you type here is sent or stored.
Step 2 Learning goal
By the end of this lesson you can:
- fill in a trace table for a short algorithm (Foundation);
- use a trace to find where an algorithm goes wrong (Core);
- predict the output before running a method (Core).
Phase 2: Teach
Step 3 A familiar example
A teacher marks a student’s long division by reading each line and checking what changed. A trace does the same for a method: you act as the machine, one step at a time.
Step 4 Clear explanation
To trace an algorithm, you carry out its steps yourself and record every value that changes. A trace table has one row per step and one column per stored value. It is the main way programmers find mistakes, because it shows what the method really does rather than what you think it does.
Trace the largest-number method on the list 4, 9, 2, 7:
| Step | Item looked at | Largest so far |
|---|---|---|
| 1 | 4 (first item) | 4 |
| 2 | 9 | 9 |
| 3 | 2 | 9 |
| 4 | 7 | 9 |
| End | none left | Output: 9 |
Read the table from top to bottom. “Largest so far” starts with the first item, rises to 9 at step 2 and does not change after that, so the output is 9. If a trace shows a value you did not expect, the fault lies in the step that produced it.
Step 5 Worked example (4 marks)
Trace “add each number to a running total, starting at 0” on the list 3, 5, 2.
- Start: total = 0. (1 mark)
- After 3: total = 3. After 5: total = 8. (1 mark)
- After 2: total = 10. (1 mark)
- No items remain, so output 10. (1 mark)
Phase 3: Practise
Step 6 Learner practice (instant-marked)
1. What does a trace table record?
A trace shows how each stored value changes step by step.
2. Trace “largest so far” on 3, 8, 5. What is the output?
The stored value becomes 8 at step 2 and stays 8.
3. Trace a running total from 0 on 4, 4, 4. What is the output?
0 + 4 + 4 + 4 = 12.
4. Why act as the machine when tracing?
Tracing reveals the real behaviour, including mistakes.
Phase 4: Close
Step 7 Recap
- A trace follows the steps by hand and records every changing value.
- A trace table has a row per step and a column per stored value.
- Trace before you trust a method.
Step 8 Exit ticket (ungraded)
Trace “largest so far” on the list 1, 6, 6, 2 and write the final value.
Private: nothing you type here is sent or stored.
Step 9 Go further (Extension)
Invent a four-item list where the largest item is the last one, and trace the method on it.
Common mistakes
| Mistake | Why it fails |
|---|---|
| Skipping steps to save time | The bug hides in the step you skipped. |
| Tracing what you meant, not what is written | Follow the text exactly. |
| Not recording the starting value | Row one should show the initial state. |
Limits. Hand tracing suits short methods. Longer programs use tools that record the trace automatically.