Lecture 12 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.

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)
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.
Introduction to Algorithms 6.046J/18.401J L ECTURE 16 Greedy Algorithms (and Graphs) Graph representation Minimum spanning trees Optimal substructure Greedy.
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.
1 Greedy 2 Jose Rolim University of Geneva. Algorithmique Greedy 2Jose Rolim2 Examples Greedy  Minimum Spanning Trees  Shortest Paths Dijkstra.
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
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.
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.
Minimum Spanning Trees CIS 606 Spring Problem A town has a set of houses and a set of roads. A road connects 2 and only 2 houses. A road connecting.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 11 Instructor: Paul Beame.
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.
Introduction to Algorithms L ECTURE 14 (Chap. 22 & 23) Greedy Algorithms I 22.1 Graph representation 23.1 Minimum spanning trees 23.1 Optimal substructure.
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.
Lecture 13 Algorithm Analysis
 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.
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),
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
Lecture 12 Algorithm Analysis
Minimum Spanning Trees
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 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
Lecture 12 Algorithm Analysis
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
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
Chapter 23: Minimum Spanning Trees: A graph optimization problem
Minimum Spanning Trees
Presentation transcript:

Lecture 12 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea

Minimum Spanning Trees

2015/11Algorithm AnalysisL12.3 Introduction - Problem A town has a set of houses and a set of roads A road connects 2 and only 2 houses A road connecting houses u and v has a repair cost w(u, v) Goal: Repair enough (and no more) roads such that 1.everyone stays connected: can reach every house from all other houses, and 2.total repair cost is minimal

2015/11Algorithm AnalysisL12.4 Model as a graph Undirected graph G = (V, E). Weight w(u, v) on each edge (u, v) ∈ E. Find T ⊆ E such that 1.T connects all vertices (T is a spanning tree), and 2.is minimized. A spanning tree whose weight is minimum over all spanning trees is called a minimum spanning tree, or MST.

2015/11Algorithm AnalysisL12.5 Example Edges of MST are shaded In the above graph there is more than one MST. Replace edge (e, f ) by (c, e) and you get a different spanning tree with the same weight

2015/11Algorithm AnalysisL12.6 Growing a Minimum Spanning Tree Some properties of an MST: –It has |V| − 1 edges –It has no cycles –It might not be unique Building up the solution –We will build a set A of edges –Initially, A has no edges –As we add edges to A, maintain a loop invariant: A is a subset of some MST –Add only edges that maintain the invariant. If A is a subset of some MST, an edge (u, v) is safe for A if and only if A ∪ {(u, v)} is also a subset of some MST. So we will add only safe edges.

2015/11Algorithm AnalysisL12.7 Generic MST algorithm Use the loop invariant to show that this generic algorithm works. –Initialization: The empty set trivially satisfies the loop invariant. –Maintenance: Since we add only safe edges, A remains a subset of some MST. –Termination: All edges added to A are in a MST, so when we stop, A is a spanning tree that is also an MST.

2015/11Algorithm AnalysisL12.8 Some Definitions Let S ⊂ V and A ⊆ E A cut (S, V − S) is a partition of vertices into disjoint sets V and V − S. Edge (u, v) ∈ E crosses cut (S, V − S) if one endpoint is in S and the other is in V − S. A cut respects A if and only if no edge in A crosses the cut. An edge is a light edge crossing a cut if and only if its weight is minimum over all edges crossing the cut. (For a given cut, there can be > 1 light edge crossing it.)

2015/11Algorithm AnalysisL12.9 Central Theorem Theorem: Let A be a subset of some MST, (S, V − S) be a cut that respects A, and (u, v) be a light edge crossing (S, V − S). Then (u, v) is safe for A. Proof: Let T be an MST that includes A. –(a) If T contains (u, v), done. –(b) If T does not contain (u, v), we will construct a different MST T' that includes A ∪ {(u, v)}.

2015/11Algorithm AnalysisL12.10 Central Theorem - Proof (cont.) A tree has unique path between each pair of vertices Since T is an MST, it contains a unique path p between u and v. Path p must cross the cut (S, V − S) at least once Let (x, y) be an edge of p that crosses the cut. From how we chose (u, v), must have w(u, v) ≤ w(x, y)

