WEEK 12 Graphs IV Minimum Spanning Tree Algorithms.

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

Chapter 23 Minimum Spanning Tree
Graph Traversals and Minimum Spanning Trees. Graph Terminology.
Graphs By JJ Shepherd. Introduction Graphs are simply trees with looser restrictions – You can have cycles Historically hard to deal with in computers.
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:
Graph Traversals and Minimum Spanning Trees : Fundamental Data Structures and Algorithms Rose Hoberman April 8, 2003.
CSE 780 Algorithms Advanced Algorithms Minimum spanning tree Generic algorithm Kruskal’s algorithm Prim’s algorithm.
1 Graphs: shortest paths & Minimum Spanning Tree(MST) Fundamental Data Structures and Algorithms Ananda Guna April 8, 2003.
Lecture 18: Minimum Spanning Trees Shang-Hua Teng.
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.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 11 Instructor: Paul Beame.
Design and Analysis of Algorithms Minimum Spanning trees
Chapter 9: Graphs Spanning Trees Mark Allen Weiss: Data Structures and Algorithm Analysis in Java Lydia Sinapova, Simpson College.
1 Minimum Spanning Trees Longin Jan Latecki Temple University based on slides by David Matuszek, UPenn, Rose Hoberman, CMU, Bing Liu, U. of Illinois, Boting.
1 Minimum Spanning Trees Longin Jan Latecki Temple University based on slides by David Matuszek, UPenn, Rose Hoberman, CMU, Bing Liu, U. of Illinois, Boting.
Minimum Spanning Tree Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
Midwestern State University Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm 1.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Graph Algorithms: Minimum.
Design and Analysis of Computer Algorithm September 10, Design and Analysis of Computer Algorithm Lecture 5-2 Pradondet Nilagupta Department of Computer.
Analysis of Algorithms
Graph Dr. Bernard Chen Ph.D. University of Central Arkansas.
2IL05 Data Structures Fall 2007 Lecture 13: Minimum Spanning Trees.
Minimum Spanning Trees CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
1 Minimum Spanning Trees. Minimum- Spanning Trees 1. Concrete example: computer connection 2. Definition of a Minimum- Spanning Tree.
Spanning Trees CSIT 402 Data Structures II 1. 2 Two Algorithms Prim: (build tree incrementally) – Pick lower cost edge connected to known (incomplete)
1 Minimum Spanning Trees (some material adapted from slides by Peter Lee, Ananda Guna, Bettina Speckmann)
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)
Minimum Spanning Trees CSE 373 Data Structures Lecture 21.
1 22c:31 Algorithms Minimum-cost Spanning Tree (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.
Midwestern State University Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm 1.
Lecture ? The Algorithms of Kruskal and Prim
Instructor: Lilian de Greef Quarter: Summer 2017
Chapter 9 : Graphs Part II (Minimum Spanning Trees)
Introduction to Algorithms
Greedy function greedy { S <- S0 //Initialization
May 12th – Minimum Spanning Trees
Minimum Spanning Tree Chapter 13.6.
CSE373: Data Structures & Algorithms
Lecture 22 Minimum Spanning Tree
Minimum Spanning Trees and Shortest Paths
Minimum Spanning Trees
Lecture 12 Algorithm Analysis
Minimum-Cost Spanning Tree
Minimum Spanning Tree.
CSE373: Data Structures & Algorithms Lecture 12: Minimum Spanning Trees Catie Baker Spring 2015.
CSE373: Data Structures & Algorithms Lecture 20: Minimum Spanning Trees Linda Shapiro Spring 2016.
CSE 373 Data Structures and Algorithms
Minimum-Cost Spanning Tree
Minimum-Cost Spanning Tree
Lecture 12 Algorithm Analysis
CSE332: Data Abstractions Lecture 18: Minimum Spanning Trees
Minimum Spanning Trees
Minimum Spanning Trees
Minimum Spanning Tree.
Minimum Spanning Trees
Fundamental Structures of Computer Science II
CSE 373: Data Structures and Algorithms
CSE 373: Data Structures and Algorithms
Lecture 12 Algorithm Analysis
CSE 373: Data Structures and Algorithms
Lecture 14 Minimum Spanning Tree (cont’d)
Chapter 23: Minimum Spanning Trees: A graph optimization problem
Topological Sorting Minimum Spanning Trees Shortest Path
Chapter 9: Graphs Spanning Trees
Minimum-Cost Spanning Tree
Presentation transcript:

WEEK 12 Graphs IV Minimum Spanning Tree Algorithms

Minimum Spanning Tree (MST) Spanning Tree (Minimum) Spanning Tree

Minimum Spanning Tree (MST) A minimum spanning tree is a tree (i.e., it is acyclic) covers all the vertices V –contains |V| - 1 edges the total cost associated with tree edges is the minimum among all possible spanning trees not necessarily unique A minimum spanning tree of an undirected graph G is a tree formed from graph edges that connects all the vertices of G at a lowest cost.

Minimum Spanning Tree (MST) How to find the Minimum Spanning tree of a given undirected graph ??? 1. Prim’s Algorithm (~Dijsktra) 2. Kruskal’s Algorithm

a. Pick a vertex r to be the root b. Set r.distance = 0 (distance of vertex r), r.parent = null (parent of vertex r) c. For all vertices v  V, which are not r, set v.distance= , v.known =FALSE, v.parent=NULL d. Set r.known= TRUE and list all adjacent vertices of r, Set adjacent.parent =r and adjacent.distance=cost of edge e. Select vertex m with minimum distance Set m.known=TRUE If the distance of any adjacent vertex of m is less than the current value change the distance and the parent. f. Repeat Step e till all the vertices have known =TRUE. class Vertex { List adj; bool known; int distance; Vertex parent; } Prim’s Algorithm

Prim’s Algorithm Example I a c e d b v.distancev.parentv.known v.distancev.parentv.known v.distancev.parentv.known e0-FALSEe0-TRUEe0- a  -FALSEa  - a2d b  - b5e b5e c  - c5e c4d d  - d4e d4eTRUE v.distancev.parentv.known v.distancev.parentv.known v.distancev.parentv.known e0-TRUEe0- e0- a2d a2d a2d b5eFALSEb5e b5eTRUE c4dFALSEc4dTRUEc4d d4e d4e d4e

Prim’s Algorithm Example I a c e d b v.distancev.parentv.known e0-TRUE a2d b5e c4d d4e a c e d b

Prim’s Algorithm – Example II

Prim’s Algorithm – Time Complexity ● The running time is O(|V| 2 ) (|V| iterations in each of which a sequential scan is performed to find the minimum cost unknown edge ) without heaps, which is optimal for dense graphs. O(|E|*log|V|) ( an underlying binary heap with |V| elements is used, and |V| deleteMin ( for picking min cost vertex) and at most |E| decreaseKey (for updates) are performed each taking O(log|V|) time ) using binary heaps,which is good for sparse graphs

Kruskal’s Algorithm // Create the list of all edges E solution = { } // will include the list of MST edges while ( more edges in E) do // Selection select minimum weight(cost) edge remove edge from E // Feasibility if (edge closes a cycle with solution so far) then reject edge else add edge to solution // Solution check if |solution| = |V | - 1 return solution or use a sorted list of edges in increasing order

Kruskal’s Algorithm (once more in other words)!! EXAMPLE I a c e d b Create a forest of trees from the vertices Repeatedly merge trees by adding “safe edges” until only one tree remains A “safe edge” is an edge of minimum weight which does not create a cycle forest: {a}, {b}, {c}, {d}, {e}

Kruskal’s Algorithm : Example I Initialization a. Create a set for each vertex v  V b. Initialize the set of “safe edges” S (Solution set) comprising the MST to the empty set c. Sort edges by increasing weight a c e d b F = {a}, {b}, {c}, {d}, {e} S =  E = {(a,d), (c,d), (d,e), (a,c), (b,e), (c,e), (b,d), (a,b)}

Kruskal’s algorithm For each edge (u,v)  E in increasing order while more than one set remains: If u and v, belong to different sets U and V (if find(u)!=find(v)) a. Add edge (u,v) to the safe edge set (Solution set) S = S  {(u,v)} b. Merge the sets U and V (union(u,v)) Return S ● Running time bounded by sorting (or findMin) ● O( |E|log|E| )

Kruskal’s algorithm: Example I E = {(a,d), (c,d), (d,e), (a,c), (b,e), (c,e), (b,d), (a,b)} Forest {a}, {b}, {c}, {d}, {e} {a,d}, {b}, {c}, {e} {a,d,c}, {b}, {e} {a,d,c,e}, {b} {a,d,c,e,b} S  {(a,d)} {(a,d), (c,d)} {(a,d), (c,d), (d,e)} {(a,d), (c,d), (d,e), (b,e)} a c e d b We will use the sorted list of all edges  E

Kruskal’s Algorithm: Example II EdgeWeightAction {v1}{v2}{v3}{v4}{v5}{v6}{v7} (v1,v4)1Accepted{v1, v4}{v2}{v3}{v5}{v6}{v7} (v6,v7)1Accepted{v1, v4}{v2}{v3}{v5}{v6, v7} (v1,v2)2Accepted{v1, v4, v2}{v3}{v5}{v6, v7} (v3,v4)2Accepted{v1, v4, v2, v3}{v5}{v6, v7} (v2,v4)3Rejected{v1, v4, v2, v3}{v5}{v6, v7} (v1,v3)4Rejected{v1, v4, v2, v3}{v5}{v6, v7} (v4,v7)4Accepted{v1, v4, v2, v3, v6, v7}{v5} (v3,v6)5Rejected{v1, v4, v2, v3, v6, v7}{v5} (v5,v7)6Accepted{v1, v4, v2, v3, v6, v7,v5}  SOLUTION INCLUDES ALL VERTICES Minimum spanning tree is the list of accepted edges : (v1,v4), (v6,v7),(v1,v2), (v3,v4), (v4,v7)

Kruskal’s Algorithm : Pseudocode