📁 Topic 1 · 1.1 Algorithms
1.1d Trace tables and identifying errors in algorithms
Edexcel 4CP0 · iGCSE Computer Science · ~10 min read
Notes
──
Video
──
Slides
──
Worksheet
──
Quiz

What is a Trace Table?

A trace table is a technique for manually tracking the values of variables as an algorithm executes step by step. It allows you to check what an algorithm does for a given input without running it on a computer — this is called dry-running or desk checking.

A trace table has one column per variable (plus an output column if needed) and one row per relevant step execution.

How to Complete a Trace Table

  1. Read the algorithm carefully from the start
  2. Create columns for each variable that changes
  3. Work through each step, updating variable values as you go
  4. Record only the changed variable in each row (some exam questions ask for all values each row — follow the instructions)
  5. At loops, repeat the body of the loop and the condition check on each iteration

Trace Table Example

Trace the following algorithm with input n = 4:

SET result TO 1
SET count TO 1
WHILE count <= n DO
SET result TO result * count
SET count TO count + 1
END WHILE
SEND result TO DISPLAY
Stepcountresultcount ≤ n?Output
Init11
Loop 121TRUE
Loop 232TRUE
Loop 346TRUE
Loop 4524TRUE
End524FALSE24

The algorithm calculates n! (factorial). Output: 24

Types of Errors in Algorithms

Error TypeDescriptionExample
Syntax errorCode breaks the rules of the language — cannot be translatedMissing END WHILE; misspelled keyword
Logic errorAlgorithm runs but produces the wrong result — error in the logicUsing < instead of ≤ in a loop condition
Runtime errorAlgorithm crashes during execution due to an impossible operationDividing by zero; accessing an index that doesn't exist

Identifying Errors Using Trace Tables

Trace tables help identify logic errors — the algorithm runs, but the trace shows the variable taking an unexpected value. Compare what the trace table shows against what the algorithm should produce to find where the logic went wrong.

📝 Exam Tip: In Paper 1, trace table questions often ask you to "complete the table" for a given input. Work methodically — do not skip steps. Loop conditions must be checked every time, not just once.
⚠️ Common Mistakes
  • Updating the wrong variable — read each line carefully
  • Not checking the loop condition on every iteration — check it after each pass through the loop body
  • Confusing syntax errors with logic errors — a logic error still runs, it just gives the wrong answer
← 1.1c Pseudocode Topic 1 · 1.1 Algorithms Next: 1.1e Linear Search →
🔒
Pro Content
Subscribe to access all 47 Edexcel iGCSE lessons.
£7.99/month
or £59/year