Minimum-Cost Spanning Tree weighted connected undirected graph cost of spanning tree is sum of edge costs find spanning tree that has minimum cost Network.

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

Greed is good. (Some of the time)
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
1 Minimum Spanning Tree Prim-Jarnik algorithm Kruskal algorithm.
1 Greedy 2 Jose Rolim University of Geneva. Algorithmique Greedy 2Jose Rolim2 Examples Greedy  Minimum Spanning Trees  Shortest Paths Dijkstra.
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
Spanning Trees.
Chapter 9: Greedy Algorithms The Design and Analysis of Algorithms.
Minimum-Cost Spanning Tree weighted connected undirected graph spanning tree cost of spanning tree is sum of edge costs find spanning tree that has minimum.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 11 Instructor: Paul Beame.
More Graph Algorithms Weiss ch Exercise: MST idea from yesterday Alternative minimum spanning tree algorithm idea Idea: Look at smallest edge not.
Design and Analysis of Algorithms Minimum Spanning trees
Parallel Programming – Graph Algorithms David Monismith CS599 Notes are primarily based upon Introduction to Parallel Programming, Second Edition by Grama,
Minimum Spanning Trees. Subgraph A graph G is a subgraph of graph H if –The vertices of G are a subset of the vertices of H, and –The edges of G are a.
Minimum Spanning Tree Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
Shortest Path Algorithms. Kruskal’s Algorithm We construct a set of edges A satisfying the following invariant:  A is a subset of some MST We start with.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Graph Algorithms: Minimum.
1 GRAPHS - ADVANCED APPLICATIONS Minimim Spanning Trees Shortest Path Transitive Closure.
Week -7-8 Topic - Graph Algorithms CSE – 5311 Prepared by:- Sushruth Puttaswamy Lekhendro Lisham.
MST Many of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill.
Graph Dr. Bernard Chen Ph.D. University of Central Arkansas.
0 Course Outline n Introduction and Algorithm Analysis (Ch. 2) n Hash Tables: dictionary data structure (Ch. 5) n Heaps: priority queue data structures.
COSC 2007 Data Structures II Chapter 14 Graphs III.
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 CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
Graph Algorithms. Definitions and Representation An undirected graph G is a pair (V,E), where V is a finite set of points called vertices and E is a finite.
Minimum Spanning Trees and Kruskal’s Algorithm CLRS 23.
© 2015 JW Ryder CSCI 203 Data Structures1. © 2015 JW Ryder CSCI 203 Data Structures2.
Spanning Trees CSIT 402 Data Structures II 1. 2 Two Algorithms Prim: (build tree incrementally) – Pick lower cost edge connected to known (incomplete)
Lecture 19 Greedy Algorithms Minimum Spanning Tree Problem.
Graph Algorithms Ananth Grama, Anshul Gupta, George Karypis, and Vipin Kumar Adapted for 3030 To accompany the text ``Introduction to Parallel Computing'',
1 Prim’s algorithm. 2 Minimum Spanning Tree Given a weighted undirected graph G, find a tree T that spans all the vertices of G and minimizes the sum.
SPANNING TREES Lecture 20 CS2110 – Fall Spanning Trees  Definitions  Minimum spanning trees  3 greedy algorithms (incl. Kruskal’s & Prim’s)
Minimum Spanning Trees CSE 373 Data Structures Lecture 21.
Spanning Tree Algorithms William T. Trotter and Mitchel T. Keller Math 3012 – Applied Combinatorics Spring 2009.
Minimum- Spanning Trees
1 22c:31 Algorithms Minimum-cost Spanning Tree (MST)
Prims Algorithm for finding a minimum spanning tree
Data Structures & Algorithms Graphs Richard Newman based on book by R. Sedgewick and slides by S. Sahni.
Minimum Spanning Trees
Chapter 9 : Graphs Part II (Minimum Spanning Trees)
Minimum Spanning Tree Chapter 13.6.
Minimum Spanning Trees
Lecture 22 Minimum Spanning Tree
Parallel Graph Algorithms
Greedy Algorithms / Minimum Spanning Tree Yin Tat Lee
Short paths and spanning trees
Minimum Spanning Trees
Data Structures & Algorithms Graphs
Minimum-Cost Spanning Tree
Minimum Spanning Tree.
Minimum Spanning Trees
Minimum Spanning Tree Neil Tang 3/25/2010
Minimum Spanning Tree.
Minimum Spanning Tree.
Minimum-Cost Spanning Tree
Minimum-Cost Spanning Tree
Kruskal’s Minimum Spanning Tree Algorithm
Minimum Spanning Tree Neil Tang 4/3/2008
Minimum Spanning Tree.
CS 584 Project Write up Poster session for final Due on day of final
Minimum Spanning Trees (MSTs)
Parallel Graph Algorithms
Prim’s Minimum Spanning Tree Algorithm Neil Tang 4/1/2008
CSE 373: Data Structures and Algorithms
Lecture 14 Minimum Spanning Tree (cont’d)
Minimum-Cost Spanning Tree
INTRODUCTION A graph G=(V,E) consists of a finite non empty set of vertices V , and a finite set of edges E which connect pairs of vertices .
Minimum Spanning Trees
More Graphs Lecture 19 CS2110 – Fall 2009.
Presentation transcript:

