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 list
Compare the item with the one next to it
If the left one is greater, swap them (ascending order)
Move along one place and repeat to the end of the list
At the end of the pass: any swaps? Go again. No swaps? Stop.
passpairswap?listnext
15 1 4 2 8

Step 1. Pass 1 begins at the first item. This first row is worked for you.

Step 1 of 16Called right: 0 of 5

Try all three lists. Watch what the already-in-order list still has to do.

Computer Science · Sorting

When does bubble sort actually stop?

You are tracing a bubble sort. The pass you have just finished made a swap, and the list now reads in perfect order.

What do you think the sort does next?
How sure are you?

Exam line: Say that passes repeat until a pass makes no swaps, and that this final pass confirms the data is in order.

Computer Science · Sorting

How many comparisons in one pass?

A list has 6 items. Bubble sort makes one complete pass over it. How many comparisons does that pass make? Slide to your estimate before you look.

Your estimate

6 comparisons

0 comparisons12 comparisons

Exam line: One pass over the whole list makes one fewer comparison than there are items: n − 1.

Watch out: Count the pairs, not the items. The last item has no neighbour to its right.

Computer Science · Choosing an algorithm

Is bubble sort a good choice for a big collection?

The claim

Bubble sort is a good choice for sorting a very large collection of data.

Place each piece of evidence to load the balance. Mark the strong ones — they count double.

  1. Bubble sort is one of the slowest algorithms for sorting data.

    Evidence 1: does it support or challenge the claim?
  2. It performs poorly in real-world use, especially on large collections of data.

    Evidence 2: does it support or challenge the claim?
  3. Other sorting algorithms exist that cope better with a large set of data.

    Evidence 3: does it support or challenge the claim?
  4. The idea is simple: compare neighbours, swap if out of order, repeat. That makes it easy to implement and to test.

    Evidence 4: does it support or challenge the claim?
  5. It rearranges the items inside the list itself, so it needs very little extra memory.

    Evidence 5: does it support or challenge the claim?
  6. If the data is already in order, it finishes after a single pass with no swaps.

    Evidence 6: does it support or challenge the claim?

Exam line: Give a factor for choosing a sorting algorithm, say whether bubble sort meets it, and reach a judgement about the task you were given.

Computer Science · Pseudo-code

Turn the hand trace into code

Finish this pseudo-code so that it sorts the list numbers into ascending order using bubble sort.

  1. swapped = TrueA flag. It says whether the last pass made a swap. It starts True so the first pass runs.
  2. missing step
Which line is step 2?

Exam line: Your pseudo-code may use different keywords. What must be there is the loop over adjacent pairs inside a loop that repeats until no swap occurs.

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

1Bubble sort compares adjacent items and swaps them if they are in the wrong order.
2One pass is one complete trip through the list, and it leaves the largest item at the end.
3Passes repeat until a pass makes no swaps; that final pass confirms the order.
4A pass over a list of n items makes n − 1 comparisons.
5Bubble sort is very slow on large collections, so other algorithms are often chosen.

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?
It arranges the items in a list in a particular order, for example from lowest to highest.
What is bubble sort?
A sorting algorithm that repeatedly goes through a list, comparing adjacent items and swapping them if they are in the wrong order.
Which items does bubble sort compare?
Adjacent items: two values side by side in the list.
In ascending order, when do you swap a pair?
When the item at the current position is greater than the one next to it.
What is a pass?
One complete trip through the list from the first item to the end.
What has happened to the largest item by the end of a pass?
It has reached its final position at the end of the list.
How many comparisons does one pass over a list of n items make?
n − 1, one fewer than the number of items.
When does bubble sort stop?
When a pass makes no swaps.
Why is a last pass with no swaps needed?
It confirms the data is in order. The sort cannot know that from a pass that still made swaps.
Name the two ways to make bubble sort more efficient.
Stop once no swaps were made in a pass, and make one fewer comparison after each pass.
How does bubble sort perform on large collections of data?
Poorly. It is one of the slowest sorting algorithms and performs poorly in real-world use.
Name three factors that affect which sorting algorithm to use.
Any three of: efficiency on large sets of data, ease of implementing and testing, memory needed, and how the data is formatted.

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 posted

More Eduqas GCSE Computer Science topics

See the full Eduqas Computer Science curriculum →

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.