1.17k likes | 1.31k Views
CS5234 Combinatorial and Graph Algorithms. Welcome!. Problem Sets Programming Assignment Exams. Administrative. CS5234 Overview. Problem set 1 due PS1: Hand it in now! Problem set 2 released tonight PS2: Submit next week IVLE (optional, electronic submission)
E N D
Problem Sets • Programming Assignment • Exams Administrative
CS5234 Overview • Problem set 1 due PS1: Hand it in now! • Problem set 2 released tonight PS2: Submit next week • IVLE (optional, electronic submission) Soon: Once registration completes…
CS5234 Overview • Problem set grading Distributed grading scheme: Once registration completes, there will be an IVLE survey where you choose a week. Grading supervised (and verified) by the TA.
CS5234 Overview • How to draw pictures? By hand: Either submit hardcopy, or scan, or take a picture with your phone! Or use a tablet / iPad… Digitally: 1. xfig (ugh) 2. OmniGraffle (mac) 3. Powerpoint (hmmm) 4. ???
CS5234 Overview • Programming assignment(s): Berth assignment problem: Last 3-4 weeks of the semester. Very hard algorithmic problem (related to graph partitioning). Design the best solution you can! Must know or learn: C++ More details later…
CS5234 Overview • Mid-term exam October 8 In class • Final exam November 19Reading Week Exams will be graded and returned.
Vertex Cover Quick Review
Vertex Cover • Definition: Given: graph G = (V,E) Find: smallest cover C ⊆ V such that every edge e ∈ E is covered by some node v ∈ V. • Challenge: NP-complete: No polynomial time algorithm unless P = NP.
Vertex Cover Example: (Suboptimal) cover (size 9)
Vertex Cover Example: Optimal cover? (size 6)
Vertex Cover • Greedy approximation algorithm: repeat: until every edge is covered 1. Let e = (u,v) be an uncovered edge. 2. Add u and v to the cover. • Details: Graph representation: Sorted adjacency list…
Vertex Cover Analysis: 1. For every matching M: OPT ≥ |M|. 2. The cover C contains a matching of size |C|/2. 3. Therefore: OPT ≥ |C|/2. Conclusion:|C| ≤ 2OPT 2-approximation algorithm
Vertex Cover (Review) • Set Cover (Review + Analysis) • Steiner Trees Today’s Plan
Set Cover • Definition: Given: set X subsets S1, S2, …, Smwhere Sj⊆ X Find: smallest collection I ⊆ {1, …, m} such that: • Challenge: NP-complete: No polynomial time algorithm unless P = NP.
Set Cover X = {C, C++, Java, Ruby, Python} • Example: Alice: C, C++ Bob:C++, Java Collin:C++, Ruby, Python Dave:C, Java • Choose a good team: Collin and Dave: optimal solution.
Set Cover set that contains the most uncovered elements
Set Cover Example: 1. Choose S2.
Set Cover Example: Choose S2. Choose S3.
Set Cover Example: Choose S2. Choose S3. Choose S4.
Set Cover Example: Choose S2. Choose S3. Choose S4. Choose S1
Set Cover Example: Output: S1, S2, S3, S4 OPT: S1, S4, S5
Set Cover To get a good approximation, show a lower bound on OPT. • “OPT has to be AT LEAST this large.” • E.g., “OPT ≥ |M|”
Set Cover Example: Note: 12 elements ≤ 6 elements per set OPT ≥ 2
Set Cover Example: Note: 6 uncovered elements ≤ 3 elements per set OPT ≥ 2
Set Cover Example: General rule: k uncovered elements ≤ t elements per set OPT ≥ (k / t)
Notation Assume GREEDY covers elements in order: x1, x2, x3, x4, x5, x6, x7, x8, …, xn xj= the jth item covered
Notation Assume GREEDY covers elements in order: x1, x2, x3, x4, x5, x6, x7, x8, …, xn S4 covers 1 new item S3 covers 3 items S1 covers 2 new items S6 covers 2 new items
Notation Assume GREEDY covers elements in order: x1, x2, x3, x4, x5, x6, x7, x8, …, xn 2 2 1 3
Notation Assume GREEDY covers elements in order: x1, x2, x3, x4, x5, x6, x7, x8, …, xn c1, c2, c3, c4, c5, c6, c7, c8, …, cn 3, 3, 3, 2, 2, 2, 2, 1, …, cj = number of items covered in same step as xj 2 2 1 3
Notation Assume GREEDY covers elements in order: x1, x2, x3, x4, x5, x6, x7, x8, …, xn • cost(x1) = 1/3 • cost(x2) = 1/3 • cost(x3) = 1/3 • cost(x4) = 1/2 • cost(x5) = 1/2 • … cost(xj) = 1/cj= amount payed to cover xj 2 2 1 3
Notation Assume GREEDY covers elements in order: x1, x2, x3, x4, x5, x6, x7, x8, …, xn cost(xj) = 1/cj= amount payed to cover xj 2 2 1 3
Set Cover Example: Note: 6 uncovered elements ≤ 3 elements per set OPT ≥ 2
Analysis Assume (x1, x2, …, xj-1) are covered: • How does OPT cover (xj, xj+1, …, xn)?
Analysis Assume (x1, x2, …, xj-1) are covered: • How does OPT cover (xj, xj+1, …, xn)? Fact: No set covers more than c(xj) elements in the set (xj, xj+1, …, xn). Why? If it did, GREEDY would have chosen it! (Tip: use the fact that algorithm is GREEDY.)
Analysis Assume (x1, x2, …, xj-1) are covered: • How does OPT cover (xj, xj+1, …, xn)? As before: n – j + 1 uncovered elements ≤ c(xj) elements per set OPT ≥ (n – j + 1) / c(xj) = (n – j + 1)cost(xj)
Analysis Assume (x1, x2, …, xj-1) are covered: • How does OPT cover (xj, xj+1, …, xn)? As before: n – j + 1 uncovered elements ≤ c(xj) elements per set OPT ≥ (n – j + 1) / c(xj) = (n – j + 1)cost(xj) cost(xj) ≤ OPT / (n – j + 1)
Analysis Assume GREEDY covers elements in order: x1, x2, x3, x4, x5, x6, x7, x8, …, xn 2 2 1 3
Set Cover Conclusion: Theorem: Greedy-Set-Cover is an O(log n) approximation algorithm for set cover.
Vertex Cover (Review) • Set Cover (Review + Analysis) • Steiner Trees Today’s Plan
A Warm-Up Problem • Problem Statement: Given: 2d (Euclidean) map & set of points of interest Find: shortest set of roads connecting all points
A Warm-Up Problem • Problem Statement: Given: 2d (Euclidean) map & set of points of interest Find: shortest set of roads connecting all points
A Warm-Up Problem • Algorithm: Compute: for every pair (u,v): distance(u,v) Build: complete graph G = (V, E) where w(u,v) = distance(u,v) Find: minimum spanning tree of G.
Spanning Tree Definition: a spanning tree is an acyclic subset of the edges that connects all nodes Weight: 32 13 4 5 9 9 1 2 8
Minimum Spanning Tree Definition: a spanning tree with minimum weight 13 4 5 9 9 1 2 8
Minimum Spanning Tree Definition: a spanning tree with minimum weight Weight: 20 13 4 5 9 9 1 2 8
Properties of MST Property 1: No cycles
Properties of MST Property 2: If you cut an MST, the two pieces are both MSTs.
Properties of MST Property 3: Cycle property For every cycle, the maximum weight edge is not in the MST. max-weight edge on cycle