Year 10 (ages 14–15, Grade 9 in the US) · Computing · GCSE programming · Lesson 16
Sorting: bubble sort
How bubble sort works by comparing and swapping adjacent items, tracing passes, swapping two variables in Python, writing a bubble sort, and its strengths and weaknesses.
Exam boards: this lesson matches the AQA and Pearson Edexcel GCSE computing courses. Check which course your school follows.

8-minute video lesson
Teaching, worked examples and 20 practice questions solved step by step.
Watch free for a monthWhat your child will learn
- Describe how bubble sort works
- Trace a bubble sort pass
- Swap two values in Python
- Evaluate bubble sort
The method
- Compare each pair of neighbouring items.
- Swap them if they are in the wrong order.
- One pass moves the largest item to the end.
- Repeat passes until a pass makes no swaps.
Key words: bubble sort, pass, swap, adjacent, efficiency.
Worked examples
Worked examples from the lesson, with every step.
Question 1
Show the first pass of bubble sort on [4, 2, 6, 1].
- Step 1: 4>2 swap → [2, 4, 6, 1]; 4<6 no swap
- Step 2: 6>1 swap → [2, 4, 1, 6]
Answer: [2, 4, 1, 6]
Question 2
Continue: second pass on [2, 4, 1, 6].
- Step 1: 2<4 no; 4>1 swap → [2, 1, 4, 6]
- Step 2: 4<6 no swap
Answer: [2, 1, 4, 6]
Question 3
How many more passes are needed to finish?
- Step 1: 2>1 swap → [1, 2, 4, 6]
- Step 2: No swaps → stop
Answer: 2 more passes (the last checks no swaps)