An array contains: [7, 2, 9, 3, 6] (a) Show the state of the array after each pass of a bubble sort. [4] (b) State the worst-case time complexity of merge sort. [1] (c) Give ONE advantage of merge sort over bubble sort for large datasets. [1]
[6 marks]
4 marks
(a) Pass 1: [2,7,3,6,9] | Pass 2: [2,3,6,7,9] | Pass 3: [2,3,6,7,9] (sorted — swap flag not set)
1 mark
(b) O(n log n)
1 mark
(c) Merge sort is O(n log n) compared to bubble sort's O(n²) — significantly faster for large n
Summary
Key Points to Remember
Bubble Sort — O(n²); compare adjacent pairs; swap optimisation with flag
Insertion Sort — O(n²) worst; O(n) best; good for nearly sorted
Merge Sort — O(n log n) guaranteed; divide & conquer; needs extra O(n) space