Minimum Spanning Trees Definition Algorithms –Prim –Kruskal Proofs of correctness.

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

Single Source Shortest Paths
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.
1 Greedy 2 Jose Rolim University of Geneva. Algorithmique Greedy 2Jose Rolim2 Examples Greedy  Minimum Spanning Trees  Shortest Paths Dijkstra.
Discussion #36 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 Tree Algorithms
CSE 780 Algorithms Advanced Algorithms Minimum spanning tree Generic algorithm Kruskal’s algorithm Prim’s algorithm.
Shortest Paths Definitions Single Source Algorithms –Bellman Ford –DAG shortest path algorithm –Dijkstra All Pairs Algorithms –Using Single Source Algorithms.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Analysis of Algorithms CS 477/677
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.
Shortest Paths Definitions Single Source Algorithms
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
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. 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.
Data Structures and Algorithms Graphs Minimum Spanning Tree PLSD210.
Shortest Path Algorithms. Kruskal’s Algorithm We construct a set of edges A satisfying the following invariant:  A is a subset of some MST We start with.
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.
9/10/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Adam Smith Algorithm Design and Analysis L ECTURE 8 Greedy Graph.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
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
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.
Lecture 19 Greedy Algorithms Minimum Spanning Tree Problem.
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.
Minimum- Spanning Trees
1 Week 3: Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm.
CSCE 411 Design and Analysis of Algorithms Set 9: More Graph Algorithms Prof. Jennifer Welch Spring 2012 CSCE 411, Spring 2012: Set 9 1.
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
Data Structures & Algorithms Graphs Richard Newman based on book by R. Sedgewick and slides by S. Sahni.
Lecture ? The Algorithms of Kruskal and Prim
Introduction to Algorithms
Minimum Spanning Tree Chapter 13.6.
Minimum Spanning Trees
Spanning Trees Kruskel’s Algorithm Prim’s Algorithm
Minimum Spanning Trees
Lecture 12 Algorithm Analysis
Greedy Algorithms / Minimum Spanning Tree Yin Tat Lee
Short paths and spanning trees
Data Structures & Algorithms Graphs
Minimum Spanning Tree.
Minimum Spanning Tree.
Autumn 2015 Lecture 11 Minimum Spanning Trees (Part II)
CSE373: Data Structures & Algorithms Lecture 12: Minimum Spanning Trees Catie Baker Spring 2015.
Algorithms and Data Structures Lecture XII
Data Structures – LECTURE 13 Minumum spanning trees
Lecture 12 Algorithm Analysis
Minimum Spanning Tree Algorithms
Minimum Spanning Tree.
CSE 417: Algorithms and Computational Complexity
Lecture 12 Algorithm Analysis
Winter 2019 Lecture 11 Minimum Spanning Trees (Part II)
Autumn 2019 Lecture 11 Minimum Spanning Trees (Part II)
Presentation transcript:

Minimum Spanning Trees Definition Algorithms –Prim –Kruskal Proofs of correctness

Problem Definition Input –Weighted, connected undirected graph G=(V,E) Weight (length) function w on each edge e in E Task –Compute a spanning tree of G of minimum total weight Spanning tree –If there are n nodes in G, a spanning tree consists of n-1 nodes such that no cycles are formed

Kruskal’s algorithm Greedy approach to edge selection –Select the minimum weight edge that does not form a cycle –Implementation Sort edges by increasing lengths –Alternatively use heap to store edges –Either way: O(E log E) time Include minimum weight edge if it does not form a cycle. How do we test if edge forms a cycle?

Use disjoint-set data structure (Chapter 21) –Each vertex belongs to a set containing the vertices in its current tree (initially only itself) –Find-set(A) = Find-set(B) = Find-set(E) = A –Find-set(C) = Find-set(D) = C –Find-set(F) = F –Find-set(G) = G Disjoint-set Data Structure ABC D EFG

Take minimum weight edge and test both endpoints to see if they are in same set Min weight edge: (A,E). Same Set. Cycle. Min weight edge: (B,C): Different Sets. No cycle. Cycle Detection ABC D EFG

Merge sets corresponding to node B and node C. –We need the result to now be: –Find-set(A) = Find-set(B) = Find-set(E) = Find-set(C) = Find-set(D) = A (or C) –Find-set(F) = F –Find-set(G) = G Update Disjoint-set Data Structure ABC D EFG

Time for Disjoint-set Data Structure Operations Initialization: –Makeset(v) for all vertices v: O(V) time Merges and Find-set Operations –O(E) of them –Each can be implemented in amortized  (V) time where  is a very slow growing function –O(E  (V)) time overall which is essentially O(E) for all practical purposes

Overall Running Time Initialization: –Makeset(v) for all vertices v: O(V) time Merges and Find-set Operations –O(E) of them –Each can be implemented in amortized  (V) time where  is a very slow growing function –O(E  (V)) time overall for cycle detection O(E log E) time for sorting edges by weight dominates

Prim’s algorithm Different greedy approach to edge selection –Initialize connected component N to be any node v –Select the minimum weight edge connecting N to V-N –Implementation Maintain a priority queue for the nodes in V-N based on how close they are to any node in N When a new node v is added to N, we need to update the weight of the neighbors of v in V-N

Maintain priority queue of nodes in V-N If we started with node D, N is now {C,D} Priority Queue values of other nodes: –A, E, F: infinity –B: 4 –G: 6 Priority Queue ABC D EFG

Node B is added to N; edge (B,C) is added to T Need to update priority queue values of A, E, F –Decrease-key operation Priority Queue values of other nodes: –A: 1 –E: 2 –F: 5 –G: 6 Updating Priority Queue ABC D EFG

Node A is added to N; edge (A,B) is added to T Need to update priority queue values of E –Decrease-key operation Priority Queue values of other nodes: –E: 2 (unchanged because 2 is smaller than 3) –F: 5 –G: 6 Updating Priority Queue ABC D EFG

Running time Analysis Assume binary heap implementation Build initial heap takes O(v) time V extract-min operations for O(V log V) time For each edge, potentially 1 decrease-key operation, so O(E log V) time Overall: O(E log V) time which is asymptotically equivalent to our implementation of Kruskal’s algorithm Use of fibonacci heap can improve running time to O(E + V log V) time –Decrease-key drops to O(1) amortized time

Proofs of Correctness (Kruskal) Let T’ be a minimum spanning tree for G Let T be the tree formed by Kruskal’s algorithm that utilizes edges in T’ whenever a tie needs to be broken Assumption: T has more weight than T’ –Otherwise Kruskal’s algorithm has produced an optimal tree

Proofs of Correctness (Kruskal) Let e be the smallest weight edge in T that is not in T’ Add e to T’ and consider the cycle Y that is formed There must be some edge e’ on Y that has weight greater than e. Explain why? –What do we know about T and T’ up to this point?

Proofs of Correctness (Kruskal) Replace e’ by e in T’ We have a new spanning tree T’’ such that the weight of T’’ is smaller than the weight of T’ This contradicts the fact that T’ was optimal. This implies no such edge e can be found, and thus T must be optimal.

Proofs of Correctness (Prim) Let T’ be a minimum spanning tree for G Let T be the tree formed by Prim’s algorithm that utilizes edges in T’ whenever a tie needs to be broken Let e be the first edge added to T that is not in T’ Finish this argument