Cambridge O Level Computer Science 2210 · 7.8 Identifying and correcting errors in algorithms

Q66 · 2210/22/M/J/20 Q3

Worked solution from the Algorithm design and problem-solving Paper 2 Algorithms, Programming and Logic booklet, Part 7 of 8.

Q662210/22/M/J/20original Q3Structured · 10 marks
Question 3 from 2210/22/M/J/20

Worked solution

(a)

Compare each line with what the algorithm should do.

Error 1: line 01. Correction: HighestMark ← 0 (it must start low, not at 100) [1]

Error 2: line 07. Correction: INPUT Mark[Count] (the index is Count, not Counter) [1]

Error 3: line 10. Correction: HighestMarkStudents ← HighestMarkStudents + 1 (add 1, not take away) [1]

Error 4: line 14. Correction: HighestMark ← Mark[Count] (the new highest mark is stored in HighestMark) [1]

(b)

Add a lowest-mark version of the highest-mark code.

LowestMark ← 100
LowestMarkStudents ← 0
FOR Count ← 1 TO 35
    IF Mark[Count] = LowestMark
      THEN
        LowestMarkStudents ← LowestMarkStudents + 1
    ENDIF
    IF Mark[Count] < LowestMark
      THEN
        LowestMarkStudents ← 1
        LowestMark ← Mark[Count]
    ENDIF
NEXT Count
OUTPUT "There are ", LowestMarkStudents, " with the lowest mark of ", LowestMark

Add a variable LowestMark [1]

Set it to a high value, for example 100 [1]

Add a variable LowestMarkStudents [1]

Set it to zero [1]

Check if Mark[Count] = LowestMark and, if true, add 1 to LowestMarkStudents [1]

Check if Mark[Count] < LowestMark and, if true, set LowestMarkStudents to 1 and LowestMark to Mark[Count]. Add an extra output statement for both values. [1]

KEY IDEATrack the best value and how many students share it; a new best value resets the count to 1.
TOTAL 10 marks

Official mark scheme

Mark scheme for 2210/22/M/J/20 question 3
VIDEO
▶ Whole paper

Video solution of the whole paper · by Zafar Ali Khan (ZAK). Tap the picture to open it on YouTube.

Solutions follow the official Cambridge mark schemes; marks are shown in grey. Videos are from other YouTube channels. Paper codes read component / series / year: M/J = May/June, O/N = October/November. Past-paper questions © UCLES, reproduced for classroom practice.