Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 13 Minumum spanning trees Motivation Properties of minimum spanning trees Kruskal’s.

Slides:



Advertisements
Similar presentations
Comp 122, Spring 2004 Greedy Algorithms. greedy - 2 Lin / Devi Comp 122, Fall 2003 Overview  Like dynamic programming, used to solve optimization problems.
Advertisements

Greedy Algorithms Greed is good. (Some of the time)
Minimum Spanning Trees Definition Two properties of MST’s Prim and Kruskal’s Algorithm –Proofs of correctness Boruvka’s algorithm Verifying an MST Randomized.
Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm.
Minimum Spanning Tree CSE 331 Section 2 James Daly.
Minimum Spanning Tree (MST) form a tree that connects all the vertices (spanning tree). minimize the total edge weight of the spanning tree. Problem Select.
1 Greedy 2 Jose Rolim University of Geneva. Algorithmique Greedy 2Jose Rolim2 Examples Greedy  Minimum Spanning Trees  Shortest Paths Dijkstra.
Chapter 23 Minimum Spanning Trees
Minimum Spanning Tree Algorithms
CSE 780 Algorithms Advanced Algorithms Minimum spanning tree Generic algorithm Kruskal’s algorithm Prim’s algorithm.
Minimum Spanning Trees Definition Algorithms –Prim –Kruskal Proofs of correctness.
Lecture 18: Minimum Spanning Trees Shang-Hua Teng.
1 Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm.
Analysis of Algorithms CS 477/677
Lecture 12 Minimum Spanning Tree. Motivating Example: Point to Multipoint Communication Single source, Multiple Destinations Broadcast – All nodes in.
CSE Algorithms Minimum Spanning Trees Union-Find Algorithm
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 11 Instructor: Paul Beame.
Midwestern State University Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm 1.
1.1 Data Structure and Algorithm Lecture 13 Minimum Spanning Trees Topics Reference: Introduction to Algorithm by Cormen Chapter 13: Minimum Spanning Trees.
Design and Analysis of Computer Algorithm September 10, Design and Analysis of Computer Algorithm Lecture 5-2 Pradondet Nilagupta Department of Computer.
Graph, Spring 2004 © L. Joskowicz 1 Graphs and basic search algorithms Motivation Definitions and properties Representation Breadth-First Search Depth-First.
Theory of Computing Lecture 10 MAS 714 Hartmut Klauck.
Definition: Given an undirected graph G = (V, E), a spanning tree of G is any subgraph of G that is a tree Minimum Spanning Trees (Ch. 23) abc d f e gh.
Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm Binary Search Trees1.
Algorithms: Design and Analysis Summer School 2013 at VIASM: Random Structures and Algorithms Lecture 3: Greedy algorithms Phan Th ị Hà D ươ ng 1.
MST Many of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill.
2IL05 Data Structures Fall 2007 Lecture 13: Minimum Spanning Trees.
Introduction to Algorithms L ECTURE 14 (Chap. 22 & 23) Greedy Algorithms I 22.1 Graph representation 23.1 Minimum spanning trees 23.1 Optimal substructure.
Spring 2015 Lecture 11: Minimum Spanning Trees
UNC Chapel Hill Lin/Foskey/Manocha Minimum Spanning Trees Problem: Connect a set of nodes by a network of minimal total length Some applications: –Communication.
Minimum Spanning Trees and Kruskal’s Algorithm CLRS 23.
 2004 SDU Lecture 7- Minimum Spanning Tree-- Extension 1.Properties of Minimum Spanning Tree 2.Secondary Minimum Spanning Tree 3.Bottleneck.
1 Minimum Spanning Trees. Minimum- Spanning Trees 1. Concrete example: computer connection 2. Definition of a Minimum- Spanning Tree.
1 Greedy Algorithms and MST Dr. Ying Lu RAIK 283 Data Structures & Algorithms.
November 13, Algorithms and Data Structures Lecture XII Simonas Šaltenis Aalborg University
Chapter 23: Minimum Spanning Trees: A graph optimization problem Given undirected graph G(V,E) and a weight function w(u,v) defined on all edges (u,v)
F d a b c e g Prim’s Algorithm – an Example edge candidates choosen.
Finding Minimum Spanning Trees Algorithm Design and Analysis Week 4 Bibliography: [CLRS]- Chap 23 – Minimum.
© 2007 Seth James Nielson Minimum Spanning Trees … or how to bring the world together on a budget.
 2004 SDU Lecture 6- Minimum Spanning Tree 1.The Minimum Spanning Tree Problem 2.Greedy algorithms 3.A Generic Algorithm 4.Kruskal’s Algorithm.
