Algorithms & Models of Computation CS/ECE 374, Fall 2017 Algorithms for Minimum Part I Spanning Trees Algorithms for Minimum Spanning Lecture 20 Tree Thursday, November 9, 2017 Sariel Har-Peled (UIUC) CS374 1 Fall 2017 1 / 46 Sariel Har-Peled (UIUC) CS374 2 Fall 2017 2 / 46 Minimum Spanning Tree Applications Input Connected graph G = ( V , E ) with edge costs Network Design 1 Goal Find T ⊆ E such that ( V , T ) is connected and total Designing networks with minimum cost but maximum 1 connectivity cost of all edges in T is smallest Approximation algorithms T is the minimum spanning tree ( MST ) of G 2 1 Can be used to bound the optimality of algorithms to 1 20 20 approximate Traveling Salesman Problem, Steiner Trees, etc. 1 2 1 2 Cluster Analysis 3 23 4 15 23 4 15 1 1 9 9 6 7 3 6 7 3 36 36 16 16 3 3 28 28 25 25 5 4 5 4 17 17 Sariel Har-Peled (UIUC) CS374 3 Fall 2017 3 / 46 Sariel Har-Peled (UIUC) CS374 4 Fall 2017 4 / 46
Some basic properties of Spanning Trees A graph G is connected iff it has a spanning tree Every spanning tree of a graph on n nodes has n − 1 edges Part II Let T = ( V , E T ) be a spanning tree of G = ( V , E ) . For every non-tree edge e ∈ E \ E T there is a unique cycle C in T + e . For every edge f ∈ C − { e } , T − f + e is another Safe and unsafe edges spanning tree of G . Sariel Har-Peled (UIUC) CS374 5 Fall 2017 5 / 46 Sariel Har-Peled (UIUC) CS374 6 Fall 2017 6 / 46 Assumption Cuts And for now . . . V \ S S S Definition Assumption Given a graph G = ( V , E ) , a cut is Edge costs are distinct, that is no two edge costs are equal. a partition of the vertices of the graph into two sets ( S , V \ S ) . Edges having an endpoint on both sides are the edges of the cut . A cut edge is crossing the cut. Sariel Har-Peled (UIUC) CS374 7 Fall 2017 7 / 46 Sariel Har-Peled (UIUC) CS374 8 Fall 2017 8 / 46
Safe and Unsafe Edges Every edge is either safe or unsafe Definition Proposition An edge e = ( u , v ) is a safe edge if there is some partition of V If edge costs are distinct then every edge is either safe or unsafe. into S and V \ S and e is the unique minimum cost edge crossing S (one end in S and the other in V \ S ). Definition An edge e = ( u , v ) is an unsafe edge if there is some cycle C such that e is the unique maximum cost edge in C . Proposition If edge costs are distinct then every edge is either safe or unsafe. Proof. Exercise. Sariel Har-Peled (UIUC) CS374 9 Fall 2017 9 / 46 Sariel Har-Peled (UIUC) CS374 10 Fall 2017 10 / 46 Safe edge Unsafe edge Example... Example... Every cut identifies one safe edge... Every cycle identifies one unsafe edge... 5 5 V \ S V \ S S S 7 7 13 13 3 3 7 7 3 3 2 2 15 15 15 5 5 ...the most expensive edge in the cycle. 11 11 Safe edge in the cut ( S, V \ S ) ...the cheapest edge in the cut. Note: An edge e may be a safe edge for many cuts! Sariel Har-Peled (UIUC) CS374 11 Fall 2017 11 / 46 Sariel Har-Peled (UIUC) CS374 12 Fall 2017 12 / 46
Example Some key observations Proofs later 20 20 1 2 1 2 Lemma If e is a safe edge then every minimum spanning tree contains e . 23 4 15 23 4 15 1 1 9 9 Lemma 6 7 3 6 7 3 36 36 If e is an unsafe edge then no MST of G contains e . 16 16 28 3 28 3 25 25 5 4 5 4 17 17 Figure: Graph with unique edge costs. Safe edges are red, rest are unsafe. And all safe edges are in the MST in this case... Sariel Har-Peled (UIUC) CS374 13 Fall 2017 13 / 46 Sariel Har-Peled (UIUC) CS374 14 Fall 2017 14 / 46 Greedy Template Initially E is the set of all edges in G T is empty (* T will store edges of a MST *) while E is not empty do Part III choose e ∈ E if ( e satisfies condition) add e to T return the set T The Algorithms Main Task: In what order should edges be processed? When should we add edge to spanning tree? KA PA RD Sariel Har-Peled (UIUC) CS374 15 Fall 2017 15 / 46 Sariel Har-Peled (UIUC) CS374 16 Fall 2017 16 / 46
Kruskal’s Algorithm Prim’s Algorithm Process edges in the order of their costs (starting from the least) and T maintained by algorithm will be a tree. Start with a node in T . In add edges to T as long as they don’t form a cycle. each iteration, pick edge with least attachment cost to T . 20 1 2 20 1 2 1 2 1 2 23 4 15 1 23 4 15 1 9 6 7 3 36 9 6 7 3 6 7 3 6 7 3 36 16 28 25 3 16 28 25 3 5 4 17 5 4 5 4 5 4 20 17 1 2 1 2 20 1 2 1 2 23 4 15 1 1 23 4 15 1 1 9 6 7 3 6 7 3 36 9 Sariel Har-Peled (UIUC) CS374 17 Fall 2017 17 / 46 Sariel Har-Peled (UIUC) CS374 18 Fall 2017 18 / 46 6 7 3 6 7 3 36 16 28 25 3 16 28 25 3 Reverse Delete Algorithm Bor˚ uvka’s Algorithm 5 4 5 4 17 5 4 5 4 20 17 1 2 1 2 Simplest to implement. See notes. 20 1 2 Initially E is the set of all edges in G 1 2 Assume G is a connected graph. T is E (* T will store edges of a MST *) 4 23 4 15 1 while E is not empty do 1 1 23 4 15 T is ∅ (* T will store edges of a MST *) 1 choose e ∈ E of largest cost while T is not spanning do 9 if removing e does not disconnect T then 6 7 3 6 7 3 36 X ← ∅ 9 6 7 3 remove e from T 6 7 3 36 for each connected component S of T do return the set T 16 add to X the cheapest edge between S and V \ S 28 25 3 3 16 28 25 3 Add edges in X to T Returns a minimum spanning tree. Back return the set T 5 4 5 4 17 5 4 5 4 20 17 1 2 1 2 1 2 20 1 2 4 23 4 15 4 1 1 1 23 4 15 1 9 9 6 7 3 6 7 3 6 7 3 36 9 6 7 3 36 16 28 25 3 3 16 28 25 3 Sariel Har-Peled (UIUC) CS374 19 Fall 2017 19 / 46 Sariel Har-Peled (UIUC) CS374 20 Fall 2017 20 / 46 5 4 5 4 5 4 17
Bor˚ uvka’s Algorithm 20 1 2 Part IV 23 4 15 1 9 6 7 3 36 Correctness 16 28 3 25 5 4 17 Sariel Har-Peled (UIUC) CS374 21 Fall 2017 21 / 46 Sariel Har-Peled (UIUC) CS374 22 Fall 2017 22 / 46 Correctness of MST Algorithms Key Observation: Cut Property Lemma Many different MST algorithms 1 All of them rely on some basic properties of MST s, in particular If e is a safe edge then every minimum spanning tree contains e . 2 the Cut Property to be seen shortly. Proof. Suppose (for contradiction) e is not in MST T . 1 Since e is safe there is an S ⊂ V such that e is the unique min 2 cost edge crossing S . Since T is connected, there must be some edge f with one end 3 in S and the other in V \ S Since c f > c e , T ′ = ( T \ { f } ) ∪ { e } is a spanning tree of 4 lower cost! Error: T ′ may not be a spanning tree!! Sariel Har-Peled (UIUC) CS374 23 Fall 2017 23 / 46 Sariel Har-Peled (UIUC) CS374 24 Fall 2017 24 / 46
Error in Proof: Example Proof of Cut Property Problematic example. S = { 1 , 2 , 7 } , e = (7 , 3) , f = (1 , 6) . T − f + e is not a Proof. spanning tree. (A) Consider adding the edge f . 1 Suppose e = ( v , w ) is not in MST 1 20 20 20 20 (B) It is safe because it is the 1 2 1 2 1 2 1 2 T and e is min weight edge in cut 2 20 20 20 cheapest edge in the cut. 1 2 ( S , V \ S ) . Assume v ∈ S . 1 2 1 2 23 23 23 23 4 15 4 15 4 15 4 15 1 1 1 1 e (C) Lets throw out the edge e T is spanning tree: there is a unique 3 2 23 4 15 23 4 15 23 4 15 1 1 1 currently in the spanning tree path P from v to w in T 9 9 9 9 P 6 7 3 6 7 3 6 7 3 6 7 3 which is more expensive than f Let w ′ be the first vertex in P 36 36 36 36 f f f 9 9 9 3 6 7 3 6 7 3 6 7 3 belonging to V \ S ; let v ′ be the and is in the same cut. Put it f e e 36 36 36 16 16 16 16 3 3 3 3 28 25 28 25 28 25 28 25 instead... vertex just before it on P , and let 16 16 16 25 3 25 3 25 3 28 28 28 e ′ = ( v ′ , w ′ ) (D) New graph of selected edges 4 5 4 5 4 5 4 5 4 (A) (B) (C) (D) 17 17 17 17 is not a tree anymore. BUG. T ′ = ( T \ { e ′ } ) ∪ { e } is spanning 4 5 4 5 4 5 4 17 17 17 tree of lower cost. (Why?) Sariel Har-Peled (UIUC) CS374 25 Fall 2017 25 / 46 Sariel Har-Peled (UIUC) CS374 26 Fall 2017 26 / 46 Proof of Cut Property (contd) Safe Edges form a Tree Observation Lemma T ′ = ( T \ { e ′ } ) ∪ { e } is a spanning tree. Let G be a connected graph with distinct edge costs, then the set of safe edges form a connected graph. Proof. Proof. T ′ is connected. Removed e ′ = ( v ′ , w ′ ) from T but v ′ and w ′ are connected Suppose not. Let S be a connected component in the graph 1 by the path P − f + e in T ′ . Hence T ′ is connected if T is. induced by the safe edges. T ′ is a tree Consider the edges crossing S , there must be a safe edge among 2 them since edge costs are distinct and so we must have picked it. T ′ is connected and has n − 1 edges (since T had n − 1 edges) and hence T ′ is a tree Sariel Har-Peled (UIUC) CS374 27 Fall 2017 27 / 46 Sariel Har-Peled (UIUC) CS374 28 Fall 2017 28 / 46
Recommend
More recommend