📘 Paper 2 · Topic 7: Algorithm Design & Problem Solving
7.2b Trace Tables & Desk Checking
Cambridge IGCSE Computer Science 0478 · ~14 min read · ⭐ Pro

What is a Trace Table?

A trace table (also called a dry run or desk check) is a manual method of testing an algorithm by stepping through it line by line and recording the value of each variable at every step.

You create columns for each variable, and one or more columns for any output. For each step of the algorithm, you fill in the current value of every variable that changes.

Why are trace tables used? They are used to: (1) check that an algorithm produces the correct output, (2) identify errors (bugs) in an algorithm, (3) understand what an existing algorithm does. These are key exam marks.

How to Complete a Trace Table

Follow these steps:

  • Create one column per variable (and one for output)
  • Work through the algorithm line by line
  • Only write a new value in a cell when that variable changes
  • Leave cells blank when the variable does not change
  • Write output values in the OUTPUT column when an OUTPUT statement is reached

Example 1 — Simple algorithm

count ← 0
total ← 0
FOR i ← 1 TO 5
    total ← total + i
    count ← count + 1
NEXT i
OUTPUT total
OUTPUT count

Trace table:

itotalcountOUTPUT
00
111
232
363
4104
5155
15
5

Example 2 — Conditional with a WHILE loop

x ← 10
y ← 1
WHILE x > 0 DO
    y ← y * 2
    x ← x - 3
ENDWHILE
OUTPUT y

Trace table:

xyOUTPUT
101
72
44
18
-216
(x = -2, condition x > 0 is FALSE, loop ends)16

Identifying Errors with Trace Tables

A trace table helps find three types of errors:

Error TypeDescriptionExample
Logic errorAlgorithm runs but gives wrong resultUsing < instead of <=, causing loop to miss the last value
Infinite loopLoop condition never becomes falseWHILE count < 10 but count is never incremented
Off-by-one errorLoop runs one too many or too few timesFOR i ← 1 TO 9 when you need 1 TO 10
⚠️ Common Mistakes in Trace Table Questions
  • Writing every value in every cell — only write when a variable CHANGES
  • Getting the loop termination wrong — always check: does the condition use < or <= ?
  • Forgetting the initialisation row (the very first values before any loop)
  • Not knowing whether a WHILE loop can run 0 times (yes it can) — check the starting condition
Video coming soon
Click slide or press arrow keys to navigate
✍️

Worksheet — Trace Tables

4 questions · 10 marks

Q1State two reasons why a programmer might use a trace table. [2]
✅ Mark scheme
Any two: to check an algorithm produces the correct output [1]; to find/identify errors (bugs) in an algorithm [1]; to understand what an existing algorithm does [1]
Q2Complete a trace table for this algorithm and state the output:
a ← 2
b ← 1
FOR i ← 1 TO 4
   b ← b + a
   a ← a * 2
NEXT i
OUTPUT b [4]
✅ Mark scheme
i=1: b=3, a=4 [1]; i=2: b=7, a=8 [1]; i=3: b=15, a=16 [1]; i=4: b=31, a=32 [1]; OUTPUT = 31
Q3What type of error would cause a loop to never terminate? What does it mean for the program? [2]
✅ Mark scheme
A logic error / infinite loop [1]; the program will run forever (crash or become unresponsive / need to be terminated) [1]
Q4Describe what is meant by an 'off-by-one' error and give an example. [2]
✅ Mark scheme
An error where a loop runs one too many or one too few times [1]; e.g., writing FOR i ← 1 TO 9 when the loop should go from 1 to 10 [1]
Quiz — Trace Tables
Q 1 of 7
Score
/ 7
Click to reveal
TermDefinition
🎯

Mini Test — Trace Tables

10 minutes · mixed marks

← 7.2a Pseudocode Topic 7: Algorithm Design Next: 7.3a Linear & Binary Search →
🔒
Pro Content
Upgrade to access all lessons.
£7.99/month
or £59/year
Subscribe now →