OCR · GCSE · Computer Science
Course version: J277 · Version from Sept 2022
Designing, creating and refining algorithms: Trace tables
A trace table records how variable values change as an algorithm runs, line by line.
Checked against the OCR J277 specification on .
- Point 5 of 5
Study notes
From the checked teaching notes for this specification point.
The idea
A trace table records how variable values change as an algorithm runs, line by line. Set up a column for each variable, plus columns for output or conditions, then work through the algorithm with a chosen input. At each step, write the new value of any variable that changes, showing the program state after every assignment. Trace tables test an algorithm by hand, find logic errors, and reveal the algorithm's purpose. For example, tracing a loop with inputs 3, 5 and 2 gives running totals 3, 8 and 10, showing the purpose is to sum the inputs. In an exam, you may complete a given table or produce one, so keep columns aligned with variables and update only the cells that change.
What earns the marks
- Creates a column for each variable, output, and condition, allocating a row for each step or iteration of the algorithm.
- Follows the algorithm sequentially, applying assignment, selection, and iteration logic correctly at each step.
- Updates variable values accurately upon change, including counters, running totals, and Boolean flags.
- Records output values exactly at the point they are generated, rather than at the end of the algorithm.
- Uses the completed trace table to identify logic errors, such as an infinite loop or an incorrect running total.
- Analyses the pattern of values and outputs in the table to deduce the overall purpose of the algorithm, such as finding a maximum value.
- Accurately traces boundary cases, such as a loop that executes zero times or an array containing a single item.
Common mistakes and how to put them right
Writing the final value of a variable in every row instead of the value after each step.
Put it right: Update a cell only when that variable changes.
Losing track of which line is being executed inside a loop.
Put it right: Number the lines or mark the current line as you work through each iteration.
Forgetting to record output or a condition result.
Put it right: Include a column for output or for the condition so the full behaviour is visible.
Describing what the algorithm does line by line instead of stating its overall purpose.
Put it right: Summarise the effect of the whole algorithm, for example 'it counts how many values are above 10'.
Exam tips
- Draw the table before starting and label columns with the exact variable names used in the algorithm.
- Work through the algorithm one line at a time and write values as you go; do not try to calculate the final answer first.
- Check the number of iterations against the loop condition so you do not add or miss a row.
- When asked for the purpose, look at the final output and the pattern of values, then state the overall task in one sentence.
Try the lesson
The start of the Designing, creating and refining algorithms: Trace tables lesson, made from checked teaching notes for this specification point.
Have a go first
What is the main purpose of a trace table when testing an algorithm?
Listen
A trace table records how variable values change as an algorithm runs, line by line. Set up a column for each variable, plus columns for output or conditions, then work through the algorithm with a chosen input. At each step, write the new value of any variable that changes, showing the program state after every assignment. Trace tables test an algorithm by hand, find logic errors, and reveal the algorithm's purpose. For example, tracing a loop with inputs 3, 5 and 2 gives running totals 3, 8 and 10, showing the purpose is to sum the inputs. In an exam, you may complete a given table or produce one, so keep columns aligned with variables and update only the cells that change. A strong answer earns marks for these points. Creates a column for each variable, output, and condition, allocating a row for each step or iteration of the algorithm. Follows the algorithm sequentially, applying assignment, selection, and iteration logic correctly at each step. Updates variable values accurately upon change, including counters, running totals, and Boolean flags. Records output values exactly at the point they are generated, rather than at the end of the algorithm. A common slip: Writing the final value of a variable in every row instead of the value after each step. Instead, update a cell only when that variable changes. Exam tip: Draw the table before starting and label columns with the exact variable names used in the algorithm.
There is more to this lesson
The full lesson goes on to check your understanding and help you earn the marks. Create a free account to carry on, with your progress saved.
A week of Premium from your first lesson · Then the free plan continues · No card, no charge
Test your understanding of Designing, creating and refining algorithms: Trace tables
Active recall beats re-reading. Take an instant quiz now to test what you’ve learned and lock it into long-term memory.
A week of Premium from your first lesson · Then the free plan continues · No card, no charge