Sorting algorithms: bubble, merge and insertion sort

10 questions44 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.

[6, 2, 9, 1, 5]

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

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

(c) State how a bubble sort knows that the list is sorted. [1]

2Grade 6–74 marks

Show how a merge sort would sort this list into ascending order.

[38, 27, 43, 3, 9, 82, 10, 16]

[4]

3Grade 6–74 marks

An insertion sort is used to put these names into alphabetical order.

["Mo", "Ali", "Tia", "Ben", "Cat"]

Show the list after each pass of the insertion sort. [4]

Stuck on Sorting algorithms: bubble, merge and insertion 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 6–74 marks

A program needs to sort a list of 50 000 customer records.

Compare merge sort and bubble sort for this task. [4]

5Grade 1–34 marks

Three sorting algorithms are described below.

DescriptionAlgorithm
1. Repeatedly compares each pair of neighbouring items and swaps them if they are in the wrong order, until a whole pass is made with no swaps. 
2. Splits the list in half again and again until each list holds one item, then combines the lists back together in order. 
3. Takes each item in turn and slides it leftwards into the correct position in the part of the list that is already sorted. 

(a) Write the name of the sorting algorithm that matches each description. [3]

(b) State why merge sort is described as a divide and conquer algorithm. [1]

6Grade 6–74 marks

A procedure is written in OCR Exam Reference Language.

procedure sort(list)
  for i = 1 to list.length - 1
    current = list[i]
    j = i - 1
    while j >= 0 AND list[j] > current
      list[j + 1] = list[j]
      j = j - 1
    endwhile
    list[j + 1] = current
  next i
endprocedure

(a) Identify the sorting algorithm that this procedure carries out. [1]

(b) Give two features of the code that show it is this algorithm. [2]

(c) The procedure is called with list = [5, 2, 4]. State the contents of list at the end of the first iteration of the for loop (when i = 1). [1]

7Grade 4–54 marks

Two students each sort the list [7, 3, 8, 1, 5] into ascending order using a different standard algorithm. They record the list at the end of each pass.

Student AStudent B
Pass 1[3, 7, 8, 1, 5][3, 7, 1, 5, 8]
Pass 2[3, 7, 8, 1, 5][3, 1, 5, 7, 8]
Pass 3[1, 3, 7, 8, 5][1, 3, 5, 7, 8]
Pass 4[1, 3, 5, 7, 8][1, 3, 5, 7, 8]

(a) Identify the algorithm used by Student A and give one reason from the table for your answer. [2]

(b) Identify the algorithm used by Student B and give one reason from the table for your answer. [2]

8Grade 6–75 marks

During a merge sort, two sorted sub-lists are merged into one sorted list.

Sub-list 1: [4, 11, 19, 25]
Sub-list 2: [6, 8, 27, 30]

(a) Write the merged list. [1]

(b) Describe how the merge step decides which item to place next in the merged list. [2]

(c) State the number of comparisons made between items during this merge. [1]

(d) Explain why a merge sort still carries out every split and merge even when the original list is already in order. [1]

9Grade 4–55 marks

A bubble sort is used to put these race times (in seconds) into descending order, largest first.

[12, 45, 7, 30, 22, 9]

(a) State the number of comparisons made during the first pass. [1]

(b) Show the list at the end of the first pass. [2]

(c) State the number of swaps made during the first pass. [1]

(d) The algorithm stops when a complete pass is made with no swaps. State the total number of passes carried out, including the final pass. [1]

10Grade 8–96 marks

The diagram shows a merge sort being used to sort the list [21, 5, 17, 9, 30, 2, 14, 11] into ascending order. The split stage is complete. Three of the boxes in the merge stage, labelled A, B and C, have been left blank.

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

(b) This list of 8 items needs 3 rounds of splitting to reach single items. State the number of rounds of splitting needed for a list of 32 items and explain your answer. [2]

(c) Explain why a merge sort usually needs more memory than a bubble sort while it is running. [1]

SplitMerge[21, 5, 17, 9, 30, 2, 14, 11][21, 5, 17, 9][30, 2, 14, 11][21, 5][17, 9][30, 2][14, 11][21][5][17][9][30][2][14][11][5, 21][9, 17]A[11, 14][5, 9, 17, 21]BC

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