Kruskal’s Idea Adding one edge at a time Non-decreasing order No cycle

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

Chen, Lu Mentor: Zhou, Jian Shanghai University, School of Management Chen213.shu.edu.cn.
Minimum Spanning Tree CSE 331 Section 2 James Daly.
Minimum cost spanning tree and activity networks Data structure 2002/12/2.
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
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.
Lecture 12 Minimum Spanning Tree. Motivating Example: Point to Multipoint Communication Single source, Multiple Destinations Broadcast – All nodes in.
1 Pertemuan 13 Minimum Spanning Tree (MST) Matakuliah: T0534/Struktur Data Tahun: 2005 Versi: September 2005.
Is the following graph Hamiltonian- connected from vertex v? a). Yes b). No c). I have absolutely no idea v.
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 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.
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 Prof Amir Geva Eitan Netzer.
Minimum Spanning Tree Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Graph Algorithms: Minimum.
Minimum Spanning Trees and Kruskal’s Algorithm CLRS 23.
© 2015 JW Ryder CSCI 203 Data Structures1. © 2015 JW Ryder CSCI 203 Data Structures2.
Module 5 – Networks and Decision Mathematics Chapter 23 – Undirected Graphs.
Minimum spanning trees Aims: To know the terms: tree, spanning tree, minimum spanning tree. To understand that a minimum spanning tree connects a network.
Minimum Spanning Trees Suppose G = (V, E) is a undirected network. Each edge (i,j) in E has an associated ‘length’ c ij (cost, time, distance, …) Determine.
EMIS 8374 Optimal Trees updated 25 April slide 1 Minimum Spanning Tree (MST) Input –A (simple) graph G = (V,E) –Edge cost c ij for each edge e 
Minimum Spanning Trees Easy. Terms Node Node Edge Edge Cut Cut Cut respects a set of edges Cut respects a set of edges Light Edge Light Edge Minimum Spanning.
Minimum-Cost Spanning Tree CS 110: Data Structures and Algorithms First Semester,
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.
Minimum Spanning Trees CSE 373 Data Structures Lecture 21.
1 22c:31 Algorithms Minimum-cost Spanning Tree (MST)
Prims Algorithm for finding a minimum spanning tree
WEEK 12 Graphs IV Minimum Spanning Tree Algorithms.
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)
Introduction to Algorithms
Minimum Spanning Tree Chapter 13.6.
Minimum Spanning Trees
Lecture 22 Minimum Spanning Tree
COMP 6/4030 ALGORITHMS Prim’s Theorem 10/26/2000.
Topological Sort (topological order)
Short paths and spanning trees
Spanning Tree A spanning tree is any tree that consists solely of edges in G and that includes all the vertices in G. Example.
Data Structures & Algorithms Graphs
Autumn 2016 Lecture 11 Minimum Spanning Trees (Part II)
Minimum-Cost Spanning Tree
Spanning Trees.
Minimum Spanning Tree.
Minimum Spanning Trees
EMIS 8373: Integer Programming
Minimum Spanning Tree.
Autumn 2015 Lecture 11 Minimum Spanning Trees (Part II)
Spanning Trees.
Minimum-Cost Spanning Tree
Kruskal’s Algorithm for finding a minimum spanning tree
Chapter 23 Minimum Spanning Tree
Minimum-Cost Spanning Tree
Kruskal’s Minimum Spanning Tree Algorithm
Minimum Spanning Trees
Richard Anderson Lecture 10 Minimum Spanning Trees
Minimum Spanning Tree.
Minimum Spanning Trees
Lecture 14 Shortest Path (cont’d) Minimum Spanning Tree
CSE 373: Data Structures and Algorithms
Minimum Spanning Trees (MSTs)
The Greedy Approach Young CS 530 Adv. Algo. Greedy.
Winter 2019 Lecture 11 Minimum Spanning Trees (Part II)
CSE 373: Data Structures and Algorithms
Lecture 14 Minimum Spanning Tree (cont’d)
Lecture 13 Shortest Path (cont’d) Minimum Spanning Tree
Minimum-Cost Spanning Tree
Minimum Spanning Trees
Autumn 2019 Lecture 11 Minimum Spanning Trees (Part II)
Presentation transcript:

Kruskal’s Idea Adding one edge at a time Non-decreasing order No cycle Build a minimum cost spanning tree T by adding edges to T one at a time Non-decreasing order Select the edges for inclusion in T in non-decreasing order of the cost No cycle An edge is added to T if it does not form a cycle N-1 edges will be selected Since G is connected and has n > 0 vertices, exactly n-1 edges will be selected J.-J. Chen, CE NTPU May 25, 2015

