CSE 780 Algorithms Advanced Algorithms Minimum spanning tree Generic algorithm Kruskal’s algorithm Prim’s algorithm.

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 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.
More Graph Algorithms Minimum Spanning Trees, Shortest Path Algorithms.
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.
Minimum Spanning Trees Definition Algorithms –Prim –Kruskal Proofs of correctness.
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.
Dynamic Sets and Data Structures Over the course of an algorithm’s execution, an algorithm may maintain a dynamic set of objects The algorithm will perform.
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.
CSE 780 Algorithms Advanced Algorithms SSSP Dijkstra’s algorithm SSSP in DAGs.
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.
Midwestern State University Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm 1.
Design and Analysis of Computer Algorithm September 10, Design and Analysis of Computer Algorithm Lecture 5-2 Pradondet Nilagupta Department of Computer.
Definition: Given an undirected graph G = (V, E), a spanning tree of G is any subgraph of G that is a tree Minimum Spanning Trees (Ch. 23) abc d f e gh.
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.
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.
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.
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
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.
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
Kruskal’s Minimum Spanning Tree Algorithm
Analysis of Algorithms CS 477/677
Lecture 12 Algorithm Analysis
Minimum Spanning Trees
Minimum Spanning Trees
Greedy Algorithms Comp 122, Spring 2004.
Lecture 12 Algorithm Analysis
Advanced Algorithms Analysis and Design
Chapter 23: Minimum Spanning Trees: A graph optimization problem
Minimum Spanning Trees
Presentation transcript:

CSE 780 Algorithms Advanced Algorithms Minimum spanning tree Generic algorithm Kruskal’s algorithm Prim’s algorithm

CSE 780 Algorithms Minimum Spanning Tree Learning outcomes: You should be able to: Write Kruskal’s and Prim’s algorithms Run both algorithms on given graphs Analyze both algorithms

CSE 780 Algorithms 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 roads such that 1. every house is connected 2. total repair cost is minimum

CSE 780 Algorithms Definition Given a connected graph G = (V, E), with weight function w : E --> R Find min-weight connected subgraph Spanning tree T: A tree that includes all nodes from V T = (V, E’), where E’  E Weight of T: W( T ) =  w(e) Minimum spanning tree (MST): A tree with minimum weight among all spanning trees

CSE 780 Algorithms Example

CSE 780 Algorithms MST MST for given G may not be unique Since MST is a spanning tree: # edges : |V| - 1 If the graph is unweighted: All spanning trees have same weight

CSE 780 Algorithms Generic Algorithm Framework for G = (V, E) : Goal: build a set of edges A  E Start with A empty Add edge into A one by one At any moment, A is a subset of some MST for G An edge is safe if adding it to A still maintains that A is a subset of a MST

CSE 780 Algorithms Finding Safe Edges When A is empty, example of safe edges? The edge with smallest weight Intuition: Suppose S  V, --- a cut (S, V-S) – a partition of vertices into sets S and V-S S and V-S should be connected By the crossing edge with the smallest weight ! That edge also called a light edge crossing the cut (S, V-S) A cut (S, V-S) respects set A of edges If no edges from A crosses the cut (S, V-S)

CSE 780 Algorithms Cut

CSE 780 Algorithms Safe-Edge 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 Corollary: Let C = (V c,E c ) be a connected component in the graph (forest) G A = (V, A). If (u, v) is a light edge connecting C to some other component in G A, then (u, v) is safe for A. Greedy Approach: Based on the generic algorithm and the corollary, to compute MST we only need a way to find a safe edge at each moment.

CSE 780 Algorithms Kruskal’s Algorithm Start with A empty, and each vertex being its own connected component Repeatedly merge two components by connecting them with a light edge crossing them Two issues: Maintain sets of components Choose light edges Disjoint set data structure Scan edges from low to high weight

CSE 780 Algorithms Pseudo-code

CSE 780 Algorithms Disjoint Set Operations Disjoint set data structure maintains a collection S = {S 1,S 2, …,S k } of disjoint dynamic sets where each set is identified by a representative (member) of the set. MAKE-SET(x): create a new set whose only member (and representative) is pointed at by x. UNION(x,y): unites dynamic sets containing x and y, S x and S y, eliminating S x and S y from S. FIND-SET(x): returns a pointer to the representative of the set containing x.

CSE 780 Algorithms Example

CSE 780 Algorithms Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

CSE 780 Algorithms Analysis Time complexity: #make-set : |V| #find-set and #union operations: |E| operations O( (|V| + |E|)  (|V| )) = O( |E|  (|V| )) as |E| >= |V| - 1  is the very slowly growing function  (|V| ) = O(lg|V|) = O(lg|E|) Sorting : O(|E| lg |E|) Total: O(|E| lg |E|) = O(|E| lg |V|) Since |E| < |V| 2, hence lg|E| = lg|V|.

CSE 780 Algorithms Prim’s Algorithm Start with an arbitrary node from V Instead of maintaining a forest, grow a MST At any time, maintain a MST for V’  V At any moment, find a light edge connecting V’ with (V-V’) I.e., the edge with smallest weight connecting some vertex in V’ with some vertex in V-V’ !

CSE 780 Algorithms Prim’s Algorithm cont. Again two issues: Maintain the tree already build at any moment Easy: simply a tree rooted at r : the starting node Find the next light edge efficiently For v  V - V’, define key(v) = the min distance between v and some node from V’ (current MST) At any moment, find the node with min key. Use a priority queue !

CSE 780 Algorithms Pseudo-code (cancel)

CSE 780 Algorithms Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

CSE 780 Algorithms Example

CSE 780 Algorithms Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

CSE 780 Algorithms Min Heap

CSE 780 Algorithms MAX HEAP

CSE 780 Algorithms Analysis Time complexity Using binary min-heap for priority queue: # initialisation in lines 1-5: O(|V|) While loop is executed |V| times Each Extract-min takes O ( log |V| ) Total Extract-min takes O ( |V| log |V| ) Assignment in line 11 involves Decrease-Key operation: Each Decrease-Key operation takes O ( log |V| ) The total is O( |E| log |V| ) ) Total time complexity: O (|V| log |V| +|E| log |V|) = O (|E| log |V|) Using Fibonacci heap: Decrease-Key: O(1) amortized time => total time complexity O(|E| + |V| log |V|)

CSE 780 Algorithms Applications Clustering Euclidean traveling salesman problem