Bubble, selection, insertion. Three different strategies, the same O(n²) ceiling — and the perfect way to see how a sort actually thinks.
Sorting puts items in order, and these three are the classic starting points. Bubble sort repeatedly compares neighbors and swaps them, letting the largest value "bubble" to the end each pass. Selection sort scans the unsorted region for the smallest value and swaps it into place — using the fewest swaps of any sort. Insertion sort grows a sorted prefix one element at a time, sliding each new value back to where it belongs. All three are O(n²) in the worst case and sort in place with O(1) extra memory — perfect for learning, and genuinely useful on small or nearly-sorted data.
Each bar's height is its value. Yellow means comparing, pink means swapping, green means locked in place. Drag to orbit; the counters show why "O(n²)" is more than a label.
Same complexity ceiling, very different behavior — and that behavior decides which one you reach for.
All three are quadratic at worst, but their best cases and swap counts differ — and the next page shows how to break O(n²) entirely.