Question bank › GCSE › GCSE Computer Science › Fundamentals of algorithms

Sorting algorithms: bubble & merge sort

10 questions45 marksabout 55 min

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

1Grade 4–54 marks

A bubble sort is used to put this list into ascending order:

[7, 3, 9, 1, 5]

(a) Show the list after the first pass of the bubble sort. [2]

(b) State how many swaps are made during the first pass. [1]

(c) Explain how the bubble sort algorithm knows that the list is fully sorted. [1]

2Grade 6–76 marks

A merge sort is used to sort this list into ascending order:

[6, 2, 8, 4, 1, 7, 3, 5]

(a) Show the stages of the merge sort. [4]

(b) Give one advantage of a merge sort compared with a bubble sort and one advantage of a bubble sort compared with a merge sort. [2]

3Grade 1–33 marks

Two standard sorting algorithms are studied at GCSE.

(a) State the name of the sorting algorithm that repeatedly compares adjacent items and swaps them if they are in the wrong order. [1]

(b) State the name of the sorting algorithm that repeatedly splits a list in half until each sublist contains one item, then combines the sublists back together in order. [1]

(c) In the algorithm named in (a), state the term used for one complete run through the list, comparing every pair of neighbouring items. [1]

Stuck on Sorting algorithms: bubble & merge sort?

Get it sorted in a free 30-minute session

We work through your weakest questions on this topic on Zoom. I reply the same day.

4Grade 4–54 marks

A bubble sort is used to put these names into alphabetical order. Each pass compares every pair of neighbouring items.

[Kai, Ada, Zoe, Ben, Eli, Cal]

(a) Show the list after the first pass. [1]

(b) Show the list after the second pass. [1]

(c) State how many comparisons are made in one pass of this list. [1]

(d) State which name is guaranteed to be in its final position at the end of the first pass. [1]

5Grade 4–54 marks

The diagram shows a merge sort being used to sort this list into ascending order:

[31, 8, 19, 4, 27, 12]

Three of the boxes, labelled A, B and C, have been left blank.

(a) Write down the contents of box A, box B and box C. [3]

(b) Explain why the sublist [31, 8, 19] is split into [31] and [8, 19] rather than straight into three single items. [1]

31 8 19 4 27 1231 8 194 27 12318 19427 1281927128 1912 27ABCsplitmerge
6Grade 6–75 marks

The final stage of a merge sort combines two sorted sublists into one sorted list.

(a) Describe how two sorted sublists are merged into a single sorted list. [2]

(b) The sublists [2, 5, 9] and [3, 4, 10] are merged. Each time the front items of the two sublists are compared counts as one comparison.

  (i) Write down the merged list. [1]

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

(c) Explain why merging [2, 5, 9] with [10, 11, 12] needs fewer comparisons than in part (b). [1]

7Grade 6–75 marks

This algorithm is a version of bubble sort. It is run on the list shown.

nums ← [1, 2, 4, 3, 5]
swapped ← True
passes ← 0
WHILE swapped
   swapped ← False
   passes ← passes + 1
   FOR i ← 0 TO LEN(nums) - 2
      IF nums[i] > nums[i + 1] THEN
         temp ← nums[i]
         nums[i] ← nums[i + 1]
         nums[i + 1] ← temp
         swapped ← True
      ENDIF
   ENDFOR
ENDWHILE
OUTPUT passes

(a) State the value output by the algorithm. [1]

(b) Explain the purpose of the variable swapped. [2]

(c) The list is changed to [5, 4, 3, 2, 1]. State the value that would now be output. [1]

(d) State the total number of comparisons (executions of the IF condition) made when sorting [5, 4, 3, 2, 1]. [1]

8Grade 8–95 marks

A programmer times two sorting algorithms, P and Q, on random lists of different sizes. One is a bubble sort and the other is a merge sort.

Number of items1000200040008000
Algorithm P time (ms)2.14.59.620.4
Algorithm Q time (ms)9538015206100

(a) Identify which algorithm is the bubble sort. Justify your answer using the data. [2]

(b) Explain why the time taken by a bubble sort grows in this way as the list gets longer. [2]

(c) Give one situation in which a bubble sort could still be the better choice. [1]

9Grade 4–54 marks

Two students each sort the list [9, 2, 7, 5] into ascending order using a different standard algorithm. Their working is shown.

Student 1

[9, 2, 7, 5]
[2, 7, 5, 9]
[2, 5, 7, 9]
[2, 5, 7, 9]

Student 2

[9, 2, 7, 5]
[9, 2]  [7, 5]
[9] [2] [7] [5]
[2, 9]  [5, 7]
[2, 5, 7, 9]

(a) State which sorting algorithm each student has used. [1]

(b) Give one piece of evidence from Student 2's working that supports your answer. [1]

(c) Explain why Student 1's last two lines are identical. [2]

10Grade 8–95 marks

This bubble sort algorithm sorts a list into ascending order. It always carries out a fixed number of passes.

nums ← [4, 1, 3, 2]
FOR pass ← 1 TO LEN(nums) - 1
   FOR i ← 0 TO LEN(nums) - 2
      IF nums[i] > nums[i + 1] THEN
         temp ← nums[i]
         nums[i] ← nums[i + 1]
         nums[i + 1] ← temp
      ENDIF
   ENDFOR
ENDFOR

(a) State the one change needed so that the algorithm sorts the list into descending order. [1]

The change in (a) is made and the algorithm is run on [4, 1, 3, 2].

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

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

(d) Using your answers to (b) and (c), explain why this version of the algorithm is inefficient and describe one change that would improve it. [2]

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