























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!
























2
O(n 2 )
O(nlgn) O(nlgn) - average
4
5
output array
7
C (frequencies)^ Cnew (cumulative sums)
8
1 2 3 4 5 6 7 8 A
1 2 3 4 5 Cnew^8
0
10
1 2 3 4 5 6 7 8 A
1 2 3 4 5 6 7 8 B
0 2 3 5 7
1 2 3 4 5 C (^8)
0
1 2 3 4 5 6 7 8 B
0 2 3 4 7
1 2 3 4 5 C (^7)
0
1 2 3 4 5 6 7 8 B
0 2 3 4 7
1 2 3 4 5 C (^8)
0
1 2 3 4 5 6 7 8 B
11
Alg.: COUNTING-SORT(A, B, n, k)
1. for i ← 0 **to r
1 n
0 k
A
C 1 n B
j
13
16
d=O(1) and k =O(n)
17
Alg.: RADIX-SORT(A, d)
for i ← 1 to d do use a stable sort to sort array A on digit i (stable sort: preserves order of identical elements)
19