דלג לתוכן

Labs · 9618 AS 10.2 · A2 19.1

Sort and Search

Be the computer. Run bubble sort, insertion sort, linear search, binary search and hash tables step by step, with the 9618 pseudocode lit as you go.

14 levelsFree bench

In the exam

Exam questions on what this lab teaches, with the points that gain marks.

9618/22 May/June 2026 · Question 55 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

  1. (a) Change > to < in the comparison: IF Numbers[Index] < Numbers[Index + 1] THEN.
  2. (b) In B the inner loop runs one time fewer on each pass of the outer loop …
  3. … because after each pass one more element at the end of the array is in its correct place.
  4. B's outer loop stops when a pass makes no swaps: the array is already sorted …
  5. … 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

  1. (a) Change > to < in the comparison: IF Numbers[Index] < Numbers[Index + 1] THEN.
  2. (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.
  3. (b)(i) The outer loop stops if no swaps are made, so fewer passes are needed.
  4. (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

  1. (a) The elements are sorted (in ascending or descending order).
  2. (c) Big O for a binary search is O(log n).
  3. (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

  1. (b) The number of elements: fewer elements are sorted faster.
  2. (b) The initial order: a partly sorted array is sorted faster.
  3. (c) O(n²).

In this lab: Levels 'Insertion sort' and 'Nearly sorted'.

IGCSE 0478/22 October/November 2024 · Question 48 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

  1. (a) DECLARE Counter : INTEGER (not STRING); Swapped ← TRUE (not Temp ← TRUE).
  2. (a) WHILE Swapped = TRUE AND Pass <= Limit - 1 (AND, not OR).
  3. (a) ItemList[Counter + 1] ← Temp; ENDIF, not ENDCASE.
  4. (b) A flag shows whether a swap was made in this pass, so the loop stops once the list is sorted.
  5. (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'.

The question as printed in the exam paper

More real experiments

All labs →

היכנס או צור חשבון

IGCSE, A-Level & AP