Algorithms and programming · GCSE Computer Science
Trace tables
GCSE Computer Science trace tables: one column per variable, one line of the algorithm at a time, and the off-by-one errors that drop the last output mark.
A trace table is a slow-motion camera: one instruction, one row, every named variable. Never update two cells in your head.
The important bits
What you need to know
- 1
A trace table records the value of each variable (and often an output column) as an algorithm executes. Copy the column headings from the question; extra invented columns rarely score.
- 2
Work one line at a time in the order the algorithm actually runs. After an assignment, write the new value in that variable’s column and leave other columns blank or unchanged according to the paper’s convention.
- 3
Selection (IF) only changes values on the branch that is true. Write the condition’s result if the table has a column for it; otherwise still decide the branch on paper before you write anything else.
- 4
Iteration means the same lines can produce several rows. WHILE tests the condition with the current values; if it is true, the body runs and you add another row. FOR loops need the loop counter in its own column.
- 5
Off-by-one errors are the classic miss: a loop that should run n times runs n−1 or n+1 because the condition used > instead of >=, or the counter started at 1 in a 0-based list.
- 6
Integer division (DIV or //) and MOD belong in separate mental boxes. 17 DIV 5 is 3; 17 MOD 5 is 2. Mixing them is a common last-column disaster.
- 7
When the algorithm prints inside a loop, every print is a separate output. Concatenate only if the paper’s output column is a running string; otherwise list each output on its own row.
- 8
Finish the table. The last comparison, the last increment, and the output after the loop are where remaining marks sit. Stopping when you “can see the answer” is how the final row vanishes.
Quotations worth analysing
Short evidence. Real method.
“Complete the trace table.”
Every cell the mark scheme expects must be filled from the printed algorithm, not from a rewritten version you prefer. One skipped assignment costs a row of follow-through.
“Show the value of each variable after each instruction.”
After each instruction, not after each block. Updating total and count in the same mental step is how both columns drift.
“The loop condition is tested before the body of a WHILE.”
If the condition is already false, the body never runs and the table may have only the initialisation rows. Do not invent a first pass.
Go deeper
Columns are a contract with the mark scheme
If the paper prints columns for x, y and output, those are the only names that score. Do not add a “working” column unless you need it on scrap paper. Initialise from the first assignment in the algorithm, not from a guess about what the programmer meant. When a WHILE condition is tested, the values in the table are the values at that moment — then you decide whether the body runs. Students lose the last row because they stop when the pattern looks obvious. The last comparison, the last increment, and the output after the loop are often separate marks. If the paper uses integer division, write DIV or // and keep the remainder out of the quotient column. Treat every line as if the examiner is watching your pencil, because they are.
Go deeper
Off-by-one is a condition error, not bad luck
A loop that should process five items and processes four is not a mystery. Trace the counter: if i starts at 0 and the test is i < 5, you get i = 0,1,2,3,4 — five passes. If you write i <= 5 you get a sixth pass or an index that does not exist. If the algorithm says FOR i ← 1 TO n and the array is indexed from 0, the first item is never visited. Write the condition in words beside the table for one second: “keep going while i is less than the length.” Then fill the row. Boundary items — the first index and the last index — are where papers hide the mark. Dry-run a three-item list on purpose; it is long enough to show the pattern and short enough that you will not skip a row.
See the idea in action
Trace this algorithm. total ← 0 count ← 0 WHILE count < 3 total ← total + count count ← count + 1 ENDWHILE OUTPUT total Columns: total | count | output Row 1: total = 0, count = 0. Test count < 3 → 0 < 3 true. Row 2: total = 0, count = 1. Test 1 < 3 true. Row 3: total = 1, count = 2. Test 2 < 3 true. Row 4: total = 3, count = 3. Test 3 < 3 false. Output 3. If you add count before total, you get 6 and lose the question. The off-by-one trap is treating WHILE as “repeat 3 times starting at 1”.
Exam technique
Turn knowledge into marks
Tick each line of the printed algorithm as you use it. Fill the table before you answer “what is the output”. Reading the code like a paragraph is how an off-by-one survives.
Common mistakes
Do not give these marks away
- 01
Updating two variables in one mental step and writing both new values as if they happened together before either assignment finished.
- 02
Stopping the table when the pattern looks obvious and missing the final condition test or the output after the loop.
- 03
Running a WHILE body once even when the condition is already false on the first test.
In a trace table, what should you do after each assignment in the algorithm?
ARewrite the algorithm in Python first
BWrite the new value in that variable’s column before moving to the next line
COnly fill the output column until the program ends
DSkip loop conditions because they do not change variables
Show the answer
Write the new value in that variable’s column before moving to the next line. A trace table is one instruction at a time. The new value of the assigned variable must be recorded before the next line uses it. Skipping conditions or filling only the output is how later rows go wrong.
Quick questions
If this is the bit you searched
How do you complete a trace table GCSE Computer Science?
Copy the column headings, initialise from the first assignments, then execute one line at a time. Add a new row when a variable changes. Test loop conditions with the current values, and do not stop before the final output.
Do I write a value in every column on every row?
Follow the paper. Some boards want only the changed cell; some want the current value of every variable on each row. Never leave a changed variable blank.
What is an off-by-one error in a trace table?
The loop runs once too often or once too few, usually because the condition used the wrong comparison or the counter started at the wrong index. The first and last items are the usual victims.
Should I trace in my head to save time?
No. Marks are on the table. A three-line dry-run in your head is how total and count both drift. Pencil is faster than a wrong output.