← IGCSE Computer Science Paper 2

Tracing maximum and minimum algorithms

In a trace table, Largest only changes on rows where this test is true. If Number is equal or smaller, the Largest cell stays the same as the row above. Smallest uses < instead.

Understanding Tracing maximum and minimum algorithms in IGCSE Computer Science Paper 2

What it does: The middle column shows the result of the test. The row with FALSE keeps Largest at 9, while the TRUE row stores the new value. 4 is less than 8, so the test is true and Smallest is updated to 4 on this row. 20 > 12 is true, so this is a row where the Largest cell changes. A tie never makes the comparison true, so Smallest does not change. The value is the same as the row above. When tracing Largest and Smallest together, each column must be checked separately. Largest stays 5, but Smallest becomes 2.

Common mistakes: Largest should only change when the new Number is bigger, so the test must use >. With < the trace table would store smaller values and Largest would go down instead of up. Every IF in Cambridge pseudocode needs THEN at the end of the condition line. It should be IF Number < Smallest THEN.

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 286–295) and word search (Modules 275–295).

Take this worksheet further — free with Cloodit

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

Learning
Duo
A trace table row has Largest = 5 and Number = 3. What is Largest after IF Number > Largest THEN?
Largest stays 5, because 3 > 5 is falseLargest becomes 3, because Number is the newest value
Matches
Number = 3, Largest = 8 3 > 8 is TRUE, so Largest becomes 3
↓
3 > 8 is FALSE, not TRUE. Largest must stay 8 because 3 is smaller, so it must not change to 3.
Applying
Meanings
Term
IF Number > Largest THEN
Meaning
In a trace table, Largest only changes on rows where this test is true. If Number is equal or smaller, the Largest cell stays the same as the row above. Smallest uses < instead.
Practice
INPUT Number
Testing
Gaps
IF Number Largest THEN
Check Answer
Spots
3INPUT Number
4IF Number < Largest THEN

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

The 'Hyena' badge — Savannah 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. A trace table row has Largest = 5 and Number = 3. What is Largest after IF Number > Largest THEN?
A. Largest becomes 3, because Number is the newest value
B. Largest stays 5, because 3 > 5 is false ✓
The Largest cell only changes when Number > Largest is true. Here it is false, so the cell copies the value from the row above.
2. Largest = 7 and the next Number is also 7. What happens in the trace table?
A. Largest is updated to 7, because the values are equal
B. Largest stays 7, because 7 > 7 is false ✓
A tie does not make the test true. Equal is not greater, so the stored value stays the same.
3. Smallest = 8 and Number = 4. What goes in the comparison column for IF Number < Smallest?
A. TRUE, so Smallest changes to 4 ✓
B. FALSE, so Smallest stays 8
4 is less than 8, so the test is true and Smallest is updated to 4 on this row.
4. Largest = 12 and Number = 20. Which is correct for this row of the trace table?
A. Comparison TRUE, Largest becomes 20 ✓
B. Comparison FALSE, Largest stays 12
20 > 12 is true, so this is a row where the Largest cell changes.
5. The data is 4, 9, 6, 9, 11 and Largest starts at 4. How many times does the Largest cell change after the start?
A. 2 times (to 9, then to 11) ✓
B. 3 times (to 9, to 9 again, then to 11)
The second 9 is a tie with Largest, so 9 > 9 is false and nothing changes. Only 9 and 11 are bigger.

Match the Pairs

IF Number > Largest THEN Largest ← Number → Largest changes only on rows where Number is strictly bigger than the stored Largest; otherwise its trace table cell is copied down unchanged.
IF Number < Smallest THEN Smallest ← Number → Smallest changes only on rows where Number is strictly lower than the stored Smallest; otherwise its cell stays the same as the row above.
A comparison column in the trace table records TRUE or FALSE for the test. Largest changes only on TRUE rows. → Number | Number > Largest | Largest 9 | TRUE | 9 4 | FALSE | 9
A tie does not change the stored value: if Number equals Largest, the test Number > Largest is FALSE. → Largest = 7, Number = 7 7 > 7 is FALSE, so Largest stays 7
Number = 3, Largest = 8 3 > 8 is TRUE, so Largest becomes 3 → 3 > 8 is FALSE, not TRUE. Largest must stay 8 because 3 is smaller, so it must not change to 3.
Number | Largest | Smallest 5 | 5 | 5 2 | 5 | 5 → On the row where Number is 2, Smallest should change to 2 because 2 < 5 is TRUE. Smallest was wrongly left at 5.

Key Term

IF Number > Largest THEN
In a trace table, Largest only changes on rows where this test is true. If Number is equal or smaller, the Largest cell stays the same as the row above. Smallest uses < instead.

Fill in the Blanks

1. IF Number > Largest THEN
Hint: Type the comparison operator that is true only when the new number is strictly bigger than the stored largest.
2. IF Number < Smallest THEN
Hint: Type the comparison operator that is true only when the new number is strictly lower than the stored smallest.
3. IF Number > Largest THEN Largest ← Number ENDIF
Hint: Type the variable whose value is copied into Largest on a row where the test is true.
4. IF Number > Largest THEN Largest ← Number ENDIF
Hint: Type the variable holding the best value so far, which the new number is compared against.
5. IF Number < Smallest THEN Smallest ← Number ENDIF
Hint: Type the keyword that closes the IF structure.

Spot the Error

Question 1
A INPUT Number
B Largest ← Number
C INPUT Number
D IF Number < Largest THEN
E Largest ← Number
F ENDIF
Line D — Largest should only change when the new Number is bigger, so the test must use >. With < the trace table would store smaller values and Largest would go down instead of up.
Question 2
A Smallest ← 100
B INPUT Number
C IF Number < Smallest
D Smallest ← Number
E ENDIF
Line C — Every IF in Cambridge pseudocode needs THEN at the end of the condition line. It should be IF Number < Smallest THEN.
Question 3
A Largest ← 0
B Smallest ← 100
C INPUT Number
D IF Number > Smallest THEN
E Largest ← Number
F ENDIF
Line D — The test that decides whether Largest changes must compare Number with Largest, not Smallest. It should be IF Number > Largest THEN.
Question 4
A Largest ← Mark[1]
B FOR N ← 2 TO 8
C IF Mark[N] > Mark[N-1] THEN
D Largest ← Mark[N]
E ENDIF
F NEXT N
Line C — This compares each mark with the previous mark, not with the stored maximum. Largest must be the thing being compared: IF Mark[N] > Largest THEN.
Question 5
A Largest ← 0
B INPUT Number
C IF Number > 0 THEN
D Largest ← Number
E ENDIF
Line C — The comparison must be against the stored value Largest, not 0. Testing against 0 is true for every positive number, so Largest would change on almost every row of the trace table.

Student with a class code? Join your class →