Minimum-Cost Spanning Tree weighted connected undirected graph cost of spanning tree is sum of edge costs find spanning tree that has minimum cost Network has 10 edges. Spanning tree has only n - 1 = 7 edges. Need to either select 7 edges or discard Example

Edge Selection Greedy Strategies Start with an n vertex forest. Consider edges in ascending order of cost. Select edge if it does not form a cycle together with already selected edges.  Kruskal’s method Start with a 1 vertex tree and grow it into an n vertex tree by repeatedly adding a vertex and an edge. When there is a choice, add a least cost edge.  Prim’s method

Kruskal’s Method Start with a forest that has no edges Consider edges in ascending order of cost. Edge (1,2) is considered first and added to the forest.

Kruskal’s Method Edge (7,8) is considered next and added Edge (3,4) is considered next and added. 4 Edge (5,6) is considered next and added. 6 Edge (2,3) is considered next and added. 7 Edge (1,3) is considered next and rejected because it creates a cycle.

Kruskal’s Method Edge (2,4) is considered next and rejected because it creates a cycle Edge (3,5) is considered next and added Edge (3,6) is considered next and rejected. 7 Edge (5,7) is considered next and added. 14

Kruskal’s Method n - 1 edges have been selected and no cycle formed. So we must have a spanning tree. Cost is 46. Min-cost spanning tree is unique when all edge costs are different

Prim’s Method Start with any single vertex tree Get a 2 vertex tree by adding a cheapest edge. 6 6 Get a 3 vertex tree by adding a cheapest edge Grow the tree one edge at a time until the tree has n - 1 edges (and hence has all n vertices)

Another Example for Prim’s Method b a d c f e a b c d e f a   2 b   c  d   e   f 2    5 0 a b c d e f D[.] =  

Another Example for Prim’s Method b a d c f e a b c d e f a   2 b   c  d   e   f 2    5 0 a b c d e f D[.] =   a b c d e f new D[.] = 

Another Example for Prim’s Method b a d c f e a b c d e f a   2 b   c  d   e   f 2    5 0 a b c d e f D[.] =  a b c d e f new D[.] =

Another Example for Prim’s Method b a d c f e a b c d e f a   2 b   c  d   e   f 2    5 0 a b c d e f D[.] = a b c d e f new D[.] =

Another Example for Prim’s Method b a d c f e a b c d e f a   2 b   c  d   e   f 2    5 0 a b c d e f D[.] = a b c d e f new D[.] =

Another Example for Prim’s Method b a d c f e a b c d e f a   2 b   c  d   e   f 2    5 0 a b c d e f D[.] = a b c d e f new D[.] =

Greedy Minimum-Cost Spanning Tree Methods Can prove that all result in a minimum-cost spanning tree. Prim’s method is fastest.  O(n 2 ) (worst case)  O((n+e) log n) if a Min Heap is used to keep track of distances of vertices to partially built tree. If e=O(n 2 ), MinHeap is not a good idea! Kruskal’s uses union-find trees to run in O(n + e log e) time.

P processors, n=|V| vertices Each processor is assigned n/p vertices (P i gets the set V i ) Each PE holds the n/p columns of A and n/p elements of d[] array... d[.] A P0P0P0P0 P1P1P1P1 PiPiPiPi P P p-1 | | | ….. n/p columns Parallel MST Algorithm (Prim’s)

