Find maximum, minimum and average values
Track extremes and calculate an average without losing the first value or dividing by zero.
Section 7 · Algorithm design and problem-solving
This sequence follows Cambridge IGCSE Computer Science 0478, 2026–2028 syllabus Version 6. It covers subject content Topic 7 only. The separately published 2029–2031 syllabus is not mapped here. Practice is original, self-checked and does not award an official Cambridge grade. Full timed papers and human subject-teacher review remain outstanding.
Before you begin
- No programming language is required. Be comfortable with place value and multiplication; each lesson introduces the computer-science notation it uses.
Work on paper. Try each question before revealing help, and explain why your method works.
Quick readiness check
How is an average calculated from a total and count?
What you will learn
- Initialise maximum and minimum from valid data
- Update extremes correctly
- Calculate average from total and count
Track extremes and average separately
Initialise Maximum and Minimum from the first valid value rather than an arbitrary number that may not fit the data. For each later value, compare it with both extremes and update when needed.
Apply and check the rule
Average equals Total divided by Count. Count every value included in the total, and only calculate the average when Count is greater than zero. If no data is valid, report that no average is available rather than dividing by zero.
Pause and explain
What should the algorithm do if Count is zero?
Worked example
For 8, 3, 10, find the minimum, maximum and average.
Show the worked solution
- Initialise Min=8 and Max=8.
- Compare 3 and 10 with both stored extremes.
- Total=21, Count=3, so Average=7.
Answer Minimum 3; maximum 10; average 7.
Try a topic test
Choose Easy, Normal or Difficult. Save your answers and open worked review after finishing.
Test this topic →From guided practice to a new situation
Write your answer and reasoning first. Use a hint only if you are stuck. The model solution is for self-checking; your written work is not automatically marked.
Find minimum, maximum and average of 6, 9, 3, 6.
Give me a hint
Track extremes, total and number of values.
Compare my reasoning
- Minimum=3 and Maximum=9.
- Total=24 and Count=4.
- Average=24/4=6.
Minimum 3; maximum 9; average 6.
Look for these in your work
- Minimum
- Maximum
- Average
A maximum-finding algorithm starts Max at 0. Give a data set for which it returns the wrong answer and correct the initialisation.
Give me a hint
Try values below zero.
Compare my reasoning
- For −7 and −2, zero is larger than every data value.
- The algorithm incorrectly leaves Max at zero.
- Set Max to the first valid value, then compare remaining values.
For −7 and −2 it returns 0 incorrectly. Initialise Max to the first valid value, −7, then update it to −2.
Look for these in your work
- Counterexample
- Wrong result
- Robust initialisation
A program sums four valid marks but increments Count only for marks above the pass mark. Explain how this affects its average.
Give me a hint
The numerator and denominator must describe the same set of values.
Compare my reasoning
- All four marks are included in Total.
- Only some marks are included in Count.
- Dividing the total by a smaller count overstates the average.
The count no longer matches the values in the total, so the average is too high. Count every mark added to the total.
Look for these in your work
- Set mismatch
- Effect
- Correction
Common mistakes
- Setting Maximum to zero when values can be negative
- Dividing by a count that excludes a value included in the total
What can you explain now?
How should a maximum be initialised for an unknown range of valid values?
Compare with the explanation
Use the first valid value
This avoids an arbitrary starting value that could be larger or smaller than the data.
After trying it yourself, choose your next review. This is your self-assessment.
Your review choice appears on Today. Sign in to sync it across devices.
Make it stick
What values are needed to calculate the average, and how should extremes be initialised?
If you needed the solution, close it and solve the problem again from a blank page. A correct answer is stronger when you can explain the reason for each step.