πŸ“š Knowledge Library β€” Topic 7.8 β€” Algorithm Design & Problem Solving

Trace Tables Explained Simply

Learn how to dry-run an algorithm one instruction at a time and record changing variable values and outputs accurately.

1. Invitation

A trace table slows an algorithm down so you can see what it is doing.

A trace table records the changing values of variables as an algorithm runs.

It allows programmers to dry-run the logic without executing the program on a computer.

πŸ’‘ Key idea: follow one instruction at a time and record only what changes.
Figure 1.1
Slow the Algorithm Down
Instruction
↓
Value changes
↓
Record change
↓
Next instruction
2. Big Idea

Each column tracks one important part of the algorithm.

Variables normally receive their own columns. Inputs and outputs may also need separate columns.

A new value is entered only when that value changes or when an input or output occurs.

πŸ’‘ The table is a record of events, not a copy of every line of code.
Figure 2.1
Typical Columns
Input
Counter
Total
Output
3. FutureLogic Bridge

Think of a football commentator recording every important moment.

The commentator follows the match in order and records events when something changes: a goal, a substitution or the final whistle.

A trace table does the same for an algorithm. It records important changes in the order they happen.

πŸ’‘ Bridge: the algorithm plays; the trace table keeps the match report.
Figure 3.1
Record the Events
Kick-off
↓
Score changes
↓
Record event
↓
Continue
4. Start with Initial Values

Initialisation is part of the trace.

If an algorithm sets Total ← 0 or Count ← 1, those values should appear before the loop begins.

Missing initial values can make every later calculation incorrect.

🎯 Exam Tip: look above the loop for variables that are initialised before any input is processed.
Figure 4.1
Before the Loop
Total ← 0
Count ← 1
↓
Loop begins
5. Work One Line at a Time

Do not try to solve the whole algorithm in your head.

1Read the next instruction.
2Work out what changes.
3Record the new value.
πŸ’‘ Repeat the same three steps until the algorithm stops.
6. Follow Loops Carefully

A loop may update the same variable many times.

Each pass through a loop must be traced separately.

Check the condition, perform the instructions, update the counter and then return to the condition.

πŸ’‘ Loop pattern: check β†’ run β†’ update β†’ check again.
Figure 6.1
Loop Cycle
Check condition
↓
Run body
↓
Update value
β†Ί
7. Record Output Only When It Happens

The OUTPUT column is not a working column.

Write something in the OUTPUT column only when the algorithm executes an OUTPUT statement.

Do not place calculations, variable names or predicted answers there unless the algorithm actually displays them.

⚠️ Common Mistake: filling the OUTPUT column on every row.
Figure 7.1
Output Rule
OUTPUT statement?
↓
Yes β†’ record it
No β†’ leave blank
8. Sentinel Values

Some inputs tell the algorithm to stop.

A sentinel value is a special input that ends a loop, such as -1, 0 or the letter N.

The sentinel is normally recorded as an input, but data after it is not processed.

πŸ’‘ Once the stop value is reached, ignore any remaining unused input data.
Figure 8.1
Stop Signal
Input values
↓
Sentinel found
↓
Algorithm stops
9. Computational Thinking

Trace tables turn logic into evidence.

SkillHow it appears
DecompositionThe algorithm is followed one instruction at a time.
Pattern recognitionRepeated loop behaviour becomes visible.
AbstractionOnly relevant variables and outputs are recorded.
Algorithmic thinkingThe exact execution order is followed.
πŸ’‘ A trace table helps prove what the algorithm actually does.
Figure 9.1
Follow the Evidence
Instruction
↓
Change
↓
Record
↓
Check logic
10. Worked Example

Trace an algorithm that totals three numbers.

AlgorithmInput data: 4, 7, 2
Total ← 0
FOR Count ← 1 TO 3
  INPUT Number
  Total ← Total + Number
NEXT Count
OUTPUT Total
CountNumberTotalOUTPUT
0
144
2711
3213
13

How the table was completed

Total begins at 0. Each input is added during one pass of the loop. The final value is written in the OUTPUT column only after the loop ends.

Model answer: β€œThe algorithm adds 4, 7 and 2 to Total. After three loop iterations, Total is 13, so 13 is output.”
11. Reading a Trace Table

Each row tells part of the story.

The first row records the initial value of Total.

The next three rows show the three loop passes. The final row records the output after the loop has finished.

πŸ’‘ Read down the table in time order, not across it as one calculation.
Figure 11.1
Rows Represent Time
Initial state
↓
Pass 1
↓
Pass 2
↓
Pass 3
↓
Output
12. Exam Tip

Use blank cells carefully.

A blank cell means that no new value was recorded at that point.

Do not repeatedly copy every unchanged value unless the table format clearly expects it.

🎯 Exam Tip: follow the style already used in any completed rows provided by the question.
Figure 12.1
Record Changes
Value changed?
↓
Write new value

No change?
Leave blank
13. Common Mistakes

Most errors come from moving too quickly.

βœ— Common mistakes

Skipping initial values, missing a loop pass, processing data after a sentinel and adding extra output.

βœ“ Better method

Use a finger or ruler to follow one instruction, update one row and then move to the next instruction.

⚠️ Accuracy is more important than speed. One missed instruction can affect every later row.
14. Summary

Trace tables in one screen.

A trace table records variable values, inputs and outputs as an algorithm runs.

Initial values must be included, loops must be followed one pass at a time and output is recorded only when an OUTPUT statement executes.

A sentinel value stops processing, so later input data is ignored.

πŸ’‘ Final thought: read one line, record one change, then move on.
Figure 14.1
Final Model
Initialise
↓
Trace
↓
Record changes
↓
Stop correctly