Examples for Kruskal’s Algorithm 0 5 2 3 1 6 1 2 3 6 3 4 4 6 4 5 0 1 10 12 14 16 18 22 24 25 28 1 2 3 4 5 6 28 16 12 18 24 22 25 10 14 1 2 3 4 5 6 1 2 3 4 5 6 10 1 2 3 4 5 6 10 12 1 2 3 4 5 6 10 12 14 1 2 3 4 5 6 10 12 14 16 6/9 J.-J. Chen, CE NTPU May 25, 2015

0 5 2 3 1 6 1 2 3 6 3 4 4 6 4 5 0 1 10 1 2 3 4 5 6 1 2 3 4 5 6 12 10 10 14 14 16 14 16 16 25 12 12 18 22 22 22 24 cost = 10 +25+22+12+16+14 25 28 J.-J. Chen, CE NTPU May 25, 2015

Kruskal’s Algorithm Find the n-1 edges O(e log e) T= ; while((T contains less than n-1 edges) && (E is not empty) ) { choose an edge(v,w) from E of lowest cost; delete(v,w) from E; if((v,w) does not create a cycle in T) add(v,w) to T; else discard(v,w); } If (T contains fewer than n-1 edges) { cout << “No spanning tree” << endl; O(e log e) It can be proved that: kruskal’s algorithm is optimal if there is a spanning tree, kruskal will find it If there is a min-cost spanning tree U, then there exists a cost-preserving transformation that maps U to the one Kruskal find J.-J. Chen, CE NTPU May 25, 2015

Kruskal’s Algorithm 1 5 6 2 4 3   choose T= ; while((T contains less than n-1 edges) && (E is not empty) ) { choose an edge(v,w) from E of lowest cost; delete(v, w) from E; if((v, w) does not create a cycle in T) add(v, w) to T; else discard(v, w); } If (T contains fewer than n-1 edges) { cout << “No spanning tree” << endl; 28 10 1 14 16 5 6 2 24 25  18  12 4 choose 22 3 J.-J. Chen, CE NTPU May 25, 2015

(tree all the time vs. forest) Prim’s Algorithm (1) (tree all the time vs. forest) // Assume that G has at least one vertex TV={0}; // start with vertex 0 and no edges For (T= ; T contains fewer than n-1 edges; add(u,v) to T) { let (u,v) be a least-cost edge such that uTV and vTV; If(there is no such edge) break; Add v to TV } If(T contains fewer than n-1 edges) { cout << “No spanning tree” << end; J.-J. Chen, CE NTPU May 25, 2015

Prim’s Algorithm (2) 1 2 3 4 5 6 28 16 12 18 24 22 25 10 14 1 2 3 4 5 6 10 1 2 3 4 5 6 10 25 22 1 2 3 4 5 6 10 25 J.-J. Chen, CE NTPU May 25, 2015

Prim’s Algorithm (3) 1 2 3 4 5 6 28 16 12 18 24 22 25 10 14 1 2 3 4 5 6 10 25 22 12 1 2 3 4 5 6 10 25 22 12 16 1 2 3 4 5 6 10 25 22 12 16 14 J.-J. Chen, CE NTPU May 25, 2015

Prim’s Algorithm (cont’d) 28 10 1 14 16 5 6 2 24 25 18 12 4 22 3 J.-J. Chen, CE NTPU May 25, 2015

Sollin’s Algorithm Sollin’s Algorithm 1 5 6 2 4 3 Selects several edges for inclusion in T at each stage. At the start of a stage, the selected edges forms a spanning forest. During a stage we select a minimum cost edge that has exactly one vertex in the tree edge for each tree in the forest. Repeat until only one tree at the end of a stage or no edges remain for selection. Stage 1: (0, 5), (1, 6), (2, 3), (3, 2), (4, 3), (5, 0), (6, 1){(0, 5)}, {(1, 6)}, {(2, 3), (4, 3)} Stage 2: {(0, 5), (5, 4)}, {(1, 6), (1, 2)}, {(2, 3), (4, 3), (1, 2)} Result: {(0, 5), (5, 4), (1, 6), (1, 2), (2, 3), (4, 3)} 28 10 1 14 16 5 6 2 24 25 18 12 4 22 3 J.-J. Chen, CE NTPU May 25, 2015