In the exam
9618/22 May/June 2026 · Question 5 · 5 marks
(a) Describe the change that would have to be made to the bubble sort algorithm A so that the Numbers array is sorted into descending order. (b)(i) Explain why the second bubble sort algorithm B is more efficient than algorithm A.
Points that gain marks
- (a) Change > to < in the comparison: IF Numbers[Index] < Numbers[Index + 1] THEN.
- (b) In B the inner loop runs one time fewer on each pass of the outer loop …
- … because after each pass one more element at the end of the array is in its correct place.
- B's outer loop stops when a pass makes no swaps: the array is already sorted …
- … so fewer passes are needed.
In this lab: 'Stop early' runs the NoSwaps flag; 'The worst case' counts 4 + 3 + 2 + 1 comparisons as each pass gets shorter.
9618/22 May/June 2026 · Question 5(a)–(b) · 6 marks
Two bubble sort algorithms sort the Numbers array into ascending order. (a) Describe the change to algorithm A that would sort into descending order. (b)(i) Explain why algorithm B (which stops when no swaps are made) is more efficient than algorithm A. (ii) State when B's outer loop iterates the minimum number of times.
Points that gain marks
- (a) Change > to < in the comparison: IF Numbers[Index] < Numbers[Index + 1] THEN.
- (b)(i) The inner loop iterates one less time each pass, because after each pass one more element at the end is in its correct place.
- (b)(i) The outer loop stops if no swaps are made, so fewer passes are needed.
- (b)(ii) When the array is already sorted (in ascending order).
In this lab: Levels 'Bubble sort', 'Stop early' and 'The worst case'.
9618/31 May/June 2024 · Question 10(a) and (c) · 3 marks
(a) State a condition that must be true for an array to be searched with a binary search. (c) Describe the performance of a binary search in relation to the number of data items. Refer to Big O notation.
Points that gain marks
- (a) The elements are sorted (in ascending or descending order).
- (c) Big O for a binary search is O(log n).
- (c) The search area halves each time, so the number of comparisons grows slowly: the time grows logarithmically as the number of items grows.
In this lab: Levels 'Binary search' and 'Binary search: not there'.
9618/31 May/June 2026 · Question 10(b)–(c) · 4 marks
(b) Describe the factors, other than changing the algorithm, that affect the time efficiency of the insertion sort. (c) State the Big O notation for its worst-case time complexity.
Points that gain marks
- (b) The number of elements: fewer elements are sorted faster.
- (b) The initial order: a partly sorted array is sorted faster.
- (c) O(n²).
In this lab: Levels 'Insertion sort' and 'Nearly sorted'.
IGCSE 0478/22 October/November 2024 · Question 4 · 8 marks
A pseudocode bubble sort that should put the array ItemList into alphabetical order has errors. (a) Identify the line numbers of five errors and suggest a correction for each. (b) Explain why the corrected bubble sort algorithm is efficient.
Points that gain marks
- (a) DECLARE Counter : INTEGER (not STRING); Swapped ← TRUE (not Temp ← TRUE).
- (a) WHILE Swapped = TRUE AND Pass <= Limit - 1 (AND, not OR).
- (a) ItemList[Counter + 1] ← Temp; ENDIF, not ENDCASE.
- (b) A flag shows whether a swap was made in this pass, so the loop stops once the list is sorted.
- (b) The inner loop's limit goes down after each pass, so fewer comparisons are made.
In this lab: Levels 'Bubble sort', 'Stop early' and 'Sort the names'.