← IGCSE Computer Science Paper 2

Finding the maximum and minimum in pseudocode

Finds the largest value: set Max to the first value, loop through the rest, and replace Max whenever a larger value is found. The minimum works the same way using < instead.

Understanding Finding the maximum and minimum in pseudocode in IGCSE Computer Science Paper 2

What it does: The > operator tests whether the new value beats the current Max, and if so it is stored in Max. The first element is already stored in Max, so the loop only needs to check the rest, starting at index 2. Max is set to the first element, so it begins as a real value from the data. The first element is Scores[1] in IGCSE pseudocode arrays. A larger value means Value is greater than Max, so use >. Using < would find the minimum instead. Assignment in IGCSE pseudocode uses the ← arrow. The = sign is for comparison.

Common mistakes: The assignment is the wrong way round. This line would overwrite the array element with Max and Max would never change. It should be Max ← Mark[Index] so the new largest value is stored in Max. Max must start as the first element, not 0. If every temperature is below 0 (for example -5), Max would stay at 0, which is not in the data. It should be Max ← Temp[1].

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
Which line correctly starts the search for the largest value in an array called Scores?
Max ← Scores[1]Max ← Scores[0] + 1
Matches
Max ← 0
↓
Starting Max at 0 is wrong because if every value is negative, Max stays 0, which is not in the data. Start with the first element instead.
Applying
Meanings
Term
IF Value > Max THEN Max ← Value
Meaning
Finds the largest value: set Max to the first value, loop through the rest, and replace Max whenever a larger value is found. The minimum works the same way using < instead.
Practice
Max ← Marks[1]
Testing
Gaps
Max ← Scores[]
Check Answer
Spots
3 IF Mark[Index] > Max THEN
4 Mark[Index] ← Max

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

The 'Ostrich' badge — Full Sprint, 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. Which line correctly starts the search for the largest value in an array called Scores?
A. Max ← Scores[0] + 1
B. Max ← Scores[1] ✓
Max is set to the first element, so it begins as a real value from the data. The first element is Scores[1] in IGCSE pseudocode arrays.
2. Which comparison replaces Max when a larger value is found?
A. IF Value > Max THEN ✓
B. IF Value < Max THEN
A larger value means Value is greater than Max, so use >. Using < would find the minimum instead.
3. Which comparison is used to find the smallest value?
A. IF Value > Min THEN
B. IF Value < Min THEN ✓
To find the minimum, replace Min whenever Value is smaller than Min, so use <.
4. All the numbers in a list are negative, for example -5, -2 and -9. Which way of starting Max works?
A. Set Max to the first number in the list ✓
B. Set Max to 0 before the loop
If Max starts at 0, no negative number is ever larger, so the answer would wrongly be 0. Starting with the first element always works.
5. What is the main reason for setting Max to the first element rather than 0?
A. The starting value is guaranteed to be one of the real data values ✓
B. Zero is not allowed as a value in pseudocode
Zero is allowed, but it might not be in the data and could be larger than every value. The first element is always a real value to compare against.

Match the Pairs

Max ← Numbers[1] → Start the maximum by storing the first value in the list, so Max begins as a real value from the data
IF Value < Min THEN Min ← Value → Replace the minimum whenever the current value is smaller than the smallest found so far
To find the largest value, replace Max only when the current value is bigger than Max → IF Value > Max THEN Max ← Value
Start Max as the first element, then loop through the remaining elements from position 2 → FOR Index ← 2 TO 10
Max ← 0 → Starting Max at 0 is wrong because if every value is negative, Max stays 0, which is not in the data. Start with the first element instead.
IF Value > Min THEN Min ← Value → The wrong operator is used. To find the minimum, the test must be Value < Min, so Min is replaced by smaller values.

Key Term

IF Value > Max THEN Max ← Value
Finds the largest value: set Max to the first value, loop through the rest, and replace Max whenever a larger value is found. The minimum works the same way using < instead.

Fill in the Blanks

1. Max ← Scores[1] FOR Index ← 2 TO 10
Hint: Type the index number of the first element in the array, so Max starts with a real value instead of an arbitrary number like 0.
2. IF Scores[Index] > Max THEN Max ← Scores[Index] ENDIF
Hint: Type the relational operator that checks whether the current value is larger than the largest so far.
3. IF Value < Min THEN Min ← Value ENDIF
Hint: Type the relational operator that checks whether the value is smaller than the smallest so far.
4. IF Value < Min THEN Min ← Value ENDIF
Hint: Type the variable that stores the smallest value found so far and is replaced when a smaller one appears.
5. Max ← Scores[1] FOR Index ← 2 TO 10 IF Scores[Index] > Max THEN
Hint: Type the index where the loop begins: the position just after the element already stored in Max.

Spot the Error

Question 1
A Max ← Mark[1]
B FOR Index ← 2 TO 10
C IF Mark[Index] > Max THEN
D Mark[Index] ← Max
E ENDIF
F NEXT Index
Line D — The assignment is the wrong way round. This line would overwrite the array element with Max and Max would never change. It should be Max ← Mark[Index] so the new largest value is stored in Max.
Question 2
A Max ← 0
B FOR Day ← 2 TO 7
C IF Temp[Day] > Max THEN
D Max ← Temp[Day]
E ENDIF
F NEXT Day
Line A — Max must start as the first element, not 0. If every temperature is below 0 (for example -5), Max would stay at 0, which is not in the data. It should be Max ← Temp[1].
Question 3
A Min ← Cost[1]
B FOR Item ← 2 TO 6
C IF Cost[Item] > Min THEN
D Min ← Cost[Item]
E ENDIF
F NEXT Item
Line C — To find the minimum you replace Min when a SMALLER value is found, so the condition needs < not >. With > this would find the maximum. It should be IF Cost[Item] < Min THEN.
Question 4
A Max ← Height[1]
B FOR N ← 2 TO 5
C IF Height[N] > Max THEN
D Max ← N
E ENDIF
F NEXT N
Line D — Max would store the position (the counter N) instead of the height value. It should be Max ← Height[N] so that Max holds the largest value found.
Question 5
A Min ← 0
B FOR Pos ← 2 TO 10
C IF Age[Pos] < Min THEN
D Min ← Age[Pos]
E ENDIF
F NEXT Pos
Line A — Starting Min at 0 means no age will ever be smaller, so Min would never be replaced and the answer would be wrong. Min must start as the first element: Min ← Age[1].

Student with a class code? Join your class →