Chapter 23: Minimum Spanning Trees: A graph optimization problem

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.
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.
CSE 780 Algorithms Advanced Algorithms Minimum spanning tree Generic algorithm Kruskal’s algorithm Prim’s algorithm.
Lecture 18: Minimum Spanning Trees Shang-Hua Teng.
1 Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm.
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.
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.
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.
Minimum Spanning Trees and Kruskal’s Algorithm CLRS 23.
 2004 SDU Lecture 7- Minimum Spanning Tree-- Extension 1.Properties of Minimum Spanning Tree 2.Secondary Minimum Spanning Tree 3.Bottleneck.
1 Minimum Spanning Trees. Minimum- Spanning Trees 1. Concrete example: computer connection 2. Definition of a Minimum- Spanning Tree.
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)
© 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
Tirgul 12 Solving T4 Q. 3,4 Rehearsal about MST and Union-Find
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
Introduction to Algorithms`
CS 3343: Analysis of Algorithms
Minimum Spanning Tree Shortest Paths
CSC 413/513: Intro to Algorithms
Minimum Spanning Trees
Lecture 12 Algorithm Analysis
CISC 235: Topic 10 Graph Algorithms.
Minimum Spanning Trees
Minimum Spanning Trees
Algorithms and Data Structures Lecture XII
Data Structures – LECTURE 13 Minumum spanning trees
Greedy Algorithm (17.4/16.4) Greedy Algorithm (GA)
Chapter 23 Minimum Spanning Tree
CS 583 Analysis of Algorithms
Minimum Spanning Trees
Kruskal’s Minimum Spanning Tree Algorithm
Analysis of Algorithms CS 477/677
Lecture 12 Algorithm Analysis
Minimum Spanning Trees
Minimum Spanning Tree.
Minimum Spanning Trees
Algorithms Searching in a Graph.
Greedy Algorithms Comp 122, Spring 2004.
Lecture 12 Algorithm Analysis
Total running time is O(E lg E).
Advanced Algorithms Analysis and Design
Binhai Zhu Computer Science Department, Montana State University
Minimum Spanning Trees
Presentation transcript:

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)  E, find an acyclic subset T  E that connects all the vertices and for which the total weight is a minimum w(T) =

Any acyclic subset T  E that connects all the vertices is a spanning tree. Any T with minimum total weight is a minimum-weight spanning tree. Most often called “minimum spanning tree

Chapter 23 covers 2 approaches for solving the minimum spanning tree problem; Kruskal’s algorithm and Prim’s algorithm. Both are examples of greedy algorithms (no global search strategy) Generic greedy MST(G,w) A = null set while A is not a minimum spanning tree add the lightest edge unless it generates a cycle (trees are acyclic graphs)

Growing a minimum spanning tree (MST): G(V,E) is an undirected graph. A is subset of V that defines part of a MST. edge (u,v) is a safe edge if A  (u,v) is also part of a MST. Kruskal and Prim algorithms differ in how they search for safe edges. Safe edges are defined by “cuts”.

Theorem 23.1(next slide) provides a rule for finding safe edges A cut (S,V-S) is a partition of vertices in G(V,E) Edge (u,v) crosses cut (S,V-S) if one end is in S and the other is V-S A cut respects set A if no edge in A crosses the cut An edge that crosses a cut is a light edge if it has the minimum weight of edges crossing the cut Edges in A are shaded. White and black V’s are in different parts of partition. (c,d) is a light edge and a safe edge for growing MST.

Let (S,V-S) be a cut in G that respects A, a growing MST. Theorem 23.1 Let (S,V-S) be a cut in G that respects A, a growing MST. Let (u,v) be a light edge crossing (S,V-S). Then (u,v) is a safe edge for A. Proof: Let T be a MST that contains A (shaded) and (x,y) but not (u,v). Both (u,v) and (x,y) cross (S, V-S) (connect B&W vertices). Define T = {T – (x,y)}{(u,v)} w(u,v) < w(x,y) because (u,v) is a light edge w(T) = w(T) – w(x,y) + w(u,v) < w(T) but T is a MST  w(T) < w(T)   w(T) must also be a MST  (u,v) is a safe edge for A

Corollary 23.2: G(V,E) a is connected, undirected, weighted graph. A is a subset of E that is included in some MST of G. GA (V,A) is a forest of connected components (VC,EC), each of which is a tree. If (u,v) is a light edge connecting C to some other component of A, then (u,v) is a safe edge of A Proof: cut (VC, V-VC) respects A and crosses (u,v)  (u,v) is a safe edge by Theorem 23.1

Corrllary 23.2 is basis for Krustal algorithm Look for a cut that respects the growing MST, A, and crosses the lightest edge not already in A. If such a cut exists, include lightest edge in A; otherwise repeat with next lightest edge. Repeat until all vertices are in the MST Resolve ambiguity by including the edge that connects to the vertex with lowest alphabetical order.

Example from text

Pseudo-code for Krustal’s algorithm: p 569 Uses operations on disjoint-set data structures that are described in Chapter 21, p499.   Make-Set(x) creates a new distinct set whose only member, x, is the representative of that set. Find-Set(x) returns a pointer to the representative of the unique set that contains element x. Union-Set(x,y) unites the sets Sx and Sy that contain elements x and y, respectively. Chooses a representative for Sx  Sy and destroys Sx and Sy

MST-Kruskal(G,w) (initialization) A  0 for each v  V[G] do Make-Set(v) sort edges E[G] in non-decreasing order by weight (process edges in sorted order) for all edges (u,v) do if Find-Set(u)  Find-Set(v) (vertices u and v are on opposite sides of a cut) (u,v,) is a light edge then A  A  {(u,v)} Union-Set(u,v) return A Running time: Sorting edges by weight takes O(E lgE) (most time consuming step) Disjoint-set operations (21.3 p505-509) O((E+V)lgV) Total O(ElgE + (E+V)lgV) -> O(ElgE) if E >> V

Prim’s MST algorithm Rationale of Prim’s algorithm: Starts from an arbitrary root.   At each step, consider all edges that connect the growing MST, A, to a vertex not already in the tree. Add the lightest of these if it is a safe edge (i.e. does not create a cycle). In hand calculation, resolve any ambiguity by alphabetical order of vertices that could be added to A (i.e, add to A the edge that connects A to the vertex with lowest alphabetical order). As MST is built, record p[v] if ask to draw the final MST.

MST-Prim(G,w,r) for each u  V[G] do key[u]  , p[u]  NIL key[r]  0 Q  V[G] (initialization completed) while Q  0 do u  Extract-Min(Q) (get the external vertex with the lightest connecting edge) for each v  Adj[u] do if v  Q and w(u,v) < key[v] (update the fields of all vertices that are adjacent to u but not in the tree) then p[v]  u, key[v]  w(u,v) Performance of Prim: (assuming Q is a binary min-heap) Build-Min-Heap requires O(V) time while Q  0 loop executes |V| times  Extract-Min operations take total O(V lgV) time body of the for loop over adjacency lists executes |E| times Q membership test can be implemented in constant time Decrease-Key to update key[v] requires O(lgV) time   Total time O((V + E)lgV ) same as disjoint-set operations in Krustal but Krustal require ElgE in addition to sort edges by weight.

Implementation of Prim’s algorithm: Start from an arbitrary root. At each step, add a light edge that connects growing MST to a vertex not already in the tree. (a safe edges by Corollary 23.2) To facilitate selection of new edges, maintain a minimum priority queue of vertices not in the growing MST. key[v], which defines the priority of v, is the minimum weight among all the edges that connect v to any vertex in the current MST. key[v] =  if no such edge exist. Algorithm terminates when queue is empty. {(v, p[v]): v  V – {r} –Q} implicitly defines the growing MST = A

Executing Prim’s MST algorithm by hand In hand calculation, resolve any ambiguity by alphabetical order of vertices in A (i.e, if vertices have equal priority, add to A the edge that connects A to the vertex with lowest alphabetical order). As MST is built, record p[v] if ask to draw the final MST.

Example from text

Krustal Prim

Completes solution by Prim’s algorithm

c d e b f g a h Assignment 22: Due 4/12/19 Use the rationale of Prim’s algorithm to find a minimum-weight spanning tree in the connected graph below. Use vertex h as the root. Record the predecessor of vertices as they are added to the MST. Resolve any ambiguity about vertex discovery by the alphabetical order of vertex labels. Use the predecessor of vertices to draw the MST. c d e b f g a h 5 8 18 7 14 3 1 11 6 2 4 10 9

To be discussed in class Ex 23.1-1, 23.1-3, and 23.1-4: text p629 Ex 23.1-6 and 23.1-10: text p630

Ex 23. 1-1: (u,v) is minimum-weight edge in a connected graph G Ex 23.1-1: (u,v) is minimum-weight edge in a connected graph G. Show that (u,v) is in some MST of G Proof: Let A be null set edges. Let (s, v-s) be any cut that crosses (u,v) By Theorem 23.1 (u,v) is a safe edge of A Theorem 23.1 Let (S,V-S) be a cut in G that respects A. Let (u,v) be a light edge crossing (S,V-S). Then (u,v) is a safe edge for A

Ex 23. 1-3: (u,v) is contained in some MST of G Ex 23.1-3: (u,v) is contained in some MST of G. Show that (u,v) is a light edge crossing some cut of G Proof: Removal (u,v) from MST breaks it into 2 parts. This allows for a cut that respects the 2 parts and crosses (u,v). (u,v) is a light edge because any other edge crossed by cut was not part of the MST.

Not an MST because cyclic Ex 23.1-4: Every edge (u,v) of a connected graph has the property that there exist a cut (s, v-s) such that (u,v) is a light edge of (s, v-s). Give a simple example of such a graph that is not an MST B A C w(A,B) = w(B,C) = w(C,A) Not an MST because cyclic

Ex 23. 1-6: For every cut of G there exist a unique light edge Ex 23.1-6: For every cut of G there exist a unique light edge. Show that the MST of G is unique. Proof: Given MSTs T and T’ of G, show that T = T’ Remove (u,v) from T then there exist a cut (s,v-s) such that (u,v) is a light edge (ex 12.1-3) Suppose (x,y) of T’ also crosses (s,v-s), then it is also a light edge. Otherwise it would not be part of T’ (ex 12.1-3) But for every cut of G the light edge is unique. Therefore (u,v) = (x,y) and T = T’

Ex 23. 1-6: For every cut of G there exist a unique light edge Ex 23.1-6: For every cut of G there exist a unique light edge. Show that the MST of G is unique. Show by an example that the converse, “If MST is unique then for every cut there exist a unique light edge” is not true

Ex 23. 1-10: T is an MST of G that includes (x,y) Ex 23.1-10: T is an MST of G that includes (x,y). w(x,y) is reduced by k. Show that T remains an MST of G. Proof: Let w(t) be the sum of weights of any spanning tree t Let w’(t) be the sum of weights after w(x,y) is reduced by k Let T’ by any spanning tree that is different from MST T. Then w(T’) > w(T) If (x,y) is not part of T’ then w’(T’) = w(T’) > w(T) > w’(T) If (x,y) is part of T’ then w’(T’) = w(T’) – k > w(T) – k = w’(T) In either case, w’(T’) > w’(T); hence T remains an MST