Lecture 22 Minimum Spanning Tree

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

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:
CSE 780 Algorithms Advanced Algorithms Minimum spanning tree Generic algorithm Kruskal’s algorithm Prim’s algorithm.
Tree tree = connected graph with no cycle tree = connected graph with |V|-1 edges tree = graph with |V|-1 edges and no cycles.
Lecture 12 Minimum Spanning Tree. Motivating Example: Point to Multipoint Communication Single source, Multiple Destinations Broadcast – All nodes in.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 11 Instructor: Paul Beame.
Design and Analysis of Algorithms Minimum Spanning trees
Minimum Spanning Tree Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
Analysis of Algorithms
Graph Dr. Bernard Chen Ph.D. University of Central Arkansas.
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.
1 Minimum Spanning Trees. Minimum- Spanning Trees 1. Concrete example: computer connection 2. Definition of a Minimum- Spanning Tree.
Lecture 19 Greedy Algorithms Minimum Spanning Tree Problem.
November 13, Algorithms and Data Structures Lecture XII Simonas Šaltenis Aalborg University
1 22c:31 Algorithms Minimum-cost Spanning Tree (MST)
WEEK 12 Graphs IV Minimum Spanning Tree Algorithms.
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.
November 22, Algorithms and Data Structures Lecture XII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Data Structures & Algorithms Graphs Richard Newman based on book by R. Sedgewick and slides by S. Sahni.
Lecture ? The Algorithms of Kruskal and Prim
Minimum Spanning Trees
Minimum Spanning Trees
Chapter 9 : Graphs Part II (Minimum Spanning Trees)
Introduction to Algorithms
Minimum Spanning Trees
Minimum Spanning Trees
Minimum Spanning Trees
Minimum Spanning Tree Chapter 13.6.
Minimum Spanning Trees
Spanning Trees.
Spanning Trees Kruskel’s Algorithm Prim’s Algorithm
Minimum Spanning Trees
Lecture 12 Algorithm Analysis
CISC 235: Topic 10 Graph Algorithms.
Greedy Algorithms / Minimum Spanning Tree Yin Tat Lee
Data Structures & Algorithms Graphs
Minimum-Cost Spanning Tree
Minimum Spanning Tree.
Minimum Spanning Trees
Minimum Spanning Tree.
Minimum Spanning Tree.
Minimum Spanning Trees
Algorithms and Data Structures Lecture XII
Minimum Spanning Trees
Minimum-Cost Spanning Tree
Data Structures – LECTURE 13 Minumum spanning trees
Chapter 23 Minimum Spanning Tree
Minimum-Cost Spanning Tree
Kruskal’s Minimum Spanning Tree Algorithm
Lecture 12 Algorithm Analysis
Minimum Spanning Tree Algorithms
Shortest Paths and Minimum Spanning Trees
Minimum Spanning Trees
Minimum Spanning Trees
Minimum Spanning Tree.
CSE 373: Data Structures and Algorithms
Minimum Spanning Trees
CSE 417: Algorithms and Computational Complexity
Minimum Spanning Trees (MSTs)
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
Minimum-Cost Spanning Tree
Minimum Spanning Trees
Presentation transcript:

Lecture 22 Minimum Spanning Tree

Connect the cities using minimum length cable! Bikaner 325 Jaipur 1843 142 50 Kota 849 ChoMu 1205 337 Reengus 1743 802 1387 1099 Ajmer 1233 Jodhpur 1120 Sikar

Minimum Spanning Tree (MST) is a Spanning tree of a weighted graph with minimum total edge weight!

D 10 1 E A 6 7 9 3 F C 4 8 5 2 B G

Is MST unique?

MST Cycle Property 8 4 2 3 6 7 9 C e f 8 4 2 3 6 7 9 e C f

Cut Vertices 2 parts Edges across the parts U V 7 c 4 a 9 5 2 f e 8 8 3 d b 7

Cut Property U V U V 10 10 f f 4 4 9 9 5 5 2 2 8 8 8 3 8 3 e e 7 7

Prim-Jarnik’s MST Algorithm Start from s and grow MST as a cloud The sets are cloud and not-cloud At each step, pick smallest edge from cut, and move the vertex to the cloud Update the edges in cut

Example

 B D C A F E 7 4 2 8 5 3 9  7 D 2 B 4 8 9  5 2 F C 8 3 8 E A 7 7 B D C A F E 7 4 2 8 5 3 9  B D C A F E 7 4 2 8 5 3 9

B D C A F E 7 4 2 8 5 3 9 B D C A F E 7 4 2 8 5 3 9

Analysis m log n for update n log n for insert/remove So O((m+n) log n)

Kruskal’s MST Algorithm greedily add the edge with minimum weight to the MST ensure that the added edge does not form a cycle

Example

B G C A F D 4 1 3 5 10 2 8 7 6 E H 11 9 B G C A F D 4 1 3 5 10 2 8 7 6 E H 11 9 B G C A F D 4 1 3 5 10 2 8 7 6 E H 11 9 B G C A F D 4 1 3 5 10 2 8 7 6 E H 11 9

four steps two steps B G C A F D 4 1 3 5 10 2 8 7 6 E H 11 9 B G C A F

Kruksa’s Algorithm MST-Kruksal (G) A = ϕ for each vertex v in G.V MAKE-SET (v) Sort edges in non decreasing order of weights for each edge (u,v) taken in non-decreasing order if FIND-SET(u)≠ FIND-SET(v) A = A U {(u,v)} UNION (Su, Sv) return A;

Analysis of Kruskal’s Algorithm m log n

Minimum Spanning Tree is only defined for undirected graphs!

How do we check if a cycle is formed when an edge is included?

Cycle is formed if and only if u and v are already connected!

Maintain a data structure of sets!

Union-Find Partition Structures

Partitions with Union-Find Operations union(A,B ): Return the set A U B, destroying the old A and B find(p): Return the set containing the element at position p

List-based Implementation

Time Complexity When doing a union, always move elements from the smaller set to the larger set Total time needed to do n unions and finds is O(n log n).

The basic difference is in which edge you choose to add next to the spanning tree in each step. In Prim's, you always keep a connected component, starting with a single vertex. You look at all edges from the current component to other vertices and find the smallest among them. You then add the neighbouring vertex to the component, increasing its size by 1. In N-1 steps, every vertex would be merged to the current one if we have a connected graph. In Kruskal's, you do not keep one connected component but a forest. At each stage, you look at the globally smallest edge that does not create a cycle in the current forest. Such an edge has to necessarily merge two trees in the current forest into one. Since you start with N single-vertex trees, in N-1 steps, they would all have merged into one if the graph was connected.

What is the difference between Kruskal’s and Prim’s Algorithm? • Prim’s algorithm initializes with a node, whereas Kruskal’s algorithm initiates with an edge. • Prim’s algorithms span from one node to another while Kruskal’s algorithm select the edges in a way that the position of the edge is not based on the last step. • In prim’s algorithm, graph must be a connected graph while the Kruskal’s can function on disconnected graphs too. • Prim’s algorithm has a time complexity of O(V2), and Kruskal’s time complexity is O(logV).

Correctness of Kruskal’s Algorithm