Minimum Spanning Tree

Similar documents
Shortest path problems

Minimum Spanning Trees My T. UF

Minimum-Spanning-Tree problem. Minimum Spanning Trees (Forests) Minimum-Spanning-Tree problem

Minimum Spanning Trees

22 Elementary Graph Algorithms. There are two standard ways to represent a

CSE 100 Minimum Spanning Trees Prim s and Kruskal

Part VI Graph algorithms. Chapter 22 Elementary Graph Algorithms Chapter 23 Minimum Spanning Trees Chapter 24 Single-source Shortest Paths

Single Source Shortest Path

G205 Fundamentals of Computer Engineering. CLASS 21, Mon. Nov Stefano Basagni Fall 2004 M-W, 1:30pm-3:10pm

Minimum-Cost Spanning Tree. Example

Example. Minimum-Cost Spanning Tree. Edge Selection Greedy Strategies. Edge Selection Greedy Strategies

5.4 Shortest Paths. Jacobs University Visualization and Computer Graphics Lab. CH : Algorithms and Data Structures 456

Chapter 23. Minimum Spanning Trees

Minimum Spanning Trees

Chapter 9. Greedy Technique. Copyright 2007 Pearson Addison-Wesley. All rights reserved.

Announcements Problem Set 5 is out (today)!

Minimum Spanning Trees

Greedy Algorithms. At each step in the algorithm, one of several choices can be made.

CS200: Graphs. Rosen Ch , 9.6, Walls and Mirrors Ch. 14

Minimum Spanning Trees

Lecture Notes for Chapter 23: Minimum Spanning Trees

CS 5321: Advanced Algorithms Minimum Spanning Trees. Acknowledgement. Minimum Spanning Trees

Week 12: Minimum Spanning trees and Shortest Paths

Shortest Path Algorithms

Lecture 10. Elementary Graph Algorithm Minimum Spanning Trees

2. True or false: even though BFS and DFS have the same space complexity, they do not always have the same worst case asymptotic time complexity.

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

Decreasing a key FIB-HEAP-DECREASE-KEY(,, ) 3.. NIL. 2. error new key is greater than current key 6. CASCADING-CUT(, )

Elementary Graph Algorithms: Summary. Algorithms. CmSc250 Intro to Algorithms

22 Elementary Graph Algorithms. There are two standard ways to represent a

4/8/11. Single-Source Shortest Path. Shortest Paths. Shortest Paths. Chapter 24

Week 11: Minimum Spanning trees

Minimum spanning trees

