CS 473G Algorithmsx
Total Page:16
File Type:pdf, Size:1020Kb
CS 473g Algorithms¬ Sariel Har-Peled December 7, 2009 This work is licensed under the Creative Commons Attribution-Noncommercial 3.0 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc/3.0/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. 2 Contents Preface 11 I NP Completeness 13 1 NP Completeness I 15 1.1 Introduction . 15 1.2 Complexity classes . 17 1.2.1 Reductions . 18 1.3 More NP-Complete problems . 19 1.3.1 3SAT ..................................... 19 1.4 Bibliographical Notes . 21 2 NP Completeness II 23 2.1 Max-Clique . 23 2.2 Independent Set . 25 2.3 Vertex Cover . 25 2.4 Graph Coloring . 26 3 NP Completeness III 29 3.1 Hamiltonian Cycle . 29 3.2 Traveling Salesman Problem . 30 3.3 Subset Sum . 31 3.4 3 dimensional Matching (3DM) . 32 3.5 Partition . 33 4 Dynamic programming 35 4.1 Basic Idea - Partition Number . 35 4.1.1 Memoization: . 37 4.2 Fibonacci numbers . 38 4.3 Edit Distance . 39 5 Dynamic programming II - The Recursion Strikes Back 43 5.1 Optimal Search Trees . 43 5.2 Optimal Triangulations . 45 3 5.3 Matrix Multiplication . 46 5.4 Longest Ascending Subsequence . 47 5.5 Pattern Matching . 47 6 Approximation algorithms 49 6.1 Greedy algorithms and approximation algorithms . 49 6.1.1 Alternative algorithm – two for the price of one . 51 6.2 Traveling Salesman Person . 51 6.2.1 TSP with the triangle inequality . 52 6.2.1.1 A 2-approximation . 52 6.2.1.2 A 3=2-approximation to TSP ,-Min . 53 4 6.3 Biographical Notes . 55 7 Approximation algorithms II 57 7.1 Max Exact 3SAT . 57 7.2 Approximation Algorithms for Set Cover . 58 7.2.1 Guarding an Art Gallery . 58 7.2.2 Set Cover . 59 7.3 Biographical Notes . 60 8 Approximation algorithms III 61 8.1 Clustering . 61 8.1.1 The approximation algorithm for k-center clustering . 62 8.2 Subset Sum . 64 8.2.1 On the complexity of "-approximation algorithms . 65 8.2.2 Approximating subset-sum . 65 8.2.2.1 Bounding the running time of ApproxSubsetSum ........ 67 8.2.2.2 The result . 67 8.3 Approximate Bin Packing . 68 8.4 Bibliographical notes . 68 II Randomized Algorithms 69 9 Randomized Algorithms 71 9.1 Some Probability . 71 9.2 Sorting Nuts and Bolts . 72 9.2.1 Running time analysis . 72 9.2.1.1 Alternative incorrect solution . 73 9.2.2 What are randomized algorithms? . 73 9.3 Analyzing QuickSort . 74 10 Randomized Algorithms II 77 10.1 QuickSort with High Probability . 77 10.1.1 Proving that an elements participates in small number of rounds. 77 10.2 Chernoff inequality . 79 4 10.2.1 Preliminaries . 79 10.2.2 Chernoff inequality . 79 10.2.2.1 The Chernoff Bound — General Case . 81 11 Min Cut 83 11.1 Min Cut . 83 11.1.1 Problem Definition . 83 11.1.2 Some Definitions . 83 11.2 The Algorithm . 84 11.2.1 Analysis . 86 11.2.1.1 The probability of success. 86 11.2.1.2 Running time analysis. 87 11.3 A faster algorithm . 87 11.4 Bibliographical Notes . 90 III Network Flow 91 12 Network Flow 93 12.1 Network Flow . 93 12.2 Some properties of flows, max flows, and residual networks . 94 12.3 The Ford-Fulkerson method . 97 12.4 On maximum flows . 98 13 Network Flow II - The Vengeance 101 13.1 Accountability . 101 13.2 Ford-Fulkerson Method . 101 13.3 The Edmonds-Karp algorithm . 102 13.4 Applications and extensions for Network Flow . 104 13.4.1 Maximum Bipartite Matching . 104 13.4.2 Extension: Multiple Sources and Sinks . 105 14 Network Flow III - Applications 107 14.1 Edge disjoint paths . 107 14.1.1 Edge-disjoint paths in a directed graphs . 107 14.1.2 Edge-disjoint paths in undirected graphs . 108 14.2 Circulations with demands . 109 14.2.1 Circulations with demands . 109 14.2.1.1 The algorithm for computing a circulation . 110 14.3 Circulations with demands and lower bounds . 110 14.4 Applications . 111 14.4.1 Survey design . 111 5 15 Network Flow IV - Applications II 113 15.1 Airline Scheduling . 113 15.1.1 Modeling the problem . 114 15.1.2 Solution . 114 15.2 Image Segmentation . 115 15.3 Project Selection . 117 15.3.1 The reduction . 118 15.4 Baseball elimination . 119 15.4.1 Problem definition . 119 15.4.2 Solution . 120 15.4.3 A compact proof of a team being eliminated . 120 IV Min Cost Flow 123 16 Network Flow V - Min-cost flow 125 16.1 Minimum Average Cost Cycle . 125 16.2 Potentials . 127 16.3 Minimum cost flow . 128 16.4 A Strongly Polynomial Time Algorithm for Min-Cost Flow . 130 16.5 Analysis of the Algorithm . 131 16.5.1 Reduced cost induced by a circulation . 132 16.5.2 Bounding the number of iterations . 132 16.6.