Skip to content
SimpleScope

Sorting

Selection sort vs Quick sort

Selection sort and Quick sort both put an array in order, in different ways. Selection sort: repeatedly pick the smallest remaining value. Quick sort: divide and conquer: partition around a pivot. In the worst case both take O(n²), so the choice comes down to the other differences below.

At a glance

PropertySelection sortQuick sort
TechniqueRepeatedly pick the smallest remaining valueDivide and conquer: partition around a pivot
Best case timeO(n²)O(n log n)
Average case timeO(n²)O(n log n)
Worst case timeO(n²)O(n²)
Extra spaceO(1)O(log n)
Stable (equal values keep their order)NoNo
In place (no extra array)YesYes
Needs sorted inputNoNo

When to choose each

Choose selection sort when

writing to memory is expensive, since it makes at most n - 1 swaps.

Avoid it when

the data is large, or you hope sorted input will be fast.

Choose quick sort when

you want a fast in-place sort on typical data.

Avoid it when

you need a worst-case guarantee or a stable sort.

The same inputs, counted

These numbers come from running both real implementations: operations (comparisons plus writes, a swap counting as two writes).

InputSelection sortQuick sort
Mixed2931
Already sorted2175
Reversed2751
Nearly sorted2365
Duplicates3129

See them run

More comparisons