Intro Sort
- Ω( n log n )
- Θ( n log n )
- O( n log n )
- space O( log n )
- Comparisons count only element-against-element checks; loop and index checks are never counted.
- Reads and writes include reads and writes to helper buffers (merge, counting, radix, bucket and tim sort).
- A swap counts once, as a swap. It is never also counted as a read or a write.
- Real time is the average time of the counted sort on this device over repeated runs, measured once before playback and independent of animation speed. Visual time is the time spent animating, excluding pauses.
How intro sort works
Intro sort starts as a quick sort, switches to heap sort if the recursion gets too deep, and finishes small partitions with insertion sort. It is the algorithm behind many C++ standard library sorts.
Read more
Quick sort is usually the fastest but has a quadratic worst case. Capping the depth at twice log₂ n and falling back to heap sort keeps the worst case at O(n log n) without giving up quick sort speed on typical data.
| Best time | Ω( n log n ) | good |
|---|---|---|
| Average time | Θ( n log n ) | good |
| Worst time | O( n log n ) | good |
| Worst space | O( log n ) | good |
Big O notation gives the lower, average and upper bounds of an algorithm. Time complexity bounds the number of operations; space complexity bounds the extra memory it uses.