Skip to content
SimpleScope

Sorting

Insertion sort vs Radix sort

Insertion sort and Radix sort both put an array in order, in different ways. Insertion sort: insert each value into a sorted prefix. 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 insertion sort takes O(n²) in the worst case. Radix sort is faster only when k and d are small compared with n; insertion sort makes no assumption about the values.

At a glance

PropertyInsertion sortRadix sort
TechniqueInsert each value into a sorted prefixSort 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)YesYes
In place (no extra array)YesNo
Needs sorted inputNoNo

When to choose each

Choose insertion sort when

the array is small or nearly sorted.

Avoid it when

the array is large and in random order.

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.

InputInsertion sortRadix sort
Mixed30141
Already sorted12141
Reversed48141
Nearly sorted14141
Duplicates36141

See them run

More comparisons