1. Initialize: Vt := {r}; d[k] =  for all k (except d[r] = 0) 2. P 0 broadcasts selectedV = r using one-to-all broadcast. 3. The PE responsible for "selectedV" marks it as belonging to set Vt. 4. For v = 2 to n=|V| do 5. Each P i updates d[k] = Min[d[k], w(selectedV, k)] for all k  Vi 6. Each P i computes MIN-di = (minimum d[] value among its unselected elements) 7. PEs perform a "global minimum" using MIN-di values and store the result in P 0. Call the winning vertex, selectedV. 8. P 0 broadcasts "selectedV" using one-to-all broadcast. 9. The PE responsible for "selectedV" marks it as belonging to set Vt. 10. EndFor

TIME COMPLEXITY ANALYSIS : In the worst-case, T seq = n 2 (Hypercube) T par = n*(n/p) + n*logp computation + communication (Mesh) T par = n*(n/p) + n * Sqrt(p) The algorithm is cost-optimal on a hypercube if plogp/n = O(1) Parallel MST Algorithm (Prim’s)

Dijkstra’s SSSP Algorithm b a d c f e a b c d e f a   2 b   c  d   e   f 2    5 0 a b c d e f L [.] =  S new L[i] = Min{ L[i], L[k] + W[k, i] } where k is the newly-selected intermediate node and W[.] is the distance between k and i

b a d c f e a b c d e f a   2 b   c  d   e   f 2    5 0 a b c d e f L [.] =   a b c d e f new L [.] =  Dijkstra’s SSSP Algorithm new L[i] = Min{ L[i], L[k] + W[k, i] } where k is the newly-selected intermediate node and W[.] is the distance between k and i

b a d c f e a b c d e f a   2 b   c  d   e   f 2    5 0 a b c d e f L [.] =  a b c d e f new L [.] = Dijkstra’s SSSP Algorithm new L[i] = Min{ L[i], L[k] + W[k, i] } where k is the newly-selected intermediate node and W[.] is the distance between k and i

b a d c f e a b c d e f a   2 b   c  d   e   f 2    5 0 a b c d e f L [.] = a b c d e f new L [.] = Dijkstra’s SSSP Algorithm new L[i] = Min{ L[i], L[k] + W[k, i] } where k is the newly-selected intermediate node and W[.] is the distance between k and i

b a d c f e a b c d e f a   2 b   c  d   e   f 2    5 0 a b c d e f L [.] = a b c d e f new L [.] = Dijkstra’s SSSP Algorithm new L[i] = Min{ L[i], L[k] + W[k, i] } where k is the newly-selected intermediate node and W[.] is the distance between k and i

b a d c f e a b c d e f a   2 b   c  d   e   f 2    5 0 a b c d e f L [.] = a b c d e f new L [.] = Dijkstra’s SSSP Algorithm new L[i] = Min{ L[i], L[k] + W[k, i] } where k is the newly-selected intermediate node and W[.] is the distance between k and i

Task Partitioning for Parallel SSSP Algorithm P processors, n=|V| vertices Each processor is assigned n/p vertices (P i gets the set V i ) Each PE holds the n/p columns of A and n/p elements of L[] array as shown below... L[.] A P0P0P0P0 P1P1P1P1 PiPiPiPi P P p-1 | | | ….. n/p columns

1. Initialize: Vt := {r}; L[k] =  for all k except L[r] = 0; 2. P 0 broadcasts selectedV = r using one-to-all broadcast. 3. The PE responsible for "selectedV" marks it as belonging to set Vt. 4. For v = 2 to n=|V| do 5. Each P i updates L[k] = Min[ L[k], L(selectedV)+W(selectedV, k) ] for  k  Vi 6. Each P i computes MIN-Li = (minimum L[.] value among its unselected elements) 7. PEs perform a "global minimum" using MIN-Li values and result is stored in P 0. Call the winning vertex, selectedV. 8. P 0 broadcasts "selectedV" and L[selectedV] using one-to-all broadcast. 9. The PE responsible for "selectedV" marks it as belonging to set Vt. 10. EndFor Parallel SSSP Algorithm (Dijkstra’s)

TIME COMPLEXITY ANALYSIS : In the worst-case, T seq = n 2 (Hypercube) T par = n*(n/p) + n*logp computation + communication (Mesh) T par = n*(n/p) + n * Sqrt(p) The algorithm is cost-optimal on a hypercube if plogp/n = O(1) Parallel SSSP Algorithm (Dijkstra’s)