Kruskal’s Minimum Spanning Tree Algorithm

Slides:



Advertisements
Similar presentations
Chapter 23 Minimum Spanning Tree
Advertisements

Comp 122, Spring 2004 Greedy Algorithms. greedy - 2 Lin / Devi Comp 122, Fall 2003 Overview  Like dynamic programming, used to solve optimization problems.
Greedy Algorithms Greed is good. (Some of the time)
Greed is good. (Some of the time)
Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm.
More Graph Algorithms Minimum Spanning Trees, Shortest Path Algorithms.
1 Greedy 2 Jose Rolim University of Geneva. Algorithmique Greedy 2Jose Rolim2 Examples Greedy  Minimum Spanning Trees  Shortest Paths Dijkstra.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 13 Minumum spanning trees Motivation Properties of minimum spanning trees Kruskal’s.
CSE 780 Algorithms Advanced Algorithms Minimum spanning tree Generic algorithm Kruskal’s algorithm Prim’s algorithm.
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.
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.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 11 Instructor: Paul Beame.
Design and Analysis of Algorithms Minimum Spanning trees
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.
Analysis of Algorithms
ADA: 10. MSTs1 Objective o look at two algorithms for finding mimimum spanning trees (MSTs) over graphs Prim's algorithm, Kruskal's algorithm Algorithm.
Algorithms: Design and Analysis Summer School 2013 at VIASM: Random Structures and Algorithms Lecture 3: Greedy algorithms Phan Th ị Hà D ươ ng 1.
2IL05 Data Structures Fall 2007 Lecture 13: Minimum Spanning Trees.
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.
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.
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.
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.
Data Structures & Algorithms Graphs Richard Newman based on book by R. Sedgewick and slides by S. Sahni.
Greedy Algorithms General principle of greedy algorithm
Lecture ? The Algorithms of Kruskal and Prim
Minimum Spanning Trees
Chapter 9 : Graphs Part II (Minimum Spanning Trees)
Introduction to Algorithms
Minimum Spanning Trees
Lecture 22 Minimum Spanning Tree
Minimum Spanning Trees
Lecture 12 Algorithm Analysis
CISC 235: Topic 10 Graph Algorithms.
Greedy Algorithms / Minimum Spanning Tree Yin Tat Lee
Minimum Spanning Trees
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.
Minimum Spanning Tree.
Minimum Spanning Trees
Algorithms and Data Structures Lecture XII
Minimum-Cost Spanning Tree
Data Structures – LECTURE 13 Minumum spanning trees
Minimum-Cost Spanning Tree
Minimum Spanning Trees
Analysis of Algorithms CS 477/677
Lecture 12 Algorithm Analysis
Minimum Spanning Trees
Minimum Spanning Tree.
Minimum Spanning Trees
Minimum Spanning Trees
Fundamental Structures of Computer Science II
Greedy Algorithms Comp 122, Spring 2004.
Minimum Spanning Trees (MSTs)
Lecture 12 Algorithm Analysis
Advanced Algorithms Analysis and Design
CSE 373: Data Structures and Algorithms
Chapter 23: Minimum Spanning Trees: A graph optimization problem
Minimum-Cost Spanning Tree
Minimum Spanning Trees
Presentation transcript:

Kruskal’s Minimum Spanning Tree Algorithm

Kruskal’s Algorithm Select edges in the order of smallest weights and accept an edge if it does not cause a cycle. Kruskal’s algorithm maintains a forest of trees. Initially each vertex is a tree with single node There are |V| trees. Then, adding an accepted edge merges two trees in the forest When algorithm terminates, there is a single tree with |V| vertices and it is a minimum spanning tree.

Initial Forest (all vertices are disjoint sets) 2 v1 v2 10 4 1 3 2 7 v3 v4 v5 8 4 6 5 v6 1 v7

Initial Forest Candidate edges are shown (edges that have low cost and edges that connect two trees) Step 1 v2 v5 v3 v6 v7 4 2 1 5 8 7 3 10 6 v1 v4

Initial Forest Step 2 Accept one of the candidate edges: (v1, v4) (we can do random accept here). 2 v1 v2 10 4 1 3 2 7 v3 v4 v5 8 4 6 5 v6 1 v7

Initial Forest Step 3 Merge the two trees connected by that edge. Obtain a new tree in this way. 2 v1 v2 10 4 1 3 2 7 v3 v4 v5 8 4 6 5 v6 1 v7

Repeat previous steps! Edge (v6-v7) is accepted. 2 v1 v2 10 4 1 3 2 7 v3 v4 v5 8 4 6 5 v6 1 v7

