Lec 08 Sorting in Linear Time
Lec 08 Sorting in Linear Time
Lec 08 Sorting in Linear Time
a2:a3 a1:a3
6
The idea of radix sort
Used by the card-sorting machines you can now find only in
computer museums.
RADIX_SORTL2H(A, d)
1 for i 1 to d
2 do use a stable sort to sort array A on digit i
9
Complexity analysis
Lemma 8.3
Given n d-digit numbers in which each digit can take
on up to k possible values, RADIX-SORT correctly
sorts these numbers in (d(n + k)) time.
10
Complexity analysis (cont.)
Lemma 8.4
Given n b-bit numbers and any positive integer r ≤ b, RADIX-
SORT correctly sorts these numbers in ((b/r)(n+2r)) time.
Proof :
Choose d = b / r.
Discussion:
Case 1: If b < lg n, choose r = b, ((b/r)(n+2r)) = (n)
Case 2: If b ≥ lg n, choose r = lg n
((b/r)(n+2r)) = (bn / lgn)
11