I Foundations: Preface
I Foundations: Preface
Preface xiii
I Foundations
Introduction 3
1 The Role of Algorithms in Computing 5
1.1 Algorithms 5
1.2 Algorithms as a technology 12
2 Getting Started 17
2.1 Insertion sort 17
2.2 Analyzing algorithms 25
2.3 Designing algorithms 34
3 Characterizing Running Times 49
3.1 O-notation, �-notation, and ‚-notation 50
3.2 Asymptotic notation: formal definitions 53
3.3 Standard notations and common functions 63
4 Divide-and-Conquer 76
4.1 Multiplying square matrices 80
4.2 Strassen’s algorithm for matrix multiplication 85
4.3 The substitution method for solving recurrences 90
4.4 The recursion-tree method for solving recurrences 95
4.5 The master method for solving recurrences 101
? 4.6 Proof of the continuous master theorem 107
? 4.7 Akra-Bazzi recurrences 115
vi Contents
Introduction 157
6 Heapsort 161
6.1 Heaps 161
6.2 Maintaining the heap property 164
6.3 Building a heap 167
6.4 The heapsort algorithm 170
6.5 Priority queues 172
7 Quicksort 182
7.1 Description of quicksort 183
7.2 Performance of quicksort 187
7.3 A randomized version of quicksort 191
7.4 Analysis of quicksort 193
8 Sorting in Linear Time 205
8.1 Lower bounds for sorting 205
8.2 Counting sort 208
8.3 Radix sort 211
8.4 Bucket sort 215
9 Medians and Order Statistics 227
9.1 Minimum and maximum 228
9.2 Selection in expected linear time 230
9.3 Selection in worst-case linear time 236
Introduction 361
14 Dynamic Programming 362
14.1 Rod cutting 363
14.2 Matrix-chain multiplication 373
14.3 Elements of dynamic programming 382
14.4 Longest common subsequence 393
14.5 Optimal binary search trees 400
15 Greedy Algorithms 417
15.1 An activity-selection problem 418
15.2 Elements of the greedy strategy 426
15.3 Huffman codes 431
15.4 Offline caching 440
16 Amortized Analysis 448
16.1 Aggregate analysis 449
16.2 The accounting method 453
16.3 The potential method 456
16.4 Dynamic tables 460
viii Contents
VI Graph Algorithms
Introduction 547
20 Elementary Graph Algorithms 549
20.1 Representations of graphs 549
20.2 Breadth-first search 554
20.3 Depth-first search 563
20.4 Topological sort 573
20.5 Strongly connected components 576
21 Minimum Spanning Trees 585
21.1 Growing a minimum spanning tree 586
21.2 The algorithms of Kruskal and Prim 591
22 Single-Source Shortest Paths 604
22.1 The Bellman-Ford algorithm 612
22.2 Single-source shortest paths in directed acyclic graphs 616
22.3 Dijkstra’s algorithm 620
22.4 Difference constraints and shortest paths 626
22.5 Proofs of shortest-paths properties 633
Contents ix
Introduction 745
26 Parallel Algorithms 748
26.1 The basics of fork-join parallelism 750
26.2 Parallel matrix multiplication 770
26.3 Parallel merge sort 775
27 Online Algorithms 791
27.1 Waiting for an elevator 792
27.2 Maintaining a search list 795
27.3 Online caching 802
28 Matrix Operations 819
28.1 Solving systems of linear equations 819
28.2 Inverting matrices 833
28.3 Symmetric positive-definite matrices and least-squares approximation
838
29 Linear Programming 850
29.1 Linear programming formulations and algorithms 853
29.2 Formulating problems as linear programs 860
29.3 Duality 866
30 Polynomials and the FFT 877
30.1 Representing polynomials 879
30.2 The DFT and FFT 885
30.3 FFT circuits 894
x Contents
Introduction 1139
A Summations 1140
A.1 Summation formulas and properties 1140
A.2 Bounding summations 1145
Contents xi
Bibliography 1227
Index 1251