Skip to content
SimpleScope

Sorting

Bubble sort vs Radix sort

Bubble sort and Radix sort both put an array in order, in different ways. Bubble sort: swap neighbors that are out of order. 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 bubble sort takes O(n²) in the worst case. Radix sort is faster only when k and d are small compared with n; bubble sort makes no assumption about the values.

At a glance

PropertyBubble sortRadix sort
TechniqueSwap neighbors that are out of orderSort 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 bubble sort when

you want the simplest sort to explain, on tiny or almost sorted data.

Avoid it when

the data is large.

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.

InputBubble sortRadix sort
Mixed40141
Already sorted6141
Reversed63141
Nearly sorted13141
Duplicates47141

See them run

More comparisons