Merge the two trees connected by that edge! 2 v1 v2 10 4 1 3 2 7 v3 v4 v5 8 4 6 5 v6 1 v7

Accept edge (v1, v2) 2 v1 v2 10 4 1 3 2 7 v3 v4 v5 8 4 6 5 v6 1 v7

Merge the two trees connected by that edge! 2 v1 v2 10 4 1 3 2 7 v3 v4 v5 8 4 6 5 v6 1 v7

Accept edge (v3, v4) 2 v1 v2 10 4 1 3 2 7 v3 v4 v5 8 4 6 5 v6 1 v7

Merge the two trees connected by that edge! 2 v1 v2 10 4 1 3 2 7 v3 v4 v5 8 4 6 5 v6 1 v7

Accept edge (v4, v7) 2 v1 v2 10 4 1 3 2 7 v3 v4 v5 8 4 6 5 v6 1 v7

Merge the two trees connected by that edge! 2 v1 v2 10 4 1 3 2 7 v3 v4 v5 8 4 6 5 v6 1 v7

Accept edge (v7, v5) 2 v1 v2 10 4 1 3 2 7 v3 v4 v5 8 4 6 5 v6 1 v7

Merge the two trees connected by that edge! 2 v1 v2 10 4 1 3 2 7 v3 v4 v5 8 4 6 5 v6 1 v7

The resulting MST is shown below! Finished! The resulting MST is shown below! 2 v1 v2 1 2 v3 v4 v5 4 6 v6 1 v7

Kruskal’s Algorithm How is it different from Prim’s algorithm? Prim’s algorithm grows one tree all the time Kruskal’s algorithm grows multiple trees (i.e., a forest) at the same time. Trees are merged together using safe edges Since an MST has exactly |V| - 1 edges, after |V| - 1 merges, we would have only one component u v tree1 tree2

Kruskal’s Algorithm Start with each vertex being its own component d e h g f i 4 8 7 11 1 2 14 9 10 6 Start with each vertex being its own component Repeatedly merge two components into one by choosing the light edge that connects them Which components to consider at each iteration? Scan the set of edges in monotonically increasing order by weight We would add edge (c, f)

Example Add (h, g) Add (c, i) Add (g, f) Add (a, b) Add (c, f) Ignore (i, g) Add (c, d) Ignore (i, h) Add (a, h) Ignore (b, c) Add (d, e) Ignore (e, f) Ignore (b, h) Ignore (d, f) {g, h}, {a}, {b}, {c}, {d}, {e}, {f}, {i} {g, h}, {c, i}, {a}, {b}, {d}, {e}, {f} {g, h, f}, {c, i}, {a}, {b}, {d}, {e} {g, h, f}, {c, i}, {a, b}, {d}, {e} {g, h, f, c, i}, {a, b}, {d}, {e} {g, h, f, c, i, d}, {a, b}, {e} {g, h, f, c, i, d, a, b}, {e} {g, h, f, c, i, d, a, b, e} a b c d e h g f i 4 8 7 11 1 2 14 9 10 6 {a}, {b}, {c}, {d}, {e}, {f}, {g}, {h}, {i}

Implementation of Kruskal’s Algorithm Uses a disjoint-set data structure to determine whether an edge connects vertices in different components

Operations on Disjoint Data Sets MAKE-SET(u) – creates a new set whose only member is u FIND-SET(u) – returns a representative element from the set that contains u Any of the elements of the set that has a particular property E.g.: Su = {r, s, t, u}, the property is that the element be the first one alphabetically FIND-SET(u) = r FIND-SET(s) = r FIND-SET has to return the same value for a given set

Operations on Disjoint Data Sets UNION(u, v) – unites the dynamic sets that contain u and v, say Su and Sv E.g.: Su = {r, s, t, u}, Sv = {v, x, y} UNION (u, v) = {r, s, t, u, v, x, y} Running time for FIND-SET and UNION depends on implementation.

KRUSKAL(V, E, w) (cont.) A ←  for each vertex v  V do MAKE-SET(v) sort E into non-decreasing order by w for each (u, v) taken from the sorted list do if FIND-SET(u)  FIND-SET(v) then A ← A  {(u, v)} UNION(u, v) return A - Running time: O(V+ElgE+ElgV)=O(ElgE) - Since E=O(V2), we have lgE=O(2lgV)=O(lgV) O(V) O(ElgE) O(E) O(lgV) O(ElgV)

Kruskal’s Algorithm Kruskal’s algorithm is a “greedy” algorithm Kruskal’s greedy strategy produces a globally optimum solution u v S V - S x y

Which one is more complex O( |E| ) O( |O| ) Depends on the number of the edges