CS 583 Analysis of Algorithms

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

Greedy Algorithms 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.
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.
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.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
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.
TECH Computer Science Graph Optimization Problems and Greedy Algorithms Greedy Algorithms  // Make the best choice now! Optimization Problems  Minimizing.
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.
COSC 3101NJ. Elder Assignment 2 Remarking Assignment 2 Marks y = 0.995x R 2 = Old Mark New Mark.
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.
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.
© 2007 Seth James Nielson Minimum Spanning Trees … or how to bring the world together on a budget.
Lecture 12 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
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
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
Spanning Trees Kruskel’s Algorithm Prim’s Algorithm
Minimum Spanning Trees
CS Introduction to Data Structures
Lecture 12 Algorithm Analysis
Greedy Algorithms / Minimum Spanning Tree Yin Tat Lee
Connected Components Minimum Spanning Tree
Algorithms and Data Structures Lecture XII
Algorithms (2IL15) – Lecture 5 SINGLE-SOURCE SHORTEST PATHS
Data Structures – LECTURE 13 Minumum spanning trees
Basic Graph Algorithms
Chapter 23 Minimum Spanning Tree
Minimum Spanning Trees
Analysis of Algorithms CS 477/677
Minimum Spanning Tree Section 7.3: Examples {1,2,3,4}
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
Lecture 12 Algorithm Analysis
Minimum Spanning Tree Algorithms
Lecture 13 Algorithm Analysis
Minimum Spanning Trees
Lecture 13 Algorithm Analysis
Minimum Spanning Trees
Lecture 14 Shortest Path (cont’d) Minimum Spanning Tree
Greedy Algorithms Comp 122, Spring 2004.
Text Book: Introduction to algorithms By C L R S
Lecture 12 Algorithm Analysis
Advanced Algorithms Analysis and Design
Lecture 13 Shortest Path (cont’d) Minimum Spanning Tree
Chapter 23: Minimum Spanning Trees: A graph optimization problem
Premaster Course Algorithms 1 Chapter 5: Basic Graph Algorithms
Minimum Spanning Trees
Presentation transcript:

CS 583 Analysis of Algorithms Minimum Spanning Tree CS 583 Analysis of Algorithms 12/27/2018 CS583 Fall'06: Minimum Spanning Tree

CS583 Fall'06: Minimum Spanning Tree Outline Breadth-First Tree Predecessor subgraph Printing paths Minimum Spanning Trees Definitions Generic algorithm Correctness Self-test 23.1-1, 23.1-4 12/27/2018 CS583 Fall'06: Minimum Spanning Tree

CS583 Fall'06: Minimum Spanning Tree Breadth-First Trees BFS builds a breadth-first tree as it searches the graph. It is represented by the  field in each vertex. Define the predecessor subgraph of G=(V, E) as G = (V, E): V = {v  V : [v]  NIL}  {s} E = {([v],v) : v  V - {s}} The predecessor graph is a breadth-first tree if: V consists of the vertices reachable from s, and For all v  V there is a unique path from s to v in G that is also a shortest path in G. The breadth-first tree is a tree since (see Theorem B.2): It is connected (there’s a path between any two vertices), and | E | = | V | - 1 12/27/2018 CS583 Fall'06: Minimum Spanning Tree

Breadth-First Trees in BFS Lemma 22.6 When applied to a directed or undirected graph G=(V,E), BFS constructs  so that the predecessor subgraph G = (V, E) is a breadth-first tree. Proof. Line 16 of BFS sets [v] = u if and only if (u,v)  E and (s,v) < . Hence V consists of the vertices in V reachable from s. Since G forms a tree, it contains a unique path from s to v. Using Theorem 22.5 we can show by induction that every such path is a shortest path.  12/27/2018 CS583 Fall'06: Minimum Spanning Tree

Printing Shortest Paths The following procedure prints out the vertices on a shortest path from s to v, assuming that BFS has already run. Print-Path(G,s,v) 1 if v = s 2 print s 3 else 4 if [v] = NIL 5 print “No path from s to v exists!” 6 else 7 Print-Path(G,s,[v]) 8 print v The procedure runs in O(|V|) time since each recursive call is for a path one vertex shorter. 12/27/2018 CS583 Fall'06: Minimum Spanning Tree

The Networking Problem Design a network that connects n sites at a minimum total cost. A weighted graph represents the cost (an edge’s weight) of connecting any two sites. An optimal network will be a subgraph of such a graph containing the minimum number of edges (n-1) at a total minimum sum of the weights of these edges. Such a subgraph forms a spanning tree. 12/27/2018 CS583 Fall'06: Minimum Spanning Tree

