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.
Reviewed by: AI editorial process; not yet individually human-reviewed
Have a quick question? Jump to the Q&A page
Jump to a section
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 ; merge sort .
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 . [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 , 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 | yes | ||
| 5 vs 8 | no | ||
| 8 vs 1 | yes |
After one pass the largest value (8) has "bubbled" to the end: .
Complexity (1 mark): worst case , because up to passes each make up to comparisons. Markers reward a correct adjacent-comparison trace with the largest value moved to the end, and .
OCR 20226 marksExplain how merge sort works using divide and conquer, and explain why its time complexity is rather than .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 (up to 2): the dividing creates about levels of splitting (halving each time), and merging at each level processes all elements, so the total work is per level times levels, giving . This beats the of bubble or insertion sort on large lists. Markers reward split-to-single-then-merge plus the levels times work argument.
Related dot points
- Searching algorithms: linear search, binary search and binary tree search, how each works with a trace, the precondition for binary search, and their time complexity in Big-O notation.
An OCR H446 answer on searching algorithms: how linear search, binary search and binary tree search work with worked traces, the requirement that binary search needs a sorted list, and the time complexity of each in Big-O notation.
- Graph and tree traversal: breadth-first and depth-first traversal of a graph, the pre-order, in-order and post-order traversal of a binary tree, and the shortest-path algorithms Dijkstra's algorithm and A* search.
An OCR H446 answer on traversal and shortest-path algorithms: breadth-first and depth-first graph traversal, the pre-order, in-order and post-order traversal of a binary tree, and how Dijkstra's algorithm and A* search find a shortest path.
- Big-O notation for time and space complexity: the constant, logarithmic, linear, linearithmic, polynomial and exponential complexity classes, how to determine the Big-O of an algorithm, and using it to compare and judge the suitability of algorithms.
An OCR H446 answer on Big-O notation: the constant, logarithmic, linear, linearithmic, polynomial and exponential complexity classes for time and space, how to determine an algorithm's Big-O, and using it to compare algorithms and judge their suitability.
- Data structures: arrays, records, tuples and lists, the stack and queue abstract data types and their operations, linked lists, trees and graphs, and hash tables, including how each is used and its advantages.
An OCR H446 answer on data structures: arrays, records, tuples and lists, the stack and queue abstract data types with their operations, linked lists, trees, graphs and hash tables, including how each is used and its advantages and disadvantages.
- Thinking logically: identifying the decision points and conditions that affect the flow of a solution; computational methods including problem recognition, divide and conquer, backtracking, heuristics, performance modelling and visualisation.
An OCR H446 answer on thinking logically and computational methods: identifying decision points and conditions in a solution, and the methods of problem recognition, divide and conquer, backtracking, heuristics, performance modelling and visualisation that make problems solvable.