2210/22/O/N/24 question 4: worked solution (October/November 2024, paper 22)

Show as plain text

Cambridge O Level Computer Science 2210 · 7.8 Identifying and correcting errors in algorithms Worked solution from the Algorithm design and problem-solving Paper 2 Algorithms, Programming and Logic booklet, Part 7 of 8. Q74 2210/22/O/N/24 original Q4 Structured · 8 marks 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 IDEA A flag to stop early and a shorter inner loop after each pass make a bubble sort more efficient. TOTAL 8 marks Official mark scheme VIDEO ▶ Topic lesson A lesson on this topic · by Mr Bulmer's Learning Zone. Tap the picture to open it on YouTube.