The Minimum Spanning Tree Problem Assume we have a connected, undirected graph G = (V,E) with the weight function w : E  R. For each edge (u,v)  E, we have weight w(u,v). We wish to find an acyclic subset T  E that connects all of the vertices, and whose total weight is minimized. w(T) = (u,v)  T w(u,v) 12/27/2018 CS583 Fall'06: Minimum Spanning Tree

CS583 Fall'06: Minimum Spanning Tree Generic MST A “generic” algorithm uses a greedy approach in that it grows the minimum spanning tree one edge at a time. The algorithm manages a set of edges A and maintains the following loop invariant: Prior to each iteration, A is a subset of some minimum spanning tree. At each step we determine an edge that can be added to A without violating the invariant. Such edge is called a safe edge. 12/27/2018 CS583 Fall'06: Minimum Spanning Tree

Generic MST: Pseudocode The following procedure sketches an algorithm to find a subset of edges of a weighted graph that forms a minimum spanning tree. Generic-MST(G,w) 1 A =  2 while <A does not form a spanning tree> 3 <find an edge (u,v) that is safe for A> 4 A = A  {(u,v)} 5 return A 12/27/2018 CS583 Fall'06: Minimum Spanning Tree

Generic MST: Loop Invariant Initialization: After line 1, the set A is empty, which is a subset of any spanning tree, Maintenance: The while loop 2-4 maintains the invariant by adding only safe edges. Termination: All edges added to A are in a minimum spanning tree. Once the spanning tree is formed it is the minimum spanning tree. 12/27/2018 CS583 Fall'06: Minimum Spanning Tree

CS583 Fall'06: Minimum Spanning Tree Finding Safe Edges The key is to find safe edges (line 3) Such edge always exists according to the loop invariant. A cut (S, V-S) of an undirected graph G = (V,E) is a partition of V. An edge (u,v) crosses the cut, if one of its endpoints is in S, and the other is in V-S. A cut respects a set A of edges if no edge in A crosses the cut. An edge is a light edge crossing a cut if its weight is the minimum of any edge crossing the cut. 12/27/2018 CS583 Fall'06: Minimum Spanning Tree

Recognizing Safe Edges Theorem 23.1 Let G = (V,E) be a connected, undirected graph with a real valued function w defined on E. Let A be a subset of E that is included in some minimum spanning tree for G. Let (S, V – S) be any cut of G that respects A. Let (u,v) be a light edge crossing (S, V – S). Then edge (u, v) is safe for A. Proof Let T be a minimum spanning tree that includes A. If it contains (u,v), then it can be safely added to A. If it does not, we construct another minimum spanning tree T1 that includes A  (u,v). 12/27/2018 CS583 Fall'06: Minimum Spanning Tree

Recognizing Safe Edges (cont.) The edge (u,v) forms a cycle with edges on the path from u to v in T. Since u and v are on the opposite sides of the cut (S, V – S), there’s at least one edge in T on this path that also crosses the cut. Let this edge be (x,y). Since (x,y) is on unique path from u to v in T, removing (x,y) breaks T. Adding (u,v) reconnects it to form a new spanning tree: T1 = T – {(x,y)}  {(u,v)} 12/27/2018 CS583 Fall'06: Minimum Spanning Tree

Recognizing Safe Edges (cont.) Show that T1 is a minimum spanning tree: Since (u,v) is a light edge and (x,y) also crosses the cut, we have: w(u,v)  w(x,y) w(T1) = w(T) – w(x,y) + w(u,v)  w(T) Since T is a minimum spanning tree, T1 is also a minimum spanning tree. Show that (u,v) is a safe edge for A: A  T (x,y)  A A  {(u,v)}  T1 Since T1 is a minimum spanning tree, (u,v) is safe for A. 12/27/2018 CS583 Fall'06: Minimum Spanning Tree

Generic-MST: Framework As the algorithm proceeds, the set A is always acyclic. MST cannot contain a cycle. At any step of the algorithm the graph GA = (V,A) is a forest. Each of the connected components is a tree. Any safe edge for A connects distinct components of GA. A  {(u,v)} must be acyclic. The loop 2-4 is executed |V| - 1 times to add each edge of an MST. 12/27/2018 CS583 Fall'06: Minimum Spanning Tree

Generic-MST: Framework (cont.) Corollary 23.2 Let G = (V,E) be a connected, undirected graph with a real valued function w defined on E. Let A be a subset of E that is included in some minimum spanning tree for G. Let C = (VC ,EC) be a connected component (tree) in the forest GA. Let (u,v) be a light edge connecting C to some other component in GA. Then edge (u, v) is safe for A. Proof The cut (VC , V - VC) respects A, and edge (u,v) is a light edge for this cut. Therefore, (u,v) is safe for A.  12/27/2018 CS583 Fall'06: Minimum Spanning Tree