← Eduqas GCSE

Sorting: Eduqas GCSE practice

Bubble, insertion and merge sort. 12 questions in the style of the Eduqas GCSE exam.

Sample questions

How does a bubble sort work?

  1. It splits the list into halves and merges them back in order
  2. It compares neighbouring (adjacent) items and swaps them if they are in the wrong order, repeating passes until no swaps are needed
  3. It takes each item in turn and inserts it into the correct place in a sorted part of the list
  4. It picks a random item and puts it at the front

Write a program that reads a whole number n, then n whole numbers one per line. Sort them into ascending order using a bubble sort (do not use sort() or sorted()) and print them on one line separated by single spaces.

This function merges two sorted lists, which is the key step of a merge sort. What does the program print?

def merge(a, b):
    result = []
    i = 0
    j = 0
    while i < len(a) and j < len(b):
        if a[i] <= b[j]:
            result.append(a[i])
            i = i + 1
        else:
            result.append(b[j])
            j = j + 1
    result = result + a[i:] + b[j:]
    return result

print(merge([2, 7, 9], [1, 3, 8, 10]))
print(merge([4], [1, 2]))