GCSE · Computer Science · AQA · Spec 8525
Bubble sort
Bubble sort only ever sees two neighbours at a time, so how does it know when it's finished?
Watch it work
Bubble sort, one comparison at a time
Four numbers, three passes. Step through every comparison and watch the list change.
Before each step, call it: swap or no swap?
| Pass | Comparing | Swap? | List now |
|---|---|---|---|
| 3, 1, 4, 2 |
Output
Step 1: Here's our unsorted list. We want it in ascending order, smallest first. Bubble sort starts at the left and only ever looks at two neighbours at a time.
Press Next to go one step at a time, Play to watch it run, or Back to rewind.
Predict, then check
Same rules, new list. Commit to an answer before you look.
Bubble sort is putting 2, 1, 3, 4 into ascending order. Its very first swap turns the list into 1, 2, 3, 4. What does the algorithm do next?
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
Compare two neighbours, swap them if they're the wrong way round, and keep going until nothing moves.
What you need to know
- Bubble sort works by going through a list again and again.
- It compares adjacent items (two items next to each other) and swaps them if they are in the wrong order.
- 'Wrong order' depends on the order you want: for ascending order (smallest first), swap when the left item is bigger than the right one.
- Each time the algorithm goes through the list is called a pass.
- Passes are repeated until a pass makes no changes. That last pass is needed to confirm the data is in order.
The big picture
Bubble sort puts a list in order by going through it again and again. On each trip through, called a pass, it compares adjacent items and swaps any pair that is in the wrong order. It keeps making passes until one pass makes no changes at all. That last pass matters: because the algorithm only ever sees two items at a time, a change-free pass is how it confirms the list is in order.
Key points
Worked example
Problem
Use bubble sort to put pear, apple, kiwi, fig into alphabetical order. Show every comparison.
⚠ Watch out
Stopping the moment the list looks sorted. Bubble sort only stops after a pass with no swaps, so its final pass never changes anything: it's there to check.
Memory hook
Picture a teacher lining students up by height who is only allowed to compare two neighbours at a time. They can't say the line is sorted until they've walked the whole line once without having to move anybody.
Check yourself
A list of five numbers is already in ascending order before bubble sort starts. How many comparisons will the algorithm make before it stops, and why?
Flashcards
(8)What does bubble sort compare?
When does bubble sort swap two items?
In bubble sort, what is a pass?
When does bubble sort stop?
Why is the last pass needed?
A pass makes just one swap. What happens next?
If the list becomes sorted partway through a pass, does the pass stop there?
In an ascending bubble sort, where is the largest value after pass 1?
Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.
Learning with Lightbulb is opening soon
You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.
Keep me postedMore AQA GCSE Computer Science topics
How this lesson was checked. This AQA GCSE Computer Science (specification 8525)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 8 November 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.