← IGCSE Computer Science Paper 2

Tracing a standard algorithm

A table with a column per variable and a row per step. Use it to test an algorithm such as total, maximum, search or bubble sort by following a short list of values by hand.

Understanding Tracing a standard algorithm in IGCSE Computer Science Paper 2

What it does: In a trace table for one pass, each row shows a comparison and any swap. The largest value moves towards the end. Tracing a maximum, the Max column starts at the first value and changes only when a bigger value is found. A short list lets you record every change of Total by hand, so you can see where an error happens. Bubble sort swaps neighbours when the first is larger than the second. 5 is greater than 3, so they swap. The search checks each item in turn. It matches 7 at position 2, so Found becomes TRUE. Total should be 3, 8, 10. Each row adds the new value to the previous Total, so the final Total is 10.

Common mistakes: Max must start as the first value, Numbers[1]. Tracing 9, 4, 2, 7, 3 with Max starting as 4 gives 7, not 9. It should be Max ← Numbers[1]. The loop adds the counter (1, 2, 3...) instead of the array value. A trace table shows Total as 1, 3, 6... whatever the marks are. It should be Total ← Total + Mark[Index].

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 242–253) and word search (Modules 232–253).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Tracing a maximum algorithm on the list 4, 9, 2. Max starts as 4. What is Max after the whole list is traced?
29
Matches
Trace of a total for 3, 5, 2 shows Total as 3, 5, 2
↓
The Total column shows each value instead of adding to the running total
Applying
Meanings
Term
trace table
Meaning
A table with a column per variable and a row per step. Use it to test an algorithm such as total, maximum, search or bubble sort by following a short list of values by hand.
Practice
// Trace with 4, 9, 2: Max is 4, 9, 9
Testing
Gaps
IF Num[I] Max THEN Max ← Num[I]
Check Answer
Spots
1Max ← Numbers[2]
2FOR Index ← 2 TO 5

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Viperfish' badge — Deep Debugger, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Tracing a maximum algorithm on the list 4, 9, 2. Max starts as 4. What is Max after the whole list is traced?
A. 2
B. 9 ✓
Max only changes when a value is bigger than the current Max. 4 stays, 9 replaces it, 2 is smaller so Max stays 9.
2. Which is the best way to check a totalling algorithm using a trace table?
A. Use a short list such as 3, 5, 2 and follow Total step by step ✓
B. Run it once with a list of 1000 values and only look at the end
A short list lets you record every change of Total by hand, so you can see where an error happens.
3. A trace table for a bubble sort pass on 5, 3, 8 compares 5 and 3. What happens next?
A. They are swapped, giving 3, 5, 8 ✓
B. They are left alone, giving 5, 3, 8
Bubble sort swaps neighbours when the first is larger than the second. 5 is greater than 3, so they swap.
4. A trace of a linear search for the value 7 in the list 2, 7, 9 finishes. What does the trace table show?
A. Found stays FALSE because 7 is not the first item
B. Found is TRUE after the second item is checked ✓
The search checks each item in turn. It matches 7 at position 2, so Found becomes TRUE.
5. Tracing a linear search for 5 in the list 2, 7, 9. What is the value of Found at the end?
A. FALSE, because no item matched ✓
B. TRUE, because the loop reached the end
Reaching the end of the list only means every item was checked. Found is TRUE only if an item matched.

Match the Pairs

Max ← 4, 9, 9, 9 across the rows of a trace table → The maximum is only replaced when a larger value is found, so it stays at 9
Found = FALSE in the last row of a search trace → The search value was not in the list, so the whole list was checked without a match
A bubble sort pass compares neighbours and swaps them if they are in the wrong order → IF List[i] > List[i + 1] THEN swap them
A trace for a maximum starts with Max set to the first item, then updates it → IF Number > Max THEN Max ← Number
Trace of a total for 3, 5, 2 shows Total as 3, 5, 2 → The Total column shows each value instead of adding to the running total
Trace of a search for 7 in 4, 7, 9 carries on to 9 and ends with Found = FALSE → The trace ignores that 7 is found at the second item, so Found should be TRUE

Key Term

trace table
A table with a column per variable and a row per step. Use it to test an algorithm such as total, maximum, search or bubble sort by following a short list of values by hand.

Fill in the Blanks

1. Max ← Num[1] FOR I ← 2 TO 5 IF Num[I] > Max THEN Max ← Num[I]
Hint: Type the relational operator that checks whether the current value is larger than the stored maximum.
2. I ← 1 Found ← FALSE WHILE I <= 5 AND Found = FALSE
Hint: Type the logical operator that keeps the search going only while both conditions are true.
3. // Trace: Found never changes to TRUE IF Found = FALSE THEN OUTPUT "Not found"
Hint: Type the keyword that displays a message after a search that failed.
4. Temp ← Num[I] Num[I] ← Num[I + 1] Num[I + 1] ← Temp
Hint: Type the variable that holds the saved value during a swap in a bubble sort pass.
5. // Num has 5 values: Num[1] to Num[5] FOR I ← 1 TO 4 // compare Num[I] with Num[I + 1]
Hint: Type the last value of I so that I + 1 stays inside a list of five items.

Spot the Error

Question 1
A Max ← Numbers[2]
B FOR Index ← 2 TO 5
C IF Numbers[Index] > Max THEN
D Max ← Numbers[Index]
E ENDIF
F NEXT Index
Line A — Max must start as the first value, Numbers[1]. Tracing 9, 4, 2, 7, 3 with Max starting as 4 gives 7, not 9. It should be Max ← Numbers[1].
Question 2
A Total ← 0
B FOR Index ← 1 TO 5
C Total ← Total + Index
D NEXT Index
E Average ← Total / 5
F OUTPUT Average
Line C — The loop adds the counter (1, 2, 3...) instead of the array value. A trace table shows Total as 1, 3, 6... whatever the marks are. It should be Total ← Total + Mark[Index].
Question 3
A Count ← 0
B FOR Index ← 1 TO 5
C IF Mark[Index] >= 50 THEN
D Count ← Mark[Index]
E ENDIF
F NEXT Index
Line D — Count is overwritten with the mark instead of going up by one, so a trace shows Count jumping to mark values. It should be Count ← Count + 1.
Question 4
A Min ← Numbers[1]
B FOR Index ← 2 TO 5
C IF Numbers[Index] > Min THEN
D Min ← Numbers[Index]
E ENDIF
F NEXT Index
Line C — With > the trace table finds the largest value, not the smallest. To find the minimum the test must be Numbers[Index] < Min.
Question 5
A Found ← TRUE
B FOR Index ← 1 TO 5
C IF Item[Index] = Target THEN
D Found ← TRUE
E ENDIF
F NEXT Index
Line A — Found must start as FALSE. If it starts TRUE, a trace for a target that is not in the list still ends with Found = TRUE. It should be Found ← FALSE.

Student with a class code? Join your class →