Year 9 (ages 13–14, Grade 8 in the US) · Computing · Algorithms · Lesson 3
Bubble sort
How bubble sort works, tracing passes and swaps, knowing when it has finished, reading Python code, and its pros and cons.
Exam boards: this lesson matches the AQA and Pearson Edexcel GCSE computing courses. Check which course your school follows.

18-minute video lesson
Teaching, worked examples and 20 practice questions solved step by step.
Watch free for a monthWhat your child will learn
- Describe bubble sort
- Trace passes and count swaps
- Know when it stops
- Evaluate bubble sort
The method
- Compare the first pair.
- Wrong order? Swap.
- Move along one; repeat to the end.
- Repeat passes until no swaps.
Key words: bubble sort, pass, swap, ascending, algorithm.
Worked examples
Worked examples from the lesson, with every step.
Question 1
Do ONE pass of bubble sort (ascending) on [4, 3, 2, 1]. Write the list after the pass and the number of swaps.
- Step 1: Start
- Step 2: Compare each pair
Answer: [3, 2, 1, 4]; 3 swaps
Question 2
Do ONE pass of bubble sort (ascending) on [2, 7, 1, 8]. Write the list after the pass and the number of swaps.
- Step 1: Start
- Step 2: Compare each pair
Answer: [2, 1, 7, 8]; 1 swap
Question 3
Do ONE pass of bubble sort (ascending) on [10, 30, 20, 40]. Write the list after the pass and the number of swaps.
- Step 1: Start
- Step 2: Compare each pair
Answer: [10, 20, 30, 40]; 1 swap