1 22c:31 Algorithms Minimum-cost Spanning Tree (MST)
© 2007 Seth James Nielson Minimum Spanning Trees … or how to bring the world together on a budget.
1 Week 3: Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm.
MST Lemma Let G = (V, E) be a connected, undirected graph with real-value weights on the edges. Let A be a viable subset of E (i.e. a subset of some MST),
Lecture 12 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
Algorithm Design and Analysis June 11, Algorithm Design and Analysis Pradondet Nilagupta Department of Computer Engineering This lecture note.
Minimum Spanning Tree. p2. Minimum Spanning Tree G=(V,E): connected and undirected w: E  R, weight function a b g h i c f d e
Midwestern State University Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm 1.
November 22, Algorithms and Data Structures Lecture XII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Greedy Algorithms General principle of greedy algorithm
Lecture ? The Algorithms of Kruskal and Prim
Introduction to Algorithms
Spanning Trees Kruskel’s Algorithm Prim’s Algorithm
Minimum Spanning Trees
Lecture 12 Algorithm Analysis
Minimum Spanning Tree.
Algorithms and Data Structures Lecture XII
Data Structures – LECTURE 13 Minumum spanning trees
Chapter 23 Minimum Spanning Tree
CS 583 Analysis of Algorithms
Lecture 12 Algorithm Analysis
Minimum Spanning Tree Algorithms
Minimum Spanning Trees
Minimum Spanning Tree.
Minimum Spanning Trees
Greedy Algorithms Comp 122, Spring 2004.
Lecture 12 Algorithm Analysis
Advanced Algorithms Analysis and Design
Chapter 23: Minimum Spanning Trees: A graph optimization problem
Minimum Spanning Trees
Presentation transcript:

Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 13 Minumum spanning trees Motivation Properties of minimum spanning trees Kruskal’s algorithm Prim’s algorithm Chapter 23 in the textbook (pp 561—579).

