Unable to open this exercise
Common exam pitfall
Students often initialize Min to 0, which prevents any positive numbers in the data set from ever replacing the minimum.
Students often initialize Max to 0, which fails completely if all input numbers in the dataset are negative.
A current maximum or minimum must start at a value that is valid for the actual dataset. Guessing 9999 as a minimum fails if every input exceeds 9999; starting a maximum at zero fails for all-negative data.
Worked example
Read the first value, 12000. Set both Minimum and Maximum to 12000. The next value, 15000, changes Maximum only. A later 11000 changes Minimum only. The result is based on observations rather than a guessed limit.
INPUT Value
Minimum <- Value
Maximum <- Value
FOR i <- 2 TO 5
INPUT Value
IF Value < Minimum THEN
Minimum <- Value
ENDIF
IF Value > Maximum THEN
Maximum <- Value
ENDIF
NEXT i
Trace before coding
For -6,-2,-9, the successive (minimum,maximum) pairs are (-6,-6), (-6,-2), (-9,-2). Equal values do not require changing either extreme. Test all-equal, all-negative and large values, not only convenient positive values.
The separate mean lesson combines total and count and handles an empty dataset.
AI Socratic Tutor
Need guidance? Ask a question or use the hint below.
AI Socratic Tutor is an All-Access Benefit
Unlock step-by-step Socratic hints, algorithm trace table walkthroughs, and error diagnostics for every Cambridge exercise.
You're chatting with an AI tutor, not a person. AI can make mistakes, so double-check its answers.
Exam-Style Check: Extreme Value Initialisation Misconceptions
• Multiple ChoiceA weather monitoring station records daily temperatures in the Arctic, where values range from -40°C to -5°C. If the programmer initializes MaxTemp <- 0 before the loop, what will the algorithm erroneously report as the maximum temperature?
Interactive exercises for Module 2 and beyond require an active plan.