Question bank › A-level Computer Science › Fundamentals of algorithms

Sorting algorithms (bubble sort, merge sort)

Answer on paper first, then reveal the mark scheme one mark at a time.

1Standard5 marks

A bubble sort is used to sort [6, 2, 9, 4, 1] into ascending order. Each pass compares adjacent pairs from the start of the list, swapping them if they are out of order. The algorithm stops after a pass in which no swaps are made. No optimisation is made to shorten later passes.

(a) Write the contents of the list at the end of each pass until the algorithm stops. [3]

(b) State the total number of comparisons made. [1]

(c) State the worst-case time complexity of bubble sort. [1]

2Hard5 marks

A merge sort is used to sort [38, 27, 43, 3, 9, 82, 10] into ascending order. When a list has an odd number of items, the extra item goes in the left half.

(a) Show the two lists produced by the first split. [1]

(b) The lists are split until each contains one item, and are then merged back in pairs. Show the lists that exist after the first round of merging (a list with no partner is left unchanged). [2]

(c) Show the final sorted list. [1]

(d) State the time complexity of merge sort. [1]

Stuck on this topic?

Book a free 30-minute session on WhatsApp and we'll find exactly which step is costing you the marks. Or build a timed paper on it.

Free 30-minute session