Data Structures, Spring 2004 © L. Joskowicz 2 Motivation Given a set of nodes and possible connections with weights between them, find the subset of connections that connects all the nodes and whose sum of weights is the smallest. Examples: –telephone switching network –electronic board wiring The nodes and subset of connections form a tree! This tree is called the Minimum Spanning Tree (MST – ( עץ פורש מינימום

Data Structures, Spring 2004 © L. Joskowicz 3 Example: spanning tree bcd hgf iae Cost: 51

Data Structures, Spring 2004 © L. Joskowicz 4 Example: minimum spanning tree bcd hgf iae Cost: 37

Data Structures, Spring 2004 © L. Joskowicz 5 Spanning trees Definition: Let G=(V,E) be a weighted connected undirected graph. A spanning tree of G is a subset T  E of edges, such that the sub-graph G’=(V,T) is connected and acyclic. The minimum spanning tree (MST) is a spanning tree that minimizes the sum:

Data Structures, Spring 2004 © L. Joskowicz 6 Generic MST algorithm Greedy strategy: grow the minimum spanning tree one edge at a time, making sure that the added edge preserves the tree structure and the minimality condition  add “safe” edges incrementally. Generic-MST(G=(V,E)) T =  ; while (T is not a spanning tree of G) do choose a safe edge e=(u,v)  E T = T  {e} return T

Data Structures, Spring 2004 © L. Joskowicz 7 Properties of MST (1) Question: how to find safe edges efficiently? Theorem 1: Let and e=(u,v) be a minimum weight edge with one endpoint in U and the other in V–U. Then there exists a minimum spanning tree T such that e is in T. UV–U V T

Data Structures, Spring 2004 © L. Joskowicz 8 Properties of MST (2) bcd hgf iae U V–U cut

Data Structures, Spring 2004 © L. Joskowicz 9 Properties of MST (2) Proof: Let T be an MST. If e is not in T, add e to T. Because T is a tree, the addition of e creates a cycle which contains e and at least one more edge e’=(u’,v’), where u’  U and v’  V–U. Clearly, w(e) ≤ w(e’) since e is of minimum weight among the edges connecting U and V–U. We can thus delete e’ from T. The resulting T’ = T – {e’}  {e} is a tree whose weight is less or equal than that of T: w(T’) ≤ w(T).

Data Structures, Spring 2004 © L. Joskowicz 10 Properties of MST (3) Theorem 2: Let G=(V,E) be a connected undirected graph and A a subset of E included in a minimum spanning tree T for G. Let (U, V–U) be a cut that respects A (no edge of A crosses the cut), and let e=(u,v) be a minimum weight edge crossing (U, V–U). Then e is safe for A. UV–U V T cut A = T  E’

Data Structures, Spring 2004 © L. Joskowicz 11 Properties of MST (4) Proof: Define an edge e to be a light edge crossing a cut if its weight is the minimum crossing the cut. Let T be an MST that includes A, and assume T does not contain the light edge e = (u,v) (if it does, e is safe). Construct another MST T’ that includes A  {e}. The edge forms a cycle with edges on the path p from u to v in T. Since u and v are on opposite sides of the cut, there is at least one edge e’ = (x,y) in T on the path p that also crosses the cut. The edge e’ is not in A because the cut respects A. Since e’ is on the unique path from u to v in T, removing it breaks T into two components.

Data Structures, Spring 2004 © L. Joskowicz 12 Properties of MST (5) Adding e = (u,v) reconnects the two components to form a new spanning tree: T’ = T –{e’}  {e} We now show that T’ is an MST. Since e = (u,v) is a light edge crossing (U, V–U) and e’ = (x,y) also crosses this cut, w(u,v) ≤ w(x,y). Thus: w(T’) = w(T) – w(u,v) + w(x,y) ≤ w(T) Since T is an MST and w(T’) ≤ w(T), then w(T’) = w(T) and T’ is also an MST.

Data Structures, Spring 2004 © L. Joskowicz 13 Properties of MST (6) Corollary: Let G=(V,E) be a connected undirected graph and A a subset of E included in a minimum spanning tree T for G, and let C = (V C, E C ) be a tree in the forest G A = (V,A). If e is a light edge connecting C to some other component in G A, then e is safe for A. Proof: The cut (V C, V–V C ) respects A, and e is a light edge for this cut. Therefore, e is safe.

Data Structures, Spring 2004 © L. Joskowicz 14 Two algorithms to find an MST There are two ways of adding a safe edge: 1.Kruskal’s algorithm: the set A is a forest and the safe edge added is always the least-weight edge in the graph connecting two distinct components (Theorem 2). 2.Prim’s algorithm: the set A is a tree and the safe edge added is always the least-weight edge connecting A to a vertex not in A (Theorem 1).

Data Structures, Spring 2004 © L. Joskowicz 15 Kruskal’s algorithm MST-Kruskal(G) A   for each vertex v  V do Make-Set(v) sort the edges in E in non-decreasing weight order for each edge e = (u,v)  E do if Find-Set(u) ≠ Find-Set(v) /* the trees are distinct */ then A  A  {e} Union(u,v) /* combine two trees */ return A

Data Structures, Spring 2004 © L. Joskowicz 16 Example: Kruskal’s algorithm bcd hgf iae X X Cost: 37 X

Data Structures, Spring 2004 © L. Joskowicz 17 Analysis of Kruskal’s algorithm Correctness: follows directly from Theorem 2. Complexity: Depends on the implementation of the set operations! A naïve implementation takes O(|V| |E|). –Sorting the edges takes O(|E| lg |E|). –the for loop goes over every edge and performs two Find-Set and one Union operation. These can be implemented to take O(1) amortized time. The total running time is O(|E| lg |E|) = O(|E| lg |V|).

Data Structures, Spring 2004 © L. Joskowicz 18 Prim’s algorithm MST-Prim(G, root) for each vertex v  V do key(v)  ∞; π[v]  null key(root)  0; Q  V while Q is not empty do u  Extract-Min(Q) for each v that is a neighbor of u do if v  Q and w(u,v) < key(v) then π[v]  u key(v)  w(u,v) /*decrease value of key */

Data Structures, Spring 2004 © L. Joskowicz 19 Example: Prim’s algorithm bcd hgf iae Cost: 37 ∞ 0 ∞ ∞ ∞ ∞ ∞∞ ∞

Data Structures, Spring 2004 © L. Joskowicz 20 Analysis of Prim’s algorithm Correctness: follows directly from the Theorem 1. Complexity: Depends on the implementation of the minimum priority queue. With a binary mean-heap, we have: –Building the initial heap takes O(|V|). –Extract-Min takes O(lg |V|) per vertex  total O(|V| lg |V|) –The for loop is executed O(|E|). –Membership test is O(1). Decreasing a key is O(lg |V|). Overall, the running time is O(|V| lg |V| + |E| lg |V|) = O(|E| lg |V|).

Data Structures, Spring 2004 © L. Joskowicz 21 Summary: MST MST is a tree of all nodes with minimum total cost Two greedy algorithms for finding MST: –Kruskal’s algorithm: edge-based. Runs in O(|V| |E|). –Prim’s algorithm: vertex-based. Runs in O(|E| lg |V|). Complexity of Kruskal’s algorithm can be improved with Union-Find ADT to O(|E| lg |V|), Complexity of Prim’s algorithm can be improved with Fibonacci heaps to O(|V| lg |V| + |E|). Randomized algorithm takes O(|V| + |E|) expected time.