The Computing Series

Where It Fails

FM3 (Unbounded Resource Consumption) — treating O(n log n) as equivalent to O(n) at n = 10⁹ causes resource exhaustion.

At n = 10⁹: - O(n) at 10⁹ operations/second: ~1 second - O(n log n) at 10⁹ operations/second: ~30 seconds - O(n²) at 10⁹ operations/second: ~31 years

The difference between O(n) and O(n log n) is a factor of 30 at n = 10⁹. For most applications this is acceptable. For real-time systems with n = 10⁹, it is not.

The failure mode: an engineer sees “O(n log n) is close to O(n)” in a textbook and treats them as equivalent. At scale, they are not equivalent. At n = 10⁹, the factor-of-30 difference is the difference between a 1-second operation and a 30-second operation.

A second failure mode: Big-O analysis does not account for cache behavior. An O(n) algorithm with poor cache locality can be slower in practice than an O(n log n) algorithm with excellent cache behavior, for n that fits in CPU cache. The constant factor from cache misses dominates. This is why mergesort (O(n log n), poor cache locality on the merge step) is often slower in practice than quicksort (O(n log n) expected, excellent cache locality) on modern hardware.


Read in the book →