A Field Guide ◆ Nº 01 Subject: Sorting Algorithms Hosted on pidgin Status: Interactive

Five algorithms · One problem · Press play

Order
from chaos.

Every list wants to be sorted. The question is how many moves it takes to get there. This is a hands-on tour of the five sorting algorithms every programmer should know — run them, step through them, race them.

Specimen under observation
fig. 0 — live demonstration now running: …

fig. 6 — head-to-head trial

The Grand Prix.

Same shuffled list, five contenders, one operation per tick each. Big-O notation stops being abstract the moment you watch merge and quick sort lap the quadratic field. Place your bets, then press start.

Speed

    * Each tick advances every algorithm by exactly one primitive operation (a comparison or a write), so the finish order reflects total work done — not wall-clock trickery. With 45 items, the quadratic sorts need roughly 1,000–2,000 operations; the divide-and-conquer pair needs a few hundred.

    fig. 7 — comparative anatomy

    The cheat sheet.

    Clip and save. n is the number of items; complexities count comparisons and moves as the list grows.

    AlgorithmBestAverageWorstSpaceStableReach for it when…
    Bubble SortO(n)O(n²)O(n²)O(1)YesYou're teaching, or the list is tiny and nearly sorted. Otherwise, almost never.
    Selection SortO(n²)O(n²)O(n²)O(1)NoWrites are expensive (flash memory) — it makes at most n−1 swaps.
    Insertion SortO(n)O(n²)O(n²)O(1)YesSmall or nearly-sorted data. It's the finishing move inside real-world hybrid sorts.
    Merge SortO(n log n)O(n log n)O(n log n)O(n)YesYou need guaranteed speed and stability — linked lists, external sorting, Timsort's backbone.
    Quick SortO(n log n)O(n log n)O(n²)O(log n)NoGeneral-purpose in-memory sorting. Superb cache behavior; the worst case is rare with random pivots.