Skip to main content
EnglandComputer ScienceSyllabus dot point

How do bubble, insertion, merge and quick sort order a list, and why are the divide-and-conquer sorts faster?

Sorting algorithms: bubble sort, insertion sort, merge sort and quick sort, how each works with a trace, and their time complexity in Big-O notation including best, average and worst cases.

An OCR H446 answer on sorting algorithms: how bubble sort, insertion sort, merge sort and quick sort order a list with worked traces, and their time complexity in Big-O notation including the difference between the quadratic and the divide-and-conquer sorts.

Generated by Claude Opus 4.814 min answer

Reviewed by: AI editorial process; not yet individually human-reviewed

Have a quick question? Jump to the Q&A page

Jump to a section
  1. What this dot point is asking
  2. The answer
  3. Examples in context
  4. Try this

What this dot point is asking

OCR wants you to describe and trace bubble sort, insertion sort, merge sort and quick sort, and give their time complexities, distinguishing the quadratic sorts from the divide-and-conquer sorts. Expect to trace a pass of a sort and to compare complexities.

The answer

Bubble sort and insertion sort

Merge sort

Quick sort

Examples in context

Insertion sort is used inside hybrid sorts (like Timsort) for small runs because it is fast on nearly sorted data. Merge sort suits very large datasets and external sorting because its merges stream data, and it is stable. Quick sort is the default in many libraries for its speed and in-place operation, with safeguards on pivot choice. Bubble sort is mainly a teaching example. OCR pairs this with searching (sort once, search many times with binary search) and with Big-O analysis.

Try this

Q1. State the worst-case time complexity of bubble sort and of merge sort. [2 marks]

  • Cue. Bubble sort O(n2)O(n^2); merge sort O(nlogn)O(n \log n).

Q2. State what quick sort does after choosing a pivot. [2 marks]

  • Cue. It partitions the list into items smaller than the pivot (to its left) and larger (to its right), then recursively sorts each partition.

Q3. State one situation where insertion sort performs close to O(n)O(n). [1 mark]

  • Cue. When the list is already sorted or nearly sorted (few shifts are needed).

Exam-style practice questions

Practice questions written in the style of OCR exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.

OCR 20206 marksUsing the list [5,2,8,1][5, 2, 8, 1], show one complete pass of a bubble sort with a trace, and state the worst-case time complexity of bubble sort.
Show worked answer →

First pass trace (up to 5), comparing adjacent pairs and swapping if out of order:

comparison list before swap? list after
5 vs 2 [5,2,8,1][5, 2, 8, 1] yes [2,5,8,1][2, 5, 8, 1]
5 vs 8 [2,5,8,1][2, 5, 8, 1] no [2,5,8,1][2, 5, 8, 1]
8 vs 1 [2,5,8,1][2, 5, 8, 1] yes [2,5,1,8][2, 5, 1, 8]

After one pass the largest value (8) has "bubbled" to the end: [2,5,1,8][2, 5, 1, 8].

Complexity (1 mark): worst case O(n2)O(n^2), because up to nn passes each make up to nn comparisons. Markers reward a correct adjacent-comparison trace with the largest value moved to the end, and O(n2)O(n^2).

OCR 20226 marksExplain how merge sort works using divide and conquer, and explain why its time complexity is O(nlogn)O(n \log n) rather than O(n2)O(n^2).
Show worked answer →

How merge sort works (up to 4): merge sort repeatedly divides the list into two halves until each sublist has one element (which is trivially sorted), then merges pairs of sublists back together in order, comparing the fronts of the two lists and taking the smaller each time, until the whole list is reassembled sorted. It is divide and conquer: split, sort the parts, combine.

Why O(nlogn)O(n \log n) (up to 2): the dividing creates about log2n\log_2 n levels of splitting (halving each time), and merging at each level processes all nn elements, so the total work is nn per level times logn\log n levels, giving O(nlogn)O(n \log n). This beats the O(n2)O(n^2) of bubble or insertion sort on large lists. Markers reward split-to-single-then-merge plus the logn\log n levels times nn work argument.

Related dot points

Sources & how we know this