Outline. (single-source) shortest path. (all-pairs) shortest path. minimum spanning tree. Dijkstra (Section 4.4) Bellman-Ford (Section 4.

CSE373: Data Structures & Algorithms Lecture 17: Minimum Spanning Trees. Dan Grossman Fall 2013

Graphs. Part II: SP and MST. Laura Toma Algorithms (csci2200), Bowdoin College

Introduction to Algorithms. Lecture 11

Tutorial. Question There are no forward edges. 4. For each back edge u, v, we have 0 d[v] d[u].

Minimum Spanning Trees

CHAPTER 23. Minimum Spanning Trees

Partha Sarathi Manal

Graph Algorithms (part 3 of CSC 282),

CSE331 Introduction to Algorithms Lecture 15 Minimum Spanning Trees

Theory of Computing. Lecture 7 MAS 714 Hartmut Klauck

CIS 121 Data Structures and Algorithms Minimum Spanning Trees

COP 4531 Complexity & Analysis of Data Structures & Algorithms

ALGORITHM DESIGN GREEDY ALGORITHMS. University of Waterloo

23.2 Minimum Spanning Trees

Title. Ferienakademie im Sarntal Course 2 Distance Problems: Theory and Praxis. Nesrine Damak. Fakultät für Informatik TU München. 20.

Dijkstra s algorithm for shortest paths when no edges have negative weight.

CS 6783 (Applied Algorithms) Lecture 5

Data Structures and Algorithms. Werner Nutt

CHAPTER 13 GRAPH ALGORITHMS

Lecture 13. Reading: Weiss, Ch. 9, Ch 8 CSE 100, UCSD: LEC 13. Page 1 of 29

Weighted Graph Algorithms Presented by Jason Yuan

CSC 8301 Design & Analysis of Algorithms: Kruskal s and Dijkstra s Algorithms

All Shortest Paths. Questions from exercises and exams

Single Source Shortest Path: The Bellman-Ford Algorithm. Slides based on Kevin Wayne / Pearson-Addison Wesley

2pt 0em. Computer Science & Engineering 423/823 Design and Analysis of Algorithms. Lecture 04 Minimum-Weight Spanning Trees (Chapter 23)

Introduction to Algorithms

Exam 3 Practice Problems

Homework Assignment #3 Graph

Unit 2: Algorithmic Graph Theory

1 Minimum Spanning Trees (MST) b 2 3 a. 10 e h. j m

CS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019

CS583 Lecture 09. Jana Kosecka. Graph Algorithms Topological Sort Strongly Connected Component Minimum Spanning Tree

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

More Graph Algorithms: Topological Sort and Shortest Distance

Tree. number of vertices. Connected Graph. CSE 680 Prof. Roger Crawfis

COT 6405 Introduction to Theory of Algorithms

Dijkstra s Single Source Shortest Path Algorithm. Andreas Klappenecker

Algorithm Analysis Graph algorithm. Chung-Ang University, Jaesung Lee

CS 310 Advanced Data Structures and Algorithms

COMP251: Single source shortest paths

CS161 - Minimum Spanning Trees and Single Source Shortest Paths

Lecture 4: Graph Algorithms

CSE 431/531: Analysis of Algorithms. Greedy Algorithms. Lecturer: Shi Li. Department of Computer Science and Engineering University at Buffalo

CSE 421 Greedy Alg: Union Find/Dijkstra s Alg

Greedy Algorithms CSE 780

6.1 Minimum Spanning Trees

CS 561, Lecture 9. Jared Saia University of New Mexico

Shortest Path Problem

Advanced algorithms. topological ordering, minimum spanning tree, Union-Find problem. Jiří Vyskočil, Radek Mařík 2012

Chapter 24. Shortest path problems. Chapter 24. Shortest path problems. 24. Various shortest path problems. Chapter 24. Shortest path problems

Minimum Spanning Trees Ch 23 Traversing graphs

Department of Computer Science and Engineering Analysis and Design of Algorithm (CS-4004) Subject Notes

DESIGN AND ANALYSIS OF ALGORITHMS GREEDY METHOD

Minimum Spanning Trees

The minimum spanning tree problem

Complexity of Prim s Algorithm

Routing Protocols and the IP Layer

Dijkstra s Algorithm

Dijkstra's algorithm Prim's algorithm

Depth-first Search (DFS)

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Taking Stock. Last Time Flows. This Time Review! 1 Characterize the structure of an optimal solution

Solutions to relevant spring 2000 exam problems

Parallel Graph Algorithms

UNIT 3. Greedy Method. Design and Analysis of Algorithms GENERAL METHOD

UC Berkeley CS 170: Efficient Algorithms and Intractable Problems Handout 8 Lecturer: David Wagner February 20, Notes 8 for CS 170

Transcription:

Minimum Spanning Tree 1 Minimum Spanning Tree G=(V,E) is an undirected graph, where V is a set of nodes and E is a set of possible interconnections between pairs of nodes. For each edge (u,v) in E, we have a weight W(u,v). Find an acyclic subset T of E, that connects all the vertices and whose total weight is minimum. LECT-14, S-2 1

A Spanning Trees Quiz: Are minimum spanning trees unique? LECT-14, S-3 Kruskal s Algorithm Consider v isolated trees in the forest. Each initially with only one node. Pick the shortest path that connects two trees in the forest. In other words, select a least-cost edge that does not result in a cycle when added to a set of already selected edges. LECT-14, S-4 2

Algorithm Spanning Tree edge set. Initialize V forests. Sort edges. Make sure two ends are in two trees. No cycle. Merge the trees in the forest If no cycle, add the edge in the spanning tree set. LECT-14, S-5 Example: Kruskal s Algorithm LECT-14, S-6 3

Example: Kruskal s Algorithm LECT-14, S-7 Example: Continued.. LECT-14, S-8 4

Proof of Correctness of an Algorithm 9 Correctness of Krsukal s Algorithm Let T be the tree found by Kruskal s algorithm. Let U be the actual minimum spanning tree. We will prove cost of T= cost of U. Do you agree? T and U and all spanning trees must have exactly V-1 edges. If, k (k>o) number of edges in U are not in T, then exactly k number of edges in T must not be in U. We will one by one substitute a unique edge of U by unique edge of T to prove that the cost does not change. LECT-14, S-10 5

Correctness of Kruskal s Algorithm (contd..) Let e be the least-cost edge in T that is not in U. Add e to U. It must create a cycle. There must be an edge f in this cycle which was not in T. Take it out. The new spanning tree has cost V=U+{e}-{f} Can {e} < {f}? No because, then U cannot be minimum spanning tree. Can {e}>{f}? No because, then f will be included by Kruskal s greedy scheme before e. That did not happen! Therefore {e}={f} Therefore T=U LECT-14, S-11 Correctness of Kruskal s algorithm T Two solution s with same cost. U V=U+{b,c}-{a,h} LECT-14, S-12 6

Complexity of Kruskal s Algorithm 1-3: Initialization O(v) 4: sorting O(E log E) 5: E iterations. 6: Each FIND-SET is O(log E) total cost= 2E.O(log E) 7: 2E 8: UNION is at most V-1 Overall complexity is O(V+E log E) LECT-14, S-13 Prim s Algorithm Like Kruskal s, but, start with any node. Extend the tree to the closest node! LECT-14, S-14 7

Prim s Algorithm Add the vertices in a Queue Key[u] is the cost of reaching vertex u from current tree set. Start from any node r. Its cost is zero. PI[u] is the root of u. Take the vertex closest to the tree. For each node adj to u, but not in spanning tree, update the reaching cost. LECT-14, S-15 Example: Prim s Algorithm LECT-14, S-16 8

Example: Prim s Algorithm LECT-14, S-17 Example: Prim s Algorithm LECT-14, S-18 9

Complexity of Prim s Algorithm 1-5: Initialization O(v) 6: Loop executes V times. 7: Each EXTRACT-MIN is O(log V). Total O(V log V). 8: Loop 8-11 executes E times. 9: membership can be tested in constant time. 11: v have to be deleted from Q (not shown): O(log V) Total: O(V log V+E log V) LECT-14, S-19 Shortest Path 20 10

Shortest Path Other Variants: Single Destination shortest-path problem. Single-pair shortest path problem. All pairs shortest-paths problem. LECT-14, S-21 Greedy Method (Dijkstra s Algorithm) We keep a set S of vertices whose closest distances to the source, Vertex 0, are known and add one vertex to S at each stage. We maintain a table D that gives, for each vertex v, the distance from 0 to v along a path all of whose vertices are in S, except possibly the last one. To determine what vertex to add to S at each step, we apply the criterion of choosing the vertex v with the smallest distance recorded in the table D, such that v is not already in S. LECT-14, S-22 11

Example LECT-14, S-23 Example (contd..) LECT-14, S-24 12

Algorithm 1. INITIALIZE_SINGLE-SOURCE(G,s) 2. S = EMPTY. 3. Q= V[G] 4. While Q not EMPTY 5. u= EXTRACT-MIN(Q) 6. Add u in S 7. For each vertex v adjacent to u 8. Do Update cost if D[v] > d[u]+w[u,v] then D[v]=d[u]+w[u,v] GoFrom[v]=u LECT-14, S-25 Proof of Correctness v 0 x Let us assume the path through another node x, which is not yet included in S to v is closer. Then D[x] must be smaller than D[v], but in that case x should already be included in S! LECT-14, S-26 13

Complexity Each EXTRACT-MIN takes O(V). Each time at least one vertex will be added. Therefore it can take at most V iterations. Step 5 is O(v 2 ) On the other hand, in steps 4-8 each path will be processed only once. Thus the complexity is O(V 2 +E). 1. INITIALIZE_SINGLE-SOURCE(G,s) 2. S = EMPTY. 3. Q= V[G] 4. While Q not EMPTY 5. u= EXTRACT-MIN(Q) 6. Add u in S 7. For each vertex v adjacent to u 8. Do Update cost if D[v] > d[u]+w[u,v] then D[v]=d[u]+w[u,v] GoFrom[v]=u LECT-14, S-27 Bellman-Ford Algorithm It can solve the shortest-path problem, even if there are negative weighted links. What if there is a negative weighted cycle? Its complexity is O(V.E) LECT-14, S-28 14