Minimum Spanning Trees and Kruskal’s Algorithm CLRS 23.

Slides:



Advertisements
Similar presentations
Comp 122, Spring 2004 Greedy Algorithms. greedy - 2 Lin / Devi Comp 122, Fall 2003 Overview  Like dynamic programming, used to solve optimization problems.
Advertisements

Minimum Spanning Trees Definition Two properties of MST’s Prim and Kruskal’s Algorithm –Proofs of correctness Boruvka’s algorithm Verifying an MST Randomized.
Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm.
Minimum Spanning Tree CSE 331 Section 2 James Daly.
Minimum Spanning Tree (MST) form a tree that connects all the vertices (spanning tree). minimize the total edge weight of the spanning tree. Problem Select.
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.
Chapter 23 Minimum Spanning Trees
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 13 Minumum spanning trees Motivation Properties of minimum spanning trees Kruskal’s.
Minimum Spanning Tree Algorithms
CSE 780 Algorithms Advanced Algorithms Minimum spanning tree Generic algorithm Kruskal’s algorithm Prim’s algorithm.
1 7-MST Minimal Spanning Trees Fonts: MTExtra:  (comment) Symbol:  Wingdings: Fonts: MTExtra:  (comment) Symbol:  Wingdings:
Lecture 18: Minimum Spanning Trees Shang-Hua Teng.
1 Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
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.
CSE Algorithms Minimum Spanning Trees Union-Find Algorithm
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.
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.
Midwestern State University Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm 1.
1.1 Data Structure and Algorithm Lecture 13 Minimum Spanning Trees Topics Reference: Introduction to Algorithm by Cormen Chapter 13: Minimum Spanning Trees.
Design and Analysis of Computer Algorithm September 10, Design and Analysis of Computer Algorithm Lecture 5-2 Pradondet Nilagupta Department of Computer.
Theory of Computing Lecture 10 MAS 714 Hartmut Klauck.
Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm Binary Search Trees1.
MST Many of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill.
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.
1 Minimum Spanning Trees. Minimum- Spanning Trees 1. Concrete example: computer connection 2. Definition of a Minimum- Spanning Tree.
1 Greedy Algorithms and MST Dr. Ying Lu RAIK 283 Data Structures & Algorithms.
November 13, Algorithms and Data Structures Lecture XII Simonas Šaltenis Aalborg University
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)
Finding Minimum Spanning Trees Algorithm Design and Analysis Week 4 Bibliography: [CLRS]- Chap 23 – Minimum.
© 2007 Seth James Nielson Minimum Spanning Trees … or how to bring the world together on a budget.
 2004 SDU Lecture 6- Minimum Spanning Tree 1.The Minimum Spanning Tree Problem 2.Greedy algorithms 3.A Generic Algorithm 4.Kruskal’s Algorithm.
Greedy Algorithms Z. GuoUNC Chapel Hill CLRS CH. 16, 23, & 24.
1 22c:31 Algorithms Minimum-cost Spanning Tree (MST)
© 2007 Seth James Nielson Minimum Spanning Trees … or how to bring the world together on a budget.
1 Week 3: Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm.
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.
Minimum Spanning Trees Problem Description Why Compute MST? MST in Unweighted Graphs MST in Weighted Graphs –Kruskal’s Algorithm –Prim’s Algorithm 1.
Algorithm Design and Analysis June 11, Algorithm Design and Analysis Pradondet Nilagupta Department of Computer Engineering This lecture note.
Minimum Spanning Tree. p2. Minimum Spanning Tree G=(V,E): connected and undirected w: E  R, weight function a b g h i c f d e
Midwestern State University Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm 1.
November 22, Algorithms and Data Structures Lecture XII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Greedy Algorithms General principle of greedy algorithm
Lecture ? The Algorithms of Kruskal and Prim
Introduction to Algorithms
Minimum Spanning Trees
Spanning Trees Kruskel’s Algorithm Prim’s Algorithm
Minimum Spanning Trees
Lecture 12 Algorithm Analysis
Minimum Spanning Tree.
Algorithms and Data Structures Lecture XII
Data Structures – LECTURE 13 Minumum spanning trees
Chapter 23 Minimum Spanning Tree
CS 583 Analysis of Algorithms
Minimum Spanning Trees
Lecture 12 Algorithm Analysis
Minimum Spanning Tree Algorithms
Minimum Spanning Trees
Minimum Spanning Trees
Greedy Algorithms Comp 122, Spring 2004.
Lecture 12 Algorithm Analysis
Total running time is O(E lg E).
Advanced Algorithms Analysis and Design
Chapter 23: Minimum Spanning Trees: A graph optimization problem
Minimum Spanning Trees
Presentation transcript:

