SLIDE 1
CSZone.co.uk
Click to advance · Arrow keys also work
Edexcel 1CP2 · Topic 1 · 1.2f

Trace
Tables

Dry-Running Algorithms · Tracking Variables · Identifying Errors

CSZoneEdexcel GCSE Computer Science 1CP2
What is a Trace Table?

Manually Running Code on Paper

A trace table is a method of manually working through an algorithm step by step, recording the value of each variable after every instruction. It is used to check correctness and identify bugs in algorithms.
Create a column for each variable and a column for any output
Fill in each row as you execute each line of the algorithm in order
Very common in Edexcel Paper 1 exam questions — you must be able to complete these
Worked Trace Table Example

Trace this algorithm:

x ← 1    total ← 0
WHILE x <= 3
    total ← total + x
    x ← x + 1
END WHILE
OUTPUT total
xtotalOutput
10
21
33
466
Using Trace Tables to Find Bugs

Spotting Logic Errors

If the output from your trace table doesn't match the expected output, the algorithm has a logic error. Look back through the table to find which row produced an unexpected value — that is where the bug is located.
Check conditions carefully — does < mean <= is needed?
Check initialisations — is the variable set to 0 or 1 at the start?
Check increment — is the counter increasing correctly?
Exam Practice

Have a go at this question

Edexcel-style question
Complete a trace table for the following algorithm with the given input. What is the output?

n ← 4, result ← 1
FOR i ← 1 TO n
  result ← result * i
END FOR
OUTPUT result
4 marks
i=1: result=1; i=2: result=2; i=3: result=6; i=4: result=24 [3 marks for correct trace]. Output = 24 [1 mark]. (This algorithm calculates 4! = 4 factorial)
Key Takeaways

What to Remember

Trace table: manually run an algorithm, recording each variable's value per step
One column per variable + output; one row per executed instruction
Used to verify correctness and locate logic errors
Essential exam skill — practice tracing loops, conditions, and subroutines