Skip to content
Menu

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.

Whiteboard video lesson: Bubble sort

18-minute video lesson

Teaching, worked examples and 20 practice questions solved step by step.

Watch free for a month

What your child will learn

  • Describe bubble sort
  • Trace passes and count swaps
  • Know when it stops
  • Evaluate bubble sort

The method

  1. Compare the first pair.
  2. Wrong order? Swap.
  3. Move along one; repeat to the end.
  4. 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.

  1. Step 1: Start
  2. 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.

  1. Step 1: Start
  2. 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.

  1. Step 1: Start
  2. Step 2: Compare each pair

Answer: [10, 20, 30, 40]; 1 swap