Knowledge Organiser: Bubble Sort
Key Terms
- Bubble sort: Compares neighbouring items and swaps them if they are in the wrong order
- Pass: One full run through the list
- Swap: Exchange the positions of two items
- Swap flag: A True or False variable that records whether a pass made any swaps
- In place: Sorts the list without needing a second list
Must-Know Facts
- After pass one, the largest value is at the end of the list
- A pass with no swaps shows the list is sorted
- A list of n items needs at most n - 1 passes that make swaps
- The first pass on 5 items makes 4 comparisons
- Bubble sort is best for small lists and for learning how sorting works
- It is a poor choice for very large lists
Key Concepts
- Compare neighbours, swap if out of order, move along, repeat
- Each pass puts one more value in its final place at the end
- Swap flag: stop as soon as a pass makes no swaps
- Repeated passes are needed because small values move left only one place per pass
- In exams: show the list after each pass
Common Mistakes
- Doing only one pass: One pass sorts the list only if it was already nearly in order
- Comparing items that are not neighbours: Bubble sort always compares adjacent items
- Not showing the list after each pass: Showing only the final list loses the method marks
- Saying the smallest value is first after pass one: It is the largest value that reaches the end. Small values only move one place left per pass
- Calling bubble sort the best sort: It is simple, but it makes many comparisons on large lists