Loading section...

O(n log n): Quasilinear Time

Why it matters: sorting requires touching every element, but divide-and-conquer keeps the total passes to log(n). Ten million rows takes about twenty-three passes, not ten million. Sorting Is O(n log n) Python's built-in sorting uses Timsort, a hybrid algorithm designed specifically for real-world data. Timsort is O(n log n) in the worst case and O(n) when data is already partially sorted. It detects naturally ordered sequences in your data and merges them efficiently. Every time you call sorted() in Python, you benefit from one of the most carefully optimized sorting implementations ever written. Notice the ratio is consistently around 2.15x when input doubles, not exactly 2x (which would be pure O(n)) and not 4x (which would be O(n²)). The slight extra cost beyond 2x comes from the log n