GCSE · Computer Science · Eduqas · Spec C500QS
Bubble sort
Imagine you can only ever look at two items at a time. How would you put a whole list in order, and how would you know when you had finished?
Computer Science · Sorting
Bubble sort: call every swap
Step through, and call each marked comparison before the table shows it.
Sorting into ascending order. Call each marked step first; nothing is run, every value is the lesson’s.
Start at the first item of the listCompare the item with the one next to itIf the left one is greater, swap them (ascending order)Move along one place and repeat to the end of the listAt the end of the pass: any swaps? Go again. No swaps? Stop.
| pass | pair | swap? | list | next |
|---|---|---|---|---|
| 1 | 5 1 4 2 8 |
Step 1. Pass 1 begins at the first item. This first row is worked for you.
Try all three lists. Watch what the already-in-order list still has to do.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
Compare two neighbours, swap if they are the wrong way round, repeat until a whole pass swaps nothing.
What you need to know
- A sorting algorithm puts the items in a list into a particular order, for example lowest to highest.
- Bubble sort compares adjacent items, which are pairs of values side by side, and swaps them if they are in the wrong order.
Have a goYour friend Sam says bubble sort "compares every item with every other item". What has Sam got wrong?
It only compares neighbours, one adjacent pair at a time.
Bubble sort never compares items that are apart. It gets items into order by swapping neighbours again and again.
- A pass is one complete trip through the list: compare a pair, swap if the left is greater, then move along.
- By the end of a pass, the largest item has reached its final position at the end of the list.
Have a goTake the list 4, 9, 2, 7. After one complete pass, which item is certain to be sitting at the very end?
9, the largest item.
A pass carries the largest item along to the end, because every time it meets a smaller neighbour it swaps past it.
- One pass over the whole list makes one fewer comparison than there are items in the list.
- Passes repeat until one makes no swaps. That last pass is what confirms the list is in order.
Have a goBubble sort is handed a list that is already in order. How many passes does it make, and why does it stop?
One pass, then it stops.
An ordered list gives no swaps, and a pass with no swaps is exactly what makes the sort finish.
- It can be made more efficient by stopping when a pass makes no swaps and making one fewer comparison after each pass.
- Bubble sort is one of the slowest sorting algorithms and performs poorly in real use, especially on large collections.
- Which algorithm to choose depends on speed on large data, ease of implementing and testing, memory needed, and data format.
- In pseudo-code, a loop over adjacent pairs sits inside a loop that repeats passes until no swap occurs.
The big picture
Bubble sort sorts a list by comparing neighbouring items and swapping any that are in the wrong order. It repeats passes until a pass makes no swaps, and that last pass is how it knows the list is in order.
Key points
Worked example
Problem
Bubble sort the list 6 2 5 3 into ascending order. Show the list after each pass and say how you know when to stop.
⚠ Watch out
Writing only the two items that moved instead of the whole list. After every comparison or pass, copy out the entire list so that nothing gets lost.
Memory hook
Bubble sort is like bubbles rising: the biggest one floats to the top (the end) on every pass, and you keep going until a pass finds nothing to move.
Check yourself
A pass over the list 1 3 2 4 swaps 3 and 2, giving 1 2 3 4. The list is now in order, so why is another pass still needed?
Flashcards
(12)What does a sorting algorithm do?
What is bubble sort?
Which items does bubble sort compare?
In ascending order, when do you swap a pair?
What is a pass?
What has happened to the largest item by the end of a pass?
How many comparisons does one pass over a list of n items make?
When does bubble sort stop?
Why is a last pass with no swaps needed?
Name the two ways to make bubble sort more efficient.
How does bubble sort perform on large collections of data?
Name three factors that affect which sorting algorithm to use.
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 Eduqas GCSE Computer Science topics
How this lesson was checked. This Eduqas GCSE Computer Science (specification C500QS)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 18 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.