Bubble sort
A simple sorting algorithm repeatedly comparing adjacent elements and swapping if out of order, moving larger elements toward end. Bubble sort has O(n²) time complexity in average and worst cases, making it inefficient for large datasets. Stable sorting preserves equal element order. Simple implementation makes it suitable for education.
Formula
Comparisons (worst) = n(n−1)/2
Real World
A PE teacher lining students up by height, repeatedly swapping adjacent pairs who are out of order, mirrors exactly how bubble sort works on a small dataset.
Exam Focus
In trace-table questions, show each complete pass and clearly indicate when no swaps occur to justify early termination.
How well did you know this?