Trace tables and finding errors Cambridge IGCSE Computer Science (9–1) revision
Not started
Learn it
In plain words
To check an algorithm without a computer, you become the computer. You work through it one line at a time, writing down every change to every variable. The record you make is a trace table, and the process is called a dry run.
5 things to know
- A trace table has a column for each variable and a column for the output.
- Work through the algorithm one line at a time. Each time a variable changes, write its new value in the next row of its column.
- Write outputs in the output column exactly as they would appear.
- A trace table shows what an algorithm really does, which is how errors are found.
- Common errors to look for: a variable starting at the wrong value, a loop that runs one time too many or too few, and the wrong comparison, such as > where >= is needed.
Worked example
An algorithm sets Total ← 0. A loop FOR Count ← 1 TO 3 inputs Number and does Total ← Total + Number. After the loop it outputs Total. Trace it for the inputs 4, 7 and 2.
- Before the loop: Total is 0.
- Count 1: Number is 4, so Total becomes 4.
- Count 2: Number is 7, so Total becomes 11.
- Count 3: Number is 2, so Total becomes 13.
- The loop ends, and the output is 13.
Tips and tricks
- Never skip a line or do two steps in your head. The marks are for each column being right at every step.
- When correcting an error, give the line and what it should say. "Line 4 should be Count ← Count + 1."
It lands in your notebook with its questions as flashcards.
Trace tables and finding errors: 6 questions and answers
These are the quiz’s questions. Do the quiz first, then come back here for the ones that got you.
What is a dry run?
Each step is followed on paper, usually with a trace table.
What does each column of a trace table usually stand for?
A new value is written whenever a variable changes.
X ← 5. X ← X * 2. X ← X − 3. What is the final value of X?
5 × 2 = 10, then 10 − 3 = 7.
Count ← 0. A loop runs FOR Index ← 1 TO 4 and does Count ← Count + 2. What is Count at the end?
The loop runs four times, adding 2 each time.
A loop should process 10 numbers but is written FOR Count ← 1 TO 9. What kind of error is this?
It runs nine times. It should end at 10.
An algorithm should accept marks of 50 or more as a pass, but uses IF Mark > 50. Which mark shows the error?Stretch
50 should pass, but 50 > 50 is false. The test should be Mark >= 50.
Quiz
6 questions
Tap an answer and you’ll see straight away whether it’s right, and why.
Worksheet
2 questions, 5 marks. Write your answers on paper, then check them.
Trace tables and finding errors
Cambridge IGCSE Computer Science (9–1) 0984 · 5 marks · papermunch.org
Name ______________________________ Date ______________
State the purpose of a trace table.[2]
Show answerHide answer
To record the value of each variable and each output as an algorithm is worked through by hand, so its behaviour can be checked and errors found.
A ← 3. B ← 4. A ← A + B. B ← A − B. State the final values of A and B, showing your working.[3]
Show answerHide answer
A is 7 and B is 3. A becomes 3 + 4 = 7. B becomes 7 − 4 = 3.
Answers: Trace tables and finding errors
- 1. To record the value of each variable and each output as an algorithm is worked through by hand, so its behaviour can be checked and errors found.
- 2. A is 7 and B is 3. A becomes 3 + 4 = 7. B becomes 7 − 4 = 3.



