Professional Documents
Culture Documents
Week-3 Linear Sort
Week-3 Linear Sort
ALGORITHMS
FOURTH EDITION
LECTURE NOTES FOR
CHAPTER 8
Sorting in Linear Time
2
CHAPTER 8 OVERVIEW
How fast can we sort?
• We will prove a lower bound, then beat it by playing a different game.
Comparison sorting
• The only operation that may be used to gain order information about a
sequence is comparison of pairs of elements.
• All sorts seen so far are comparison sorts: insertion sort, selection
sort, merge sort, quicksort, heapsort, treesort.
3
LOWER BOUNDS FOR SORTING (comparison sorts:)
Lower bounds
4
SORTING IN LINEAR TIME
Counting sort
5
SORTING IN LINEAR TIME (continued)
6
SORTING IN LINEAR TIME (continued)
7
SORTING IN LINEAR TIME (continued)
8
SORTING IN LINEAR TIME (continued)
9
SORTING IN LINEAR TIME (continued)
10
SORTING IN LINEAR TIME (continued)
11
SORTING IN LINEAR TIME (continued)
12
SORTING IN LINEAR TIME (continued)
13
SORTING IN LINEAR TIME (continued)
14
SORTING IN LINEAR TIME (continued)
15
SORTING IN LINEAR TIME (continued)
16
RADIX SORT
17
RADIX SORT
18
EXAMPLE
19
EXAMPLE
20
EXAMPLE
21
EXAMPLE
22
EXAMPLE
23
EXAMPLE (continued)
24
EXAMPLE (continued)
25
EXAMPLE (continued)
26
EXAMPLE (continued)
27
ANALYSIS
28
ANALYSIS
29
ANALYSIS
30
BUCKET SORT
31
BUCKET SORT
32
BUCKET SORT
33
EXAMPLE
37
ANALYSIS
38
ANALYSIS
39