2015/11Algorithm AnalysisL12.11 Central Theorem - Proof (cont.) Since the cut respects A, edge (x, y) is not in A. To form T' from T : –Remove (x, y) in order to Split T into two components –Add (u, v) in order to reconnect. So T' = T − {(x, y)} ∪ {(u, v)}. T' is a MST. Because T' is a spanning tree and: –w(T') = w(T ) − w(x, y) + w(u, v) ≤ w(T)

2015/11Algorithm AnalysisL12.12 Central Theorem - Proof (cont.) Finally we have to show that (u, v) is safe for A: –A ⊆ T and (x, y)  A ⇒ A ⊆ T' –A ∪ {(u, v)} ⊆ T' –Since T' is an MST, (u, v) is safe for A Corollary If C = (V C, E C ) is a connected component in the forest G A = (V, A) and (u, v) is a light edge connecting C to some other component in G A (i.e., (u, v) is a light edge crossing the cut (V C, V − V C )), then (u, v) is safe for A.

Kruskal’s Algorithm

2015/11Algorithm AnalysisL12.14 Kruskal’s Algorithm - Structure G = (V, E) is a connected, undirected, weighted graph. w : E → R. –Starts with each vertex being its own component. –Repeatedly merges two components into one by choosing the light edge that connects them (i.e., the 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.

2015/11Algorithm AnalysisL12.15 Kruskal’s Algorithm - Pseudocode

2015/11Algorithm AnalysisL12.16 Kruskal’s Algorithm - Analysis Basics: –Initialize A: O(1) –First for loop: |V| MAKE-SETs –Sort E: O(E lg E) –Second for loop: O(E) FIND-SETs and UNIONs Assuming the implementation of disjoint-set data structure, presented in the Textbook in Chapter 21, that uses union by rank and path compression: –O((V + E) α(V)) + O(E lg E) –Since G is connected, |E| ≥ |V| − 1 ⇒ O(E α(V)) + O(E lg E) –α(|V|) = O(lg V) = O(lg E) –Therefore, total time is O(E lg E) –|E| ≤ |V| 2 ⇒ lg |E| = O(2 lg V) = O(lg V) –Therefore we can restate the running time as O(E lg V)

Prim’s Algorithm

2015/11Algorithm AnalysisL12.18 Prim’s Algorithm Builds one tree, so A is always a tree Starts from an arbitrary “root” r At each step, find a light edge crossing cut (V A, V − V A ), where V A = vertices that A is incident on. Add this edge to A.

2015/11Algorithm AnalysisL12.19 Prim’s Algorithm (cont.) How to find the light edge quickly? Use a priority queue Q: –Each object is a vertex in V − V A –Key of v is minimum weight of any edge (u, v), where u ∈ V A. –Then the vertex returned by EXTRACT-MIN is v such that there exists u ∈ V A and (u, v) is light edge crossing (V A, V − V A ) –Key of v is ∞ if v is not adjacent to any vertices in V A.

2015/11Algorithm AnalysisL12.20 Prim’s Algorithm (cont.) The edges of A will form a rooted tree with root r: –r is given as an input to the algorithm, but it can be any vertex –Each vertex knows its parent in the tree by the attribute π[v] = parent of v –π[v] = NIL if v = r or v has no parent –As algorithm progresses, A = {(v, π[v]) : v ∈ V − {r} − Q} –At termination, V A = V ⇒ Q = ∅, so MST is A = {(v, π[v]) : v ∈ V − {r}}

2015/11Algorithm AnalysisL12.21 Prim’s Algorithm - Pseudocode

2015/11Algorithm AnalysisL12.22 Complexity - Analysis Depends on how the priority queue is implemented: Suppose Q is a binary heap. –Initialize Q and first for loop:O(V lg V) –Decrease key of r : O(lg V) –while loop: |V| EXTRACT-MIN calls ⇒ O(V lg V) ≤ |E| DECREASE-KEY calls ⇒ O(E lg V) –Total: O(E lg V)