The big idea: Bubble sort compares neighbouring pairs and swaps them when they are the wrong way round, so the largest value moves to the end each pass.
Selection sort finds the smallest value in what is left and swaps it into place, once per position.
Both algorithms on the same six numbers, with running comparison and swap counts. Switch between them.
Interactive diagram
Explore the labelled diagram, charts and maps for this topic in full study mode.
Free preview
This is the free notes preview
You're reading the free notes. Aimnova Pro unlocks the full study experience — and you can try it with your first topic free to keep:
- FlashcardsLock in vocabulary and key terms with spaced repetition.
- Practice questionsAnswer exam-style questions and get instant AI marking.
- Mock exams & past-paper vaultSit full mocks and see exactly how examiners award marks.
- Personalised study planA daily plan built around your exam date and weak areas.
What one pass does
Why the range shrinks
The early exit
The cost
Practice with real exam questions
Answer exam-style questions and get AI feedback that shows you exactly what examiners want to see in a full-marks response.
Bubble sort
- O(n²) comparisons, O(n²) swaps
- Best case O(n) — one pass over sorted data with the early exit
- Very many swaps: it moves data constantly
- Slightly simpler to write and to trace
Selection sort
- O(n²) comparisons, but only O(n) swaps
- No best case — it always does every comparison
- At most one swap per position, decided after looking
- Better when moving data is what costs
The distinction that matters: Both do O(n²) comparisons. The difference is the swaps.
Selection sort looks first and moves once. Bubble sort moves as it goes. When writing data is expensive, that difference is the whole argument.
Both use O(1) space: Each sorts in place, needing only a couple of extra variables however large the list.
So in a question about memory, neither has an advantage — the answer is that both are O(1).
How this is tested — you must trace a pass exactly and compare on both comparisons and swaps. It comes up two ways:
Paper 2 — working with code
- Trace one or more passes of a sort, 4-6 marks
- State and justify time and space complexity
- Compare the two for a given data set
Paper 2 — the algorithmic-thinking question
- Reason about pass counts with no code shown
- Explain which sort suits a stated situation
The classic trap: Saying selection sort is more efficient. Both do O(n²) comparisons — selection sort only wins on swaps. Saying which measure you mean is the mark.
Show the list after each pass of a bubble sort on [5, 2, 8, 1], then state the complexity and compare with selection sort.
Model answer plan
See the mark-by-mark plan — for / against / judgement, with marking guidance — in study mode.