Radix Sort
| Operation | Method | Time | Adaptive? | In-Place? | Stable? | Online? |
|---|---|---|---|---|---|---|
| Radix sort | Non-Comparison | ** | ** | ** | ** |
Idea
The main idea is to sort
is the less significant figure(rightmost), the one we start with. is the most significant figure (leftmost)
The result is sorting by starting from the rightmost figure to the leftmost one.

The Algorithm
radixsort(array A, int d)
for (i = 1 to d):
sort(A, i) #Use a stable sorting algorithm on the i-th figureradixsort(array A, int d)
for (i = 1 to d):
sort(A, i) #Use a stable sorting algorithm on the i-th figureCorrectness Demonstration
Demonstration by induction on the target column to sort
- Base Case:
, we sort the only column - Inductive Hypothesis: We assume the figures of the columns
are sorted - Inductive Step: We demonstrate that a stable algorithm on the
-th column, keeps the columns sorted - If two figures in position
are equal, by the principle of stability, they remain in the same order as they were given. Plus, by Inductive Hypothesis they are sorted. - If two figures in position
are not equal, the algorithm sorts them on the -th column and puts them in the right position.
- If two figures in position
Lemma
Given
Time Complexity Demonstration
For each iteration the cost is
Final Time Complexity:
sort()is a stable sorting algorithm to order the array, based on- In this case
- In this case
- If
, - If
and ,
Space Complexity Demonstration - Not In-Place
Let us suppose to have
We can divide every integer in
The time of execution of the radix sort is
Given the values of
Case 1 -
Then, for every value of
In this case we choose
Case 2 -
Then,
must be large must be small, else it would be dominant on
The best choice is
Conclusions
In general we use the radix sort when the input is made of integers in the interval