Sorting Algorithms

💻 Computer Science Years 8–11 Foundation

How bubble, insertion and merge sort put a list in order, and why their speeds differ.

Open this lesson, with practice and a printable worksheet →

Hand a child a shuffled deck of cards and say "put these in order". Watch closely and you will see them invent a sorting algorithm on the spot — sliding each new card into its right place, or swapping neighbours that look wrong. Computers face the same job constantly: alphabetising contacts, ranking scores, ordering search results. There are many recipes for it, but three are the classics of GCSE: bubble sort, insertion sort and merge sort.

Why this matters: A sorted list unlocks fast tools like binary search, and sorting is one of the most-studied problems in computing. Comparing these three teaches a huge lesson: different algorithms can solve the same task with wildly different amounts of effort.
Compare 5 and 2: 5 2 8 1 5 > 2, so swap 2 5 8 1
Bubble sort: compare neighbours and swap the ones out of order.

Bubble sort — swap neighbours

Bubble sort walks along the list comparing each pair of neighbours, swapping them if they are in the wrong order. After one full pass the largest value has "bubbled" to the end. It repeats passes until a whole pass makes no swaps. Simple to grasp, but slow — it can make roughly n² comparisons.

Insertion sort — build a sorted section

sorted ← | → unsorted26941insert 4 between 2 and 624691
Insertion sort slots each card into its place in the sorted part.

Insertion sort is how most people sort a hand of playing cards. It takes each item in turn and inserts it into its correct place among the items already sorted to its left, shuffling bigger cards along to make room. It is often quicker than bubble sort on nearly-sorted data.

Merge sort — divide and conquer

5 2 8 15 28 15281now merge back in order ↑2 51 81 2 5 8
Merge sort splits down to single items, then merges pairs in order.

Merge sort uses decomposition: it splits the list in half, then halves again and again until every piece is a single item (which is already "sorted"). Then it merges pairs of pieces back together in order. It is much faster on big lists — about n×log₂n work — but it needs extra memory to hold the pieces.

SortIdeaSpeed on big listsExtra memory
BubbleSwap neighboursSlow (n²)Very little
InsertionInsert into sorted partSlow (n²)Very little
MergeSplit then mergeFast (n log n)More
Worked reasoning: One bubble-sort pass on [5, 2, 8, 1]. Compare 5 & 2 → swap → [2, 5, 8, 1]. Compare 5 & 8 → in order. Compare 8 & 1 → swap → [2, 5, 1, 8]. After one pass the largest (8) has bubbled to the end; the list is not yet fully sorted, so another pass is needed.
Common mistake: Thinking one pass of bubble sort finishes the job.
list size (n)workbubble n²merge n log n
On big lists bubble sort's n² work explodes; merge sort stays gentle.
One pass only guarantees the largest remaining item reaches its final place. You keep passing until a full pass makes no swaps at all.

Memory hook: Bubble = Bump neighbours; Insertion = slot cards In; Merge = split, then Mend back together.

Get the printable worksheet →
← Searching Algorithms → Trace Tables & Efficiency
← Sasta Basta home All subjects