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

Q74 · 2210/22/O/N/24 Q4

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

Q742210/22/O/N/24original Q4Structured · 8 marks
Question 4 from 2210/22/O/N/24

Worked solution

(a)

Find the five mistakes and write each fix.

Line 02: STRING should be INTEGER (Counter is a loop counter) [1]

Line 09: Temp ← TRUE should be Swapped ← TRUE [1]

Line 10: OR should be AND [1]

Line 17: ItemList[Counter] ← Temp should be ItemList[Counter + 1] ← Temp [1]

Line 19: ENDCASE should be ENDIF [1]

(b)

Write any three of these points:

A flag (Swapped, set to FALSE at the start of each pass) shows if a swap was made [1]

The flag stops the loop when a pass makes no swap, because the data is sorted [1]

The limit of the inner loop is reduced after each pass (Limit - Pass), so fewer comparisons and repeats are needed [1]

KEY IDEAA flag to stop early and a shorter inner loop after each pass make a bubble sort more efficient.
TOTAL 8 marks

Official mark scheme

Mark scheme for 2210/22/O/N/24 question 4
VIDEO
▶ Topic lesson

A lesson on this topic · by Mr Bulmer's Learning Zone. 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.