Five sorts and the engine’s own sort on the same sacks, n doubling up to 512: real comparison counts chalked on the board against n, n log n and n². Which…
Why it matters
"Which algorithm?" has no single answer: it depends on n, the data’s arrangement and memory. Watching real comparison counts climb as n doubles turns Big-O from a formula into a feel: why quick sort is fast but can be fragile, why merge is steady but needs a bench, why the built-in sort is quick on data that is already sorted.
The key idea
Big-O is growth: double n, watch the work
Common mistakes
Thinking O(n²) is always slower than O(n log n) Only for large n. At small n the constants win: eight shuffled sacks, and insertion does less work than merge, which is why real sorts use insertion for small pieces.
Thinking quick sort is always fastest On average yes, but a naive pivot (the rightmost) makes it n(n − 1)/2 on a sorted or reversed row. A random pivot or the median of three avoids it.
Thinking one algorithm has one Big-O There are best, average and worst cases. Insertion: n − 1 comparisons on a sorted row, n(n − 1)/2 on a reversed one. Say which case.
Thinking the built-in sort is quick sort V8 has used TimSort since 2018: stable, O(n log n) worst case, and it spots runs that are already in order, so a sorted or reversed row needs only n − 1 comparisons.
Try it in this playground
Double up to 512 Bubble, insertion or selection on shuffled sacks: each row about four times the one before.
Merge on any arrangement Measure merge up to 512 and see its curve stay near n log n.
Quick on a sorted row The rightmost pivot sends it up to the n² curve.
Count the built-in sort Its comparator is counted every time the engine calls it.