How do we check an algorithm works using a trace table and well-chosen test data?
Use a trace table to follow variable values through an algorithm, and choose normal, boundary and invalid test data
A focused answer to the O-Level Computing point on tracing and testing. Building a trace table to track variables through an algorithm, and choosing normal, boundary and invalid test data to find errors.
Reviewed by: AI editorial process; not yet individually human-reviewed
Have a quick question? Jump to the Q&A page
Jump to a section
What this dot point is asking
SEAB wants you to use a trace table to follow the values of variables as an algorithm runs, and to choose good test data: normal, boundary and invalid. The central idea is that tracing lets you check an algorithm by hand, step by step, while well-chosen test data exposes the errors that hide at the edges and outside the expected range.
The answer
What a trace table is
A trace table is a table with one column per variable (plus any output). You work through the algorithm one line at a time, writing down the new value whenever a variable changes. It lets you see exactly what the algorithm does, which is the surest way to find a logic error.
line / step | a | b | output
How to fill a trace table
- Make a column for each variable and for output.
- Start at the first line and work down, in order.
- Each time a variable changes, write its new value in a new row.
- For a loop, go round as many times as the loop runs, writing each pass.
Worked trace
Trace this for input :
x = 5
INPUT y (y = 7)
x = x + y (x = 12)
OUTPUT x
| x | y | output |
|---|---|---|
| 5 | ||
| 5 | 7 | |
| 12 | 7 | 12 |
Choosing test data
Testing checks that a program behaves correctly. Use three kinds of data:
- Normal (valid) data: typical values the program should accept, such as a mark of .
- Boundary data: values right at the edge of the allowed range, such as and , and just outside, such as and .
- Invalid (erroneous) data: values the program should reject, such as or a letter where a number is expected.
Why boundaries matter most
Many bugs hide at the edges of a range, where a programmer might write > instead of >=. Testing the exact limits catches these off-by-one errors that normal data would slip past.
Examples in context
Example 1. Debugging a loop that runs one time too many. A trace table on a loop that should print to but prints to instantly shows the condition uses <= where < was needed. Following the values by hand pinpoints the off-by-one error that staring at the code missed.
Example 2. Testing a login age check. A site requires users to be at least . Boundary tests of , and confirm that exactly is allowed and is not, catching a > versus >= mistake that normal ages like would never reveal.
Try this
Q1. State what each column of a trace table represents. [2 marks]
- Cue. Each column holds the values of one variable (or the output) as the algorithm runs.
Q2. Give an example of boundary test data for a program that accepts ages to . [2 marks]
- Cue. A value at the edge such as or , and just outside such as or .
Q3. Explain why invalid test data should be used. [2 marks]
- Cue. To check the program correctly rejects values it should not accept, rather than crashing or storing bad data.
Exam-style practice questions
Practice questions written in the style of SEAB exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.
Original5 marksTrace this algorithm with a trace table, for the input list , showing the value of total and i at each step.
```
total = 0
FOR i = 1 TO 3
INPUT num
total = total + num
NEXT i
OUTPUT total
```Show worked answer →
Set up columns for i, num, total. Start with total = 0, then process each input.
i num total
- - 0
1 4 4
2 9 13
3 2 15
The loop runs three times, adding , then , then to the running total. The output is the final total, which is .
Markers reward a column per variable, total starting at , each row updating total correctly, and the output .
Original5 marksA program accepts an exam mark from to . (a) Give one example each of normal, boundary and invalid test data for this program. (b) Explain why boundary testing is important.Show worked answer →
(a) Examples:
- Normal data: a typical valid value such as , well inside the allowed range.
- Boundary data: a value at the edge of the range, such as or (and just outside, such as or ).
- Invalid data: a value the program should reject, such as or a letter like 'x'.
(b) Boundary testing is important because errors most often occur at the edges of a range, where a programmer may use the wrong comparison (for example > instead of >=). Testing the exact limits checks that the boundaries are handled correctly.
Markers reward one valid normal value, a value at the limit for boundary, an out-of-range value for invalid, and the point that errors cluster at boundaries.
Related dot points
- Define an algorithm and represent its sequence, selection and iteration using standard flowchart symbols
A focused answer to the O-Level Computing point on algorithms and flowcharts. What an algorithm is, the standard flowchart symbols, and how to show sequence, selection and iteration in a flowchart.
- Write algorithms in pseudocode using input, output, assignment, selection (IF) and iteration (WHILE, FOR)
A focused answer to the O-Level Computing point on pseudocode. Writing algorithms with input, output, assignment, IF selection, and WHILE and FOR loops, in clear language-independent steps.
- Describe and trace linear search and binary search, and explain why binary search needs a sorted list
A focused answer to the O-Level Computing point on searching. How linear search checks each item in turn, how binary search halves a sorted list each step, and why binary search is faster but needs sorted data.
- Describe and trace the bubble sort, explaining how repeated passes of comparisons and swaps sort a list
A focused answer to the O-Level Computing point on sorting. How bubble sort compares neighbouring items and swaps them, how each pass moves the largest value to the end, and tracing the algorithm by hand.
- Define and call Python functions with parameters and return values, and explain the benefits of using functions
A focused answer to the O-Level Computing point on Python functions. Defining functions with def, passing parameters, returning values, the difference between a parameter and an argument, and why functions make programs reusable.