Radix Sort
 Considers binary representation of keys
 assumes that the keys are represented in a base M number system
Straight Radix Sort
5, 0, 2, 7, 3
1. Represent numbers in binary
101, 000, 010, 111, 011
2. At every iteration examine a column of bits starting from the right to the left.
Examine column K and while keeping the order, sort elements based on the bit in that column.
K = 0
1 0 1 000
0 0 0 010
0 1 0 => 101
1 1 1 111
0 1 1 011
K = 1
0 0 0 000
0 1 0 101
1 0 1 => 010
1 1 1 111
0 1 1 011
k = 2
0 0 0 000 0
1 0 1 010 2
0 1 0 => 011 3
1 1 1 101 5
0 1 1 111 7
Assuming that number of bits used to represent the keys is "b" then the
complexity of this algorithm is b*O(n) = O(bn)
/ \
number of iterations steps needed at each iteration
Assuming sorting int of 32 bits
n b O(bn) O(nlog n)
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document1024 32 O(32 * 1024) O(1024 * 10) < better
1024 3 O(3 * 1024) O(1024 * 10)

better
Radix sort is better than other O(n log n) algorithms only when b is small.
101 000 000 000 = 0
This is the end of the preview.
Sign up
to
access the rest of the document.
 Fall '08
 Staff
 Data Structures, Sort, Max, worst case, Haystack

Click to edit the document details