Bubble sort (Edexcel GCSE Computer Science): Revision Notes
Bubble sort
What is bubble sort and why do we need it?
Organising data in a specific sequence helps us work with it more effectively and makes it much easier to understand. Bubble sort is one of several sorting algorithms that can arrange data items in order.
The bubble sort algorithm gets its name because smaller elements "bubble" to the top of the list, just like air bubbles rising to the surface of water. While it may require several complete runs through the data to get everything in the right place, it's one of the most straightforward sorting methods to understand.
Understanding sorting order
Before we dive into how bubble sort works, we need to understand the two main ways we can organise data. The choice between these two approaches depends on what you want to achieve with your sorted data.
Understanding Data Organization
Ascending order means arranging items from smallest to largest:
- Numbers: 1, 2, 3, 4, 5
- Letters: a, b, c, d
Descending order means arranging items from largest to smallest:
- Numbers: 5, 4, 3, 2, 1
- Letters: d, c, b, a
How the bubble sort algorithm works
The bubble sort algorithm follows a simple but effective approach. It begins at the start of the list and compares adjacent (neighbouring) items, swapping them if they're in the wrong order.

Key Steps of Bubble Sort:
- Start at the beginning: The algorithm examines the first two items in the list
- Compare and swap: If the items are in the wrong order, they get swapped
- Move along: The algorithm then looks at the next pair of adjacent items
- Continue the pattern: This comparing and swapping continues until the end of the list
- Complete a pass: When you reach the end, you've completed one "pass" through the data
- Repeat if needed: The algorithm makes additional passes until no more swaps are required
The brilliant thing about bubble sort is that after each complete pass, at least one element ends up in its correct final position. The largest element will "bubble up" to its proper spot at the end of the list.
Worked example with names
Let's see bubble sort in action with a practical example. Imagine you need to sort these names into ascending (alphabetical) order: Kai, Camila, Samuel, Muhammad, Mia.

Worked Example: Sorting Names Alphabetically
The table shows each step of the sorting process:
- First comparisons: Kai and Camila are compared, and since "Camila" comes before "Kai" alphabetically, they get swapped
- Continuing through: Each adjacent pair gets compared and swapped if necessary
- Multiple passes: The algorithm continues making passes through the list
- Final result: Eventually, all names end up in alphabetical order: Camila, Kai, Mia, Muhammad, Samuel
The crucial point is that the algorithm must complete a full pass without making any swaps to confirm the list is completely sorted.
Key characteristics of bubble sort
Understanding the key characteristics of bubble sort helps you know when and how to use this algorithm effectively.
Algorithm Characteristics
Efficiency: Bubble sort isn't the fastest sorting algorithm, but it's excellent for learning because the logic is very clear and easy to follow.
When to use it: It works well for small datasets or when you need a simple algorithm that's easy to implement and understand.
How it stops: The algorithm knows it's finished when it can go through the entire list without needing to swap any items.
Exam tips
Essential Exam Strategies
- Trace through carefully: When answering bubble sort questions, work through each comparison step by step
- Count your passes: Remember that you may need multiple complete passes through the data
- Check your work: The algorithm isn't finished until you can go through the whole list without any swaps
- Watch the order: Make sure you understand whether the question asks for ascending or descending order
Remember!
Key Points to Remember:
- Bubble sort compares adjacent items and swaps them if they're in the wrong order
- The algorithm may require multiple passes through the data to get everything sorted
- After each pass, at least one element will be in its correct final position
- The sorting is complete when you can make a full pass without any swaps
- Bubble sort works for both ascending and descending order - just change your comparison logic