Minimum Spanning Trees and Kruskal’s Algorithm CLRS 23

Minimum Spanning Trees (MST) A common problem in communications networks and circuit design: connecting a set of nodes by a network of minimum total length Represent the problem as an undirected graph where edge weights denote wire lengths

Formally, Given a connected undirected graph G=(V,E), a spanning tree is an acyclic subset of edges T that connects all the vertices together. Assuming each edge (u,v) of G has a numeric weight (or cost) w(u,v), the cost of a spanning tree T is the sum of the weights of the edges in T. A minimum spanning tree (MST) is a spanning tree of minimum weight.

Minimum Spanning Trees (MST) Never pays to have cycles Resulting connection graph is connected, undirected and acyclic, hence a free tree Not unique Total weight = Total weight = 37

Generic MST Algorithm Two main algorithms for computing MSTs –Kruskal’s –Prim’s Both greedy algorithms The greedy strategy captured by a generic aproach: –Grow the MST one edge at a time –which edge to select?

Generic MST Algorithms Maintain a set of edges : A Loop invariant: A is a subset of some MST Safe edge (u,v): A U {(u,v)} is also a subset of an MST Generic-MST(G, w) A = empty set while A does not form a spanning tree do find an edge (u,v) that is safe for A A = A U {(u,v)} return A

How to recognize safe edges? Definitions first: Cut: Let S be a subset of vertices V. A cut (S, V-S) is a partition of vertices into two disjoint sets S and V-S S V-S

We say that an edge crosses the cut (S, V-S) if one of its endpoints is in S and the other is in (V-S) S V-S

We say that a cut respects a set A of edges if no edge in A crosses the cut Total weight = S V-S

An edge is a light edge crossing a cut if its weight is the minimum of any edge crossing the cut. Total weight = S V-S

How to recognize safe edges? Theorem: Let G=(V,E) be a connected undirected graph with a real valued weight function w defined on E. Let A be a subset of E that is included in some MST for G. Let (S, V-S) be any cut of G that respects A and let (u,v) be a light edge crossing (S, V-S). Then, edge (u,v) is safe for A.

Proof Suppose that no MST contains (u,v). Let T be an MST of G. u v x y T

Add (u,v) to T, creating a cycle. There must be at least one more edge on this cycle that crosses the cut: (x,y) u v x y 4 8 6

The edge (x,y) is not in A, since the cut respects A Remove (x,y) and restore the spanning tree T’ w(T’) = w(T) + w(u,v) – w(x,y) < w(T) –Conradicts the assumption that T is an MST. u v x y 4 6 T’

Kruskal’s Algorithm Add edges to A in increasing order of weights. –If the edge being considered introduces a cycle, skip it. –Otherwise add to A. Notice that the edges in A make a forest, and they keep getting merged together.

Correctness Say (u, v) is the edge is going to be added next, and it does not introduce a cycle in A. Let A’ denote the tree of A that contains vertex u. Consider the cut ( A’, V-A’). Every edge crossing the cut is not in A, so this cut respects A and (u,v) is the light edge crossing it. Thus, (u,v) is safe..

How to efficiently detect if adding (u,v) creates a cycle in A Can be done by a data structure called Disjoint Set Union- Find Supports three operations: –CreateSet(u): create a set containing a single item u –FindSet(u): return the set that contains item u –Union(u,v): merge the set containing u with the set containing v Suffices to know: takes O(n log n + m) time to carry out any sequence of m union-find operations on a set of size n.

Kruskal(G=(V,E), w) { A = empty set for each (u in V) CreateSet(u) //create a set for each vertex Sort E in increasing order by weight for each ((u,v) from the sorted list E) { if (FindSet(u) != FindSet(v)) { // u and v are in different trees Add(u,v) to A Union(u,v) } return A } Θ(E log E) for sorting the edges O(V log V + E) for a sequence of E union find operations Total : O(E log E) since (E >= V-1)

Prim’s Algorithm Edges in A always form a tree (partial MST) Start from a vertex r and grow until the tree spans all vertices Let S denote the set of vertices which are on this partial MST –A is the set of edges connecting the vertices in S At each stage the light edge crossing (S, V-S) is added to A S V-S r

Prim’s Algorithm Prim(G=(V,E),w,r) { for each (u in V) { key[u] = infinity pred[u] = NIL } key[r] = 0; PQ = {V} //add all vertices to Priority Queue PQ based on keys while (PQ is not empty) do { u = PQ.Extract-Min() for each (v in Adj[u]) if (v is in PQ and w(u,v) < key[v]) then { pred[v] = u key[v]=w(u,v) PQ.DecreaseKey(v, key[v]) //reorganizes the PQ }