Back to the topic

The mark scheme starts on a new page, so you can print pages one and two for a student and keep the last page yourself. Everything prints in black on white whichever theme you are using.

AQA GCSE CS · 3.1.4

Sorting Algorithms

Section A: 10 multiple choice questions, 10 marks. Section B: 5 written questions, 19 marks. Total 29 marks.

Name

Class

Date

Mark  / 29

Section A

Circle the letter of the correct answer. One mark each.

  1. 1After one complete pass of a bubble sort in ascending order, which item is guaranteed to be in its final position?1
    1. AThe largest item, at the end of the list
    2. BThe smallest item, at the start of the list
    3. CNo item is guaranteed to be in place
    4. DThe middle item
  2. 2What tells a bubble sort that the list is now sorted?1
    1. AThe middle item stops changing
    2. BThe first pass has finished
    3. CA complete pass finishes with no swaps made
    4. DThe list length has been reached
  3. 3In a merge sort, what is the list repeatedly divided into?1
    1. ASub lists, until each contains a single item
    2. BTwo halves, only once
    3. CSorted and unsorted sections
    4. DSub lists of four items
  4. 4During the merge stage, how is the next item chosen?1
    1. AThe first item of the left sub list is always taken
    2. BThe largest item in either sub list is taken
    3. CThe smaller of the two items at the front of the sub lists is taken
    4. DItems are taken at random and then checked
  5. 5Which sort generally requires more memory?1
    1. AMerge sort, because sub lists are held during merging
    2. BBubble sort, because it stores every swap
    3. CThey use exactly the same amount
    4. DNeither uses any extra memory
  6. 6How many passes at most does a bubble sort need on a list of 6 items?1
    1. A3
    2. B5
    3. C6
    4. D36
  7. 7Which statement about bubble sort is correct?1
    1. AIt is the fastest known sorting algorithm
    2. BIt requires the list to be partly sorted first
    3. CIt cannot sort text, only numbers
    4. DIt is simple to implement and sorts the list in place
  8. 8Roughly how does the work done by a bubble sort grow when the list size is doubled?1
    1. AIt roughly doubles
    2. BIt stays the same
    3. CIt increases by one pass
    4. DIt roughly quadruples
  9. 9A merge sort is applied to [8, 2, 5, 1]. What are the sub lists immediately before merging begins?1
    1. A[8, 2], [5, 1]
    2. B[8, 2, 5], [1]
    3. C[8], [2], [5], [1]
    4. D[1, 2, 5, 8]
  10. 10Which situation most favours a bubble sort over a merge sort?1
    1. AA list that must be sorted as quickly as possible
    2. BA very short list on a device with very little memory
    3. CA list of ten million items
    4. DA list that is in completely random order and very large

Section B

Answer in the space provided. The number of marks tells you how many separate points to make.

  1. 1DescribeDescribe how a bubble sort sorts a list of numbers into ascending order.4
  2. 2DescribeDescribe how a merge sort works.4
  3. 3WriteThe list [6, 2, 9, 4] is sorted using a bubble sort. Show the contents of the list after each of the first two passes.2
  4. 4CompareCompare a bubble sort and a merge sort. Your answer should refer to efficiency and memory use.6
  5. 5ExplainExplain why a bubble sort may need fewer passes on a list that is already almost in order.3

Mark scheme

Section A

1A2C3A4C5A6B7D8D9C10B

Section B

1 Describe how a bubble sort sorts a list of numbers into ascending order. 4

One mark for each of the following, to a maximum of 4.

  • Adjacent pairs of items are compared
  • If they are in the wrong order they are swapped
  • This is repeated for the whole list, which is called a pass
  • Passes continue until a pass is completed with no swaps

Model answer. A bubble sort starts at the beginning of the list and compares the first two items. If they are in the wrong order it swaps them, then moves along one position and compares the next adjacent pair, continuing to the end of the list. One complete journey through the list is called a pass, and at the end of each pass the largest remaining value has been carried to its correct position at the end. The algorithm then begins another pass, and it keeps going until a whole pass is completed without a single swap being made, which shows that no pair is out of order and the list is sorted.

2 Describe how a merge sort works. 4

One mark for each of the following, to a maximum of 4.

  • The list is repeatedly divided in half
  • Until each sub list contains only one item
  • Pairs of sub lists are then merged back together
  • During each merge the smaller of the two front items is taken first, so the result stays in order

Model answer. A merge sort repeatedly divides the list in half, then divides each half in half, and continues until every sub list contains only one item, at which point every sub list is trivially in order. It then merges the sub lists back together in pairs. To merge two sub lists it compares the item at the front of each and takes whichever is smaller, repeating until one sub list is empty and then taking whatever is left in the other. Because both inputs to every merge are already sorted, the merged result is sorted too, and after the final merge the whole list is in order.

3 The list [6, 2, 9, 4] is sorted using a bubble sort. Show the contents of the list after each of the first two passes. 2

One mark for each of the following, to a maximum of 2.

  • After pass 1 the list is 2, 6, 4, 9
  • After pass 2 the list is 2, 4, 6, 9

Model answer. During the first pass 6 and 2 are swapped to give 2, 6, 9, 4, then 6 and 9 are left alone, then 9 and 4 are swapped, so the list after pass one is 2, 6, 4, 9. During the second pass 2 and 6 are left alone, then 6 and 4 are swapped, so the list after pass two is 2, 4, 6, 9.

4 Compare a bubble sort and a merge sort. Your answer should refer to efficiency and memory use. 6

One mark for each of the following, to a maximum of 6.

  • A bubble sort repeatedly swaps adjacent items, while a merge sort divides the list and merges it back
  • A merge sort is more efficient on large lists
  • Because halving the list means the number of rounds grows very slowly as the list grows
  • A bubble sort needs roughly n squared comparisons, so doubling the data quadruples the work
  • A bubble sort uses less memory because it sorts in place
  • A merge sort needs additional memory to hold the sub lists while merging

Model answer. A bubble sort works by repeatedly comparing adjacent pairs of items and swapping any that are in the wrong order, whereas a merge sort divides the list until each sub list holds one item and then merges the sub lists back together in order. On large lists a merge sort is considerably more efficient, because each round of merging halves the number of sub lists, so the number of rounds grows extremely slowly even as the list becomes very large. A bubble sort has to walk the whole list once per pass and may need almost as many passes as there are items, which means roughly n squared comparisons, so doubling the size of the list roughly quadruples the work. The trade off is memory. A bubble sort rearranges items inside the original list and so needs almost no extra memory, while a merge sort has to hold the sub lists it is building as well as the original data. For a small list, or on a device with very little memory, a bubble sort is therefore a reasonable choice, but for a large list where speed matters a merge sort is far better.

5 Explain why a bubble sort may need fewer passes on a list that is already almost in order. 3

One mark for each of the following, to a maximum of 3.

  • A bubble sort stops when a pass completes with no swaps
  • An almost sorted list needs few swaps, so that condition is reached quickly
  • So the algorithm can finish after only one or two passes rather than n minus 1

Model answer. A bubble sort does not run a fixed number of passes. It keeps making passes until one complete pass finishes without a single swap, because that shows no adjacent pair is out of order and the list must therefore be sorted. If the list is already almost in order then very few items need swapping, so the algorithm reaches a swap free pass after only one or two passes rather than after the n minus 1 passes it would need in the worst case. This is one of the few situations in which a bubble sort performs well.