Skip to content
SimpleScope

Sorting

Quick sort vs Radix sort

Quick sort and Radix sort both put an array in order, in different ways. Quick sort: divide and conquer: partition around a pivot. 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 quick sort takes O(n²) in the worst case. Radix sort is faster only when k and d are small compared with n; quick sort makes no assumption about the values.

At a glance

PropertyQuick sortRadix sort
TechniqueDivide and conquer: partition around a pivotSort digit by digit, least significant first, with a stable counting sort for each digit
Compares values with each otherYesNo
Best case timeO(n log n)O(d (n + k))
Average case timeO(n log n)O(d (n + k))
Worst case timeO(n²)O(d (n + k))
Extra spaceO(log n)O(n + k)
Stable (equal values keep their order)NoYes
In place (no extra array)YesNo
Needs sorted inputNoNo

When to choose each

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.

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.

InputQuick sortRadix sort
Mixed31141
Already sorted75141
Reversed51141
Nearly sorted65141
Duplicates29141

See them run

More comparisons