You've designed programs. Now watch them run, trace their state, work out what they do, and fix them when they break. Common algorithms, trace tables, finding purpose, hunting errors — the four skills that separate solid Paper 2 candidates from great ones.
Read this before you tap the activities. These notes give you everything you need to feel confident before the Trace Table Runner and Bug Hunter. When you're ready, tap 🎓 Learn.
You've spent Topic 7.1–7.6 designing programs. Now you'll run them. That means recognising the five common algorithms Cambridge tests (linear search, bubble sort, max, min, average), tracing an algorithm step by step in a table, working out what an algorithm does just by reading it, and finding and fixing errors. Every Cambridge Paper 2 asks a trace-table question — it's the most reliable mark-earner on the paper, and the hardest to bluff.
By the end of Topic 7.7–7.10 you should be able to…
| Term | One-line definition |
|---|---|
| Algorithm | A sequence of steps to solve a problem. |
| Trace table | A table used to step through an algorithm and record every variable value. |
| Linear search | Check each element in turn until the target is found or the list ends. |
| Bubble sort | Compare adjacent pairs; swap if out of order; repeat until no swaps. |
| Counter | A variable that counts occurrences (e.g. how many pass a test). |
| Totaller | A variable that accumulates a running total (also called an accumulator). |
| Iteration | One pass of a loop. |
| Nested loop | A loop inside another loop (bubble sort's core pattern). |
| Flag | A BOOLEAN variable that signals "done" or "found" — often used to exit a loop early. |
| Syntax error | Code that breaks the rules of the language (missing ENDIF, wrong keyword). |
| Logic error | Code that runs but produces the wrong result (> instead of >=). |
| Runtime error | Code that fails while running (dividing by zero, array out of bounds). |
| Algorithm | What it does | Core pattern |
|---|---|---|
| Linear search | Check each element; stop when found | Loop + IF + flag |
| Bubble sort | Repeatedly swap adjacent pairs | Nested loop + swap |
| Max | Track the largest value seen | Loop + IF (>) |
| Min | Track the smallest value seen | Loop + IF (<) |
| Average | Sum + count then divide | Totaller ÷ counter |
| Type | Meaning | Example |
|---|---|---|
| Syntax | Breaks the language rules | Missing ENDIF; NEXT j when the loop was FOR i |
| Logic | Code runs but gives wrong result | Using > when you meant >=; outputting the wrong variable |
| Runtime | Fails during execution | Dividing by zero; accessing Array[11] in a 10-element array |
Given Numbers = [23, 41, 17, 88, 5] and this algorithm:
Max <- Numbers[1]
FOR i <- 2 TO 5
IF Numbers[i] > Max THEN
Max <- Numbers[i]
ENDIF
NEXT i
OUTPUT Max
The trace table:
| i | Numbers[i] | Max | Output |
|---|---|---|---|
| 23 | |||
| 2 | 41 | 41 | |
| 3 | 17 | ||
| 4 | 88 | 88 | |
| 5 | 5 | ||
| 88 |
Note: no quotation marks on 88. Blank cells where variables don't change.
Count <- 0
FOR i <- 1 TO 30
INPUT Score
IF Score >= 50 THEN
Count <- Count + 1
ENDIF
NEXT i
OUTPUT Count
Purpose (in one sentence): It counts how many of 30 input scores are 50 or greater (i.e. how many passed).
Notice the pattern: Count is a counter. The IF is a filter. Loop 30 times = process 30 items.
The trace table Output column stores values, not strings-as-text. Write Found at 3, not "Found at 3". Examiners deduct for the quotes.
Once the algorithm's stopping condition is met, no further rows go in the trace table. A WHILE that exits at i=6 doesn't get a row for i=7.
"It sets Count to 0, then loops from 1 to 30…" is reading the code back, not stating its purpose. Say what it does: "It counts how many scores are ≥ 50."
Bubble sort needs a nested loop: outer for passes, inner for comparisons. A single loop sorts only one pair, not the whole list.
Leave the cell blank — but don't remove the row. Every iteration gets a row; unchanged variables just don't get a value.
Mark-winning tips distilled from the 2023–2025 examiner reports:
Tap each question to reveal the answer. Aim for at least 5 of 6.
Name the five common algorithms. Know the three error types (syntax, logic, runtime). Follow every trace-table rule (record every assignment, no quotes on outputs, stop at loop exit). State an algorithm's purpose in one sentence.
Ready? Tap the 🎓 Learn tab and try the Trace Table Runner — step through three real algorithms and watch the variables update live.
Five algorithms cover almost every Cambridge Paper 2 question: linear search (check each item until found), bubble sort (repeatedly swap adjacent pairs), and three accumulator patterns — max, min and average. Every one of them is tested by tracing — stepping through the code with sample data and recording every variable in a table. If you can trace it, you understand it. Trace tables also help you spot two things: the purpose of an unfamiliar algorithm (7.9) and the errors in a buggy one (7.10). Get comfortable with tracing and this whole section opens up.
Grab a pen and paper. Copy the Max algorithm from Book Notes. Pick your own array of 5 numbers. Draw a trace table with columns for i, Numbers[i], Max, Output. Step through by hand — one row per iteration. If your Max ends as the largest number in your list, you've done it right. That's the skill every trace-table question tests.
Debuggers in real IDEs (VS Code, PyCharm, Visual Studio) are essentially live trace tables. You set a breakpoint, run the program, and the IDE shows you every variable's current value, stepping through one instruction at a time. Learning trace tables is learning how to think like a debugger — a skill you'll use every day as a professional programmer.
Bubble sort is famously inefficient on large data (O(n²)) — modern languages use quicksort or Timsort instead. So why does Cambridge still teach bubble sort? What is the educational value of an "inefficient" algorithm?
Every Paper 2 error-hunting question expects you to identify the type as well as fix the bug. Get the type right and the fix follows.
What: code that breaks the language rules.
When: caught by the compiler/interpreter before the program even runs.
Examples: missing ENDIF, NEXT j when the loop is FOR i, misspelled keyword.
What: code that runs but produces the wrong answer.
When: only visible when you test with data.
Examples: > where you meant >=, outputting the wrong variable, off-by-one in a loop range.
What: code that fails while running.
When: program crashes mid-execution.
Examples: dividing by zero, accessing Array[11] in a 10-element array, reading a file that doesn't exist.
Pick an algorithm, click Step, watch the current line highlight and the trace table build up row by row. This is the exact skill every Paper 2 trace-table question tests.
The five patterns you must recognise. Learn to spot them at a glance.
The Output column stores values, not strings. Write Found at 3, not "Found at 3". Examiners deduct for the quotes every session.
Once the stopping condition is met, no further rows go in the trace table. A WHILE that exits at i=6 doesn't get a row for i=7.
Cited: 2025 s25 · 2024 w24"When tracing an algorithm, each time a variable has a value assigned to it, this needs to be recorded in the trace table." — Cambridge examiner report 2024 w24.
Cited: 2024 w24 examiner reportCambridge wants ONE sentence stating the overall goal — not a walkthrough of every line. "It counts how many scores pass" scores; "It sets Count to 0, then loops 30 times, then…" doesn't.
Cited: 2023 w23 Q4(b), 2024 s24 Q3(b)"Some attempts at the bubble sort only used one loop" — 2024 w24. Bubble sort MUST be nested: outer for passes, inner for comparisons. A single loop only sorts one pair.
Cited: 2024 w24 Q12"Many candidates identified the same error twice with the switching of the Yes and No on one of the decision boxes." When correcting errors, count the DISTINCT bugs, not the same bug from two angles.
Cited: 2024 w24 examiner reportA pseudocode snippet is shown. Which of the five common algorithms is it?
Given the current row of a trace and the next instruction, what's the NEXT row?
An error is described. Is it a syntax, logic, or runtime error?
A short algorithm is shown. State its purpose in one line.
10 rapid questions on algorithms, tracing, errors. Beat your best.
Every question below is drawn from a real Cambridge Paper 2 (2023–2025) or the examiner report describing that question. Type your answer, then reveal the model.
The Output column stores values, not string literals. Never wrap outputs in quotes.
2025 s25 · 2024 w24 (identical wording)Once the stopping condition is met, no further rows go in the trace table.
2025 s25 · 2024 w24Every time a variable is assigned, record it. Even if the value looks the same.
2024 w24 examiner reportIf the question gives 5 inputs, trace all 5. Do not stop after the first.
2025 s25 Q9Purpose = ONE sentence stating the overall goal. Not a walkthrough.
2023 w23 Q4(b), 2024 s24 Q3(b)Bubble sort needs nested loops. Outer for passes, inner for comparisons.
2024 w24 Q12A decision box with swapped Yes/No labels is ONE error, not two. Count distinct bugs.
2024 w24 examiner reportSQL keywords (ASC, DESC, ORDER BY) belong in database queries — not in sort pseudocode.
2024 w24 examiner reportA WHILE that never reaches its terminal condition runs forever. Always check that the loop variable is modified inside the loop.
2024 w24 examiner reportThe five common algorithms.
Linear search · Bubble sort · Max · Min · Average.
The three error types.
Syntax (won't run) · Logic (wrong answer) · Runtime (crashes).
The trace-table checklist.
1. Record every assignment. 2. No quotes on outputs. 3. Stop when the loop stops. 4. Blank cells for unchanged variables.
Nested loops + swap.
Outer loop = passes. Inner loop = adjacent comparisons. IF out-of-order → swap using a temp variable. Optional: flag to exit early when a pass makes no swaps.
State the overall goal, not the steps.
"It counts how many scores pass" ✓
"It sets Count to 0, then loops 30 times, then compares each score…" ✗
Green = secured (≥70%). Yellow = focus (30–69%). Grey = not attempted. Tap any badge to override.