Revise Computingrevisecomputing.co.uk
At a glanceFeaturesStudentsPricingHow it worksFree GCSE notesExam dates
At a glanceFeaturesStudentsPricingHow it worksFree GCSE notesExam dates

Knowledge organisers / Designing, creating and refining algorithms

Trace tables

All topicsPractise exam questions
Knowledge organiser

Designing, creating and refining algorithms

2.1.2g

Create and use trace tables to follow an algorithm

What you need to know

A trace table is used to track the values of variables as an algorithm runs step by step. Each row represents one step of execution, and each column represents a variable. Trace tables help you understand what an algorithm does, check for logic errors, and predict the output of a program without actually running it.

Key points

  • Trace tables have a column for each variable in the algorithm and a column for any output.
  • Each row shows the values after one instruction or iteration has been executed.
  • They are especially useful for tracing through loops to see how values change each iteration.
  • Trace tables help identify logic errors by revealing unexpected variable values.
  • You may be asked to complete a trace table for a given algorithm in the exam.
  • Work through the algorithm line by line, updating values in the table as you go.
  • Exam Tip:Leave the output column BLANK if nothing is printed on that line. Writing "x" or "-" is ambiguous and may lose marks.
  • Exam Tip:Include the correct line number for each change. Line number errors are penalised once, then follow-through is applied.
  • Exam Tip:If a variable does not change on a line, you can either leave it blank or repeat the current value.
  • Exam Tip:Outputs must be exact. For print("The score is", score), the output is 'The score is 4' — not just 4. Do NOT include the comma from the print statement.
  • Exam Example:Tracing staffID = surname + str(year), while staffID.length < 10: staffID = staffID + "x". With 'Kofi' and 2021: Kofi2021 → Kofi2021x → Kofi2021xx. Output on print line: 'ID Kofi2021xx'.
  • Exam Example:Tracing while c < 100: c = c * 10. With c = 9: c becomes 90, then 900. Careful with loop bounds — the loop stops when the condition is False.

Code examples

Algorithm to trace
python
# Trace this algorithm:
x = 1
for i in range(1, 4):
    x = x * i
    print(x)

# Trace table:
# i  |  x  | Output
# ---|-----|-------
# 1  |  1  |  1
# 2  |  2  |  2
# 3  |  6  |  6