Sorting: bubble sort
Sorting puts data in order, such as scores from lowest to highest. Bubble sort is the simplest sorting algorithm to follow by hand.
How bubble sort works
2. Move along one place and compare the next pair. Keep going to the end of the list. That is one pass.
3. After each pass, the biggest unsorted item has 'bubbled' to the end.
4. Repeat passes until a whole pass makes no swaps. Then the list is sorted.
One pass on 5, 3, 8, 1, 4
After pass 1: 3, 5, 1, 4, 8. The 8 is now in its final place.
After pass 2: 3, 1, 4, 5, 8.
Good and bad points
But it is slow on big lists, because it makes many comparisons and can need many passes.
For large lists, faster algorithms such as merge sort are used.
Show the list 6, 2, 9, 4 after the first pass of bubble sort.
- 6 and 2: swap: 2, 6, 9, 4.
- 6 and 9: no swap.
- 9 and 4: swap: 2, 6, 4, 9.
Answer: 2, 6, 4, 9
Bubble sort compares neighbouring pairs and swaps them if they are in the wrong order. Each pass moves the largest unsorted item to the end. It stops after a pass with no swaps. Simple, but slow for big lists.
- Bubble sort
- A sort that compares neighbouring pairs and swaps them if they are in the wrong order, making passes until no swaps are needed.
- Algorithm
- A precise set of step-by-step instructions to solve a problem or complete a task.
- AND
- A Boolean operator that gives True (1) only when both inputs are True.
- List
- A data structure that stores many items under one name, in order, such as scores = [4, 7, 2].
- Merge sort
- A divide and conquer sort that splits a list into single items, then merges them back together in order.
Try two quick questions
See if it has sunk in. Answers are marked straight away.
2 more questions
Try each one, then tap to check.
Write 3, 4, 1, 2 after one pass of bubble sort (ascending). Separate the numbers with commas.
Show the answer
Answer: 3, 1, 2, 4
3,4: no swap; 4,1: swap; 4,2: swap. Result: 3, 1, 2, 4.
Write 8, 3, 6, 1, 7 after one pass of bubble sort (ascending). Separate the numbers with commas.
Show the answer
Answer: 3, 6, 1, 7, 8
8,3: swap; 8,6: swap; 8,1: swap; 8,7: swap. Result: 3, 6, 1, 7, 8.
Check you have got it
Answer 6 quick questions with instant marking. If you get one wrong, GCSE-ready shows you why and gives you another go. It is free, and you do not need an account.
Facts checked against the sources below, 27 October 2026. Last updated 2 October 2026. Spotted a mistake? Tell us and we will fix it.