Introduction to Algorithms

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.
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 (MST) form a tree that connects all the vertices (spanning tree). minimize the total edge weight of the spanning tree. Problem Select.
1 Greedy 2 Jose Rolim University of Geneva. Algorithmique Greedy 2Jose Rolim2 Examples Greedy  Minimum Spanning Trees  Shortest Paths Dijkstra.
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.
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.
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.
Design and Analysis of Algorithms Minimum Spanning trees
1.1 Data Structure and Algorithm Lecture 13 Minimum Spanning Trees Topics Reference: Introduction to Algorithm by Cormen Chapter 13: Minimum Spanning Trees.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Graph Algorithms: Minimum.
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.
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.
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)
F d a b c e g Prim’s Algorithm – an Example edge candidates choosen.
© 2007 Seth James Nielson Minimum Spanning Trees … or how to bring the world together on a budget.
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.
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.
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
Minimum Spanning Trees
Algorithm Analysis Fall 2017 CS 4306/03
Minimum Spanning Trees
Minimum Spanning Trees
Introduction to Algorithms`
Minimum Spanning Trees
Lecture 12 Algorithm Analysis
Minimum Spanning Trees
Minimum Spanning Tree.
Minimum Spanning Tree.
Minimum Spanning Trees
Algorithms and Data Structures Lecture XII
Data Structures – LECTURE 13 Minumum spanning trees
Chapter 23 Minimum Spanning Tree
CS 583 Analysis of Algorithms
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
Greedy Algorithms Comp 122, Spring 2004.
Introduction to Algorithms: Greedy Algorithms (and Graphs)
Lecture 12 Algorithm Analysis
Advanced Algorithms Analysis and Design
Algorithm Course Dr. Aref Rashad
Lecture 14 Minimum Spanning Tree (cont’d)
Chapter 23: Minimum Spanning Trees: A graph optimization problem
Minimum Spanning Trees
Presentation transcript:

Introduction to Algorithms Minimum Spanning Trees My T. Thai @ UF

Problem Find a low cost network connecting a set of locations Any pair of locations are connected There is no cycle Some applications: Communication networks Circuit design … My T. Thai mythai@cise.ufl.edu

Minimum Spanning Tree (MST) Problem Input: Undirected, connected graph G=(V, E), each edge (u, v)  E has weight w(u, v) Output: acyclic subset T  E that connects all of the vertices with minimum total weight w(T) = (u,v)T w(u,v) Bold edges form a Minimum Spanning Tree My T. Thai mythai@cise.ufl.edu

Growing a minimum spanning tree Suppose A is a subset of some MST Iteratively add safe edge (u,v) s.t. A  {(u,v)} is still a subset of some MST Generic algorithm: Key problem: How to find safe edges? Note: MST has |V|-1 edges My T. Thai mythai@cise.ufl.edu

Some definitions A cut (S, V - S) is a partition of vertices into disjoint sets S and V - S An edge crosses the cut (S, V - S) if it has one end point in S, one end point in V - S A cut respects a set A of edges if and only if no edge in A crosses the cut, e.g. A is the set of bold edges My T. Thai mythai@cise.ufl.edu

Some definitions An edge is a light edge crossing a cut if and only if its weight is minimum over all edges crossing the cut, e.g. edge (c, d) Observation: Any MST has at least one edge connect S and V – S => one cross edge is safe for A My T. Thai mythai@cise.ufl.edu

Find a safe edge Proof: Let T be a MST that includes A Case 1: (u, v)  T => done. Case 2: (u, v) not in T: Exist edge (x, y) T cross the cut, (x, y) A Removing (x, y) breaks T into two components. Adding (u, v) reconnects 2 components T´ = T - {(x, y)}  {(u, v)} is a spanning tree w(T´) = w(T) - w(x, y) + w(u, v)  w(T) => T’ is a MST => done My T. Thai mythai@cise.ufl.edu

Corollary In GENERIC-MST A is a forest containing connected components. Initially, each component is a single vertex. Any safe edge merges two of these components into one. Each component is a tree. My T. Thai mythai@cise.ufl.edu

Kruskal’s Algorithm Starts with each vertex in its own component Repeatedly merges two components into one by choosing a light edge that connects them (i.e., a light edge crossing the cut between them) Scans the set of edges in monotonically increasing order by weight. Uses a disjoint-set data structure to determine whether an edge connects vertices in different components My T. Thai mythai@cise.ufl.edu

Disjoint-set data structure Maintain collection S = {S1, . . . , Sk} of disjoint dynamic (changing over time) sets Each set is identified by a representative, which is some member of the set Operations: MAKE-SET(x): make a new set Si = {x}, and add Si to S UNION(x, y): if x ∈ Sx , y ∈ Sy, then S ← S − Sx − Sy ∪ {Sx ∪ Sy} Representative of new set is any member of Sx ∪ Sy, often the representative of one of Sx and Sy. Destroys Sx and Sy (since sets must be disjoint). FIND-SET(x): return representative of set containing x In Kruskal’s Algorithm, each set is a connected component My T. Thai mythai@cise.ufl.edu

Pseudo code Running time: O(E lg V) ( is E is sorted) First for loop: |V| MAKE-SETs Sort E: O(E lg E) - O(E lg V) Second for loop: (o(E log V) (chapter 21) My T. Thai mythai@cise.ufl.edu

Example My T. Thai mythai@cise.ufl.edu

My T. Thai mythai@cise.ufl.edu

Prim’s Algorithm Builds one tree, so A always a tree Starts from an arbitrary “root” r At each step, find a light edge crossing cut (VA, V − VA), where VA = vertices that A is incident on. Add this edge to A. My T. Thai mythai@cise.ufl.edu

Prim’s Algorithm Uses a priority queue Q to find a light edge quickly Each object in Q is a vertex in V - VA Key of v is minimum weight of any edge (u, v), where u  VA Then the vertex returned by Extract-Min is v such that there exists u  VA and (u, v) is light edge crossing (VA, V – VA) Key of v is  if v is not adjacent to any vertex in VA My T. Thai mythai@cise.ufl.edu

Running time: O(E lgV) Using binary heaps to implement Q Initialization: O(V) Building initial queue : O(V) V Extract-Min’s : O(V lgV) E Decrease-Key’s : O(E lgV) Note: Using Fibonacci heaps can save time of Decrease-Key operations to constant (chapter 19) => running time: O(E + V lg V) My T. Thai mythai@cise.ufl.edu

Example My T. Thai mythai@cise.ufl.edu

My T. Thai mythai@cise.ufl.edu

Summary MST T of connected undirect graph G = (V, E): Is a subgraph of G Connected Has V vertices, |V| -1 edges There is exactly 1 path between a pair of vertices Deleting any edge of T disconnects T Kruskal’s algorithm connects disjoint sets of connects vertices until achieve a MST Run nearly linear time if E is sorted: My T. Thai mythai@cise.ufl.edu

Summary Prim’s algorithm starts from one vertex and iteratively add vertex one by one until achieve a MST Faster than Kruskal’s algorithm if the graph is dense O(E + V lg V) vs O(E lg V) My T. Thai mythai@cise.ufl.edu