Selection Sort vs Quick Sort
Across our 3 test inputs, Quick Sort needed 106 comparisons in total versus 135 for Selection Sort. On average Selection Sort runs in O(n²) time and Quick Sort in O(n log n).
Head-to-head on identical inputs (comparisons)
| Input | Selection Sort | Quick Sort |
|---|---|---|
| Random order | 45 | 22 |
| Nearly sorted | 45 | 39 |
| Reversed | 45 | 45 |
Complexity
| Selection Sort | Quick Sort | |
|---|---|---|
| Average time | O(n²) | O(n log n) |
| Worst time | O(n²) | O(n²) |
| Space | O(1) | O(log n) |
| Stable | No | No |
When to use Selection Sort
When memory writes are expensive (minimizes swaps). Otherwise, insertion sort is generally preferred.
When to use Quick Sort
General-purpose sorting. Fast in practice due to excellent cache locality. Default algorithm used in many language libraries (often hybridised as Introsort).