Skip to content
SimpleScope

Sorting

Selection sort vs Radix sort

Selection sort and Radix sort both put an array in order, in different ways. Selection sort: repeatedly pick the smallest remaining value. Radix sort: sort digit by digit, least significant first, with a stable counting sort for each digit. Radix sort compares no values: it takes O(d (n + k)), where k is the number of possible values (or digit values) and d the number of digits (radix sort), while selection sort takes O(n²) in the worst case. Radix sort is faster only when k and d are small compared with n; selection sort makes no assumption about the values.

At a glance

PropertySelection sortRadix sort
TechniqueRepeatedly pick the smallest remaining valueSort digit by digit, least significant first, with a stable counting sort for each digit
Compares values with each otherYesNo
Best case timeO(n²)O(d (n + k))
Average case timeO(n²)O(d (n + k))
Worst case timeO(n²)O(d (n + k))
Extra spaceO(1)O(n + k)
Stable (equal values keep their order)NoYes
In place (no extra array)YesNo
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 radix sort when

many integers or fixed-length keys have few digit positions (d is small).

Avoid it when

the array is small, or the keys are long.

The same inputs, counted

These numbers come from running both real implementations: operations (comparisons plus writes, a swap counting as two writes). Radix sort makes no comparisons, so its count is writes only. The lesson always runs 3 digit passes, even on these one-digit numbers.

InputSelection sortRadix sort
Mixed29141
Already sorted21141
Reversed27141
Nearly sorted23141
Duplicates31141

See them run

More comparisons