Selection Sort vs Merge Sort

Across our 3 test inputs, Merge Sort needed 59 comparisons in total versus 135 for Selection Sort. On average Selection Sort runs in O(n²) time and Merge Sort in O(n log n). Merge Sort is stable; Selection Sort is not.

Head-to-head on identical inputs (comparisons)

InputSelection SortMerge Sort
Random order4525
Nearly sorted4519
Reversed4515

Complexity

Selection SortMerge Sort
Average timeO(n²)O(n log n)
Worst timeO(n²)O(n log n)
SpaceO(1)O(n)
StableNoYes

When to use Selection Sort

When memory writes are expensive (minimizes swaps). Otherwise, insertion sort is generally preferred.

When to use Merge Sort

When stable sorting is strictly required and O(n) extra space is acceptable. Highly predictable performance (always O(n log n)).