Minimum Spanning Tree.

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

O(N 1.5 ) divide-and-conquer technique for Minimum Spanning Tree problem Step 1: Divide the graph into  N sub-graph by clustering. Step 2: Solve each.
Minimum Spanning Trees Definition Two properties of MST’s Prim and Kruskal’s Algorithm –Proofs of correctness Boruvka’s algorithm Verifying an MST Randomized.
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
CSE 780 Algorithms Advanced Algorithms Minimum spanning tree Generic algorithm Kruskal’s algorithm Prim’s algorithm.
Minimum Spanning Trees Definition Algorithms –Prim –Kruskal Proofs of correctness.
Spanning Trees.
Spanning Trees. 2 Spanning trees Suppose you have a connected undirected graph Connected: every node is reachable from every other node Undirected: edges.
Minimum-Cost Spanning Tree weighted connected undirected graph spanning tree cost of spanning tree is sum of edge costs find spanning tree that has minimum.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 11 Instructor: Paul Beame.
Design and Analysis of Algorithms Minimum Spanning trees
Prim’s Algorithm and an MST Speed-Up
Spanning Trees. Spanning trees Suppose you have a connected undirected graph –Connected: every node is reachable from every other node –Undirected: edges.
Minimum Spanning Trees
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.
Minimum Spanning Tree By Jonathan Davis.
Minimum Spanning Trees What is a MST (Minimum Spanning Tree) and how to find it with Prim’s algorithm and Kruskal’s algorithm.
Minimum Spanning Tree in Graph - Week Problem: Laying Telephone Wire Central office.
Minimum Spanning Trees and Clustering By Swee-Ling Tang April 20, /20/20101.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Graph Algorithms: Minimum.
SPANNING TREES Lecture 21 CS2110 – Spring
0 Course Outline n Introduction and Algorithm Analysis (Ch. 2) n Hash Tables: dictionary data structure (Ch. 5) n Heaps: priority queue data structures.
Module 5 – Networks and Decision Mathematics Chapter 23 – Undirected Graphs.
Minimum Spanning Trees Easy. Terms Node Node Edge Edge Cut Cut Cut respects a set of edges Cut respects a set of edges Light Edge Light Edge Minimum Spanning.
Minimum-Cost Spanning Tree CS 110: Data Structures and Algorithms First Semester,
Prim's Algorithm This algorithm starts with one node. It then, one by one, adds a node that is unconnected to the new graph to the new graph, each time.
Lecture 19 Greedy Algorithms Minimum Spanning Tree Problem.
Minimal Spanning Tree Problems in What is a minimal spanning tree An MST is a tree (set of edges) that connects all nodes in a graph, using.
Chapter 8 Dynamic Programming Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Minimum Spanning Trees CS 146 Prof. Sin-Min Lee Regina Wang.
Lecture19: Graph III Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
Union-Find  Application in Kruskal’s Algorithm  Optimizing Union and Find Methods.
SPANNING TREES Lecture 20 CS2110 – Fall Spanning Trees  Definitions  Minimum spanning trees  3 greedy algorithms (incl. Kruskal’s & Prim’s)
Minimum- Spanning Trees
MA/CSSE 473 Day 34 MST details: Kruskal's Algorithm Prim's Algorithm.
© M. Winter COSC/MATH 4P61 - Theory of Computation Minimum-weight Spanning Tree Weighted Graph Spanning.
Data Structures & Algorithms Graphs Richard Newman based on book by R. Sedgewick and slides by S. Sahni.
Minimum Spanning Tree Graph Theory Basics - Anil Kishore.
Graph Search Applications, Minimum Spanning Tree
Minimum-cost spanning tree
Minimum-Cost Spanning Tree and Kruskal’s Algorithm
Minimum Spanning Trees
Chapter 9 : Graphs Part II (Minimum Spanning Trees)
May 12th – Minimum Spanning Trees
Minimum Spanning Trees
Minimum Spanning Tree Chapter 13.6.
Minimum Spanning Trees
Lecture 22 Minimum Spanning Tree
Short paths and spanning trees
Data Structures & Algorithms Graphs
Graph Algorithm.
Minimum-Cost Spanning Tree
CSCE350 Algorithms and Data Structure
Minimum Spanning Tree.
Minimum Spanning Trees
Connected Components Minimum Spanning Tree
Minimum Spanning Tree.
Minimum Spanning Trees
Spanning Trees.
Minimum-Cost Spanning Tree
Minimum-Cost Spanning Tree
Kruskal’s Minimum Spanning Tree Algorithm
MA/CSSE 473 Day 33 Student Questions Change to HW 13
Minimum Spanning Trees
Minimum Spanning Tree.
Minimum spanning trees
Minimum Spanning Trees (MSTs)
Spanning Trees Lecture 20 CS2110 – Spring 2015.
Lecture 14 Minimum Spanning Tree (cont’d)
Minimum-Cost Spanning Tree
Presentation transcript:

Minimum Spanning Tree

Spanning Trees A spanning tree of a graph is just a subgraph that contains all the vertices and is a tree. A graph may have many spanning trees. Graph A Some Spanning Trees from Graph A or or or

Complete Graph All 16 of its Spanning Trees

Minimum Spanning Trees The Minimum Spanning Tree for a given graph is the Spanning Tree of minimum cost for that graph. Complete Graph Minimum Spanning Tree 7 2 2 5 3 3 4 1 1

Algorithms for Obtaining the Minimum Spanning Tree Kruskal's Algorithm Prim's Algorithm Boruvka's Algorithm

Complete Graph 4 B C 4 2 1 A 4 E F 1 2 D 3 10 5 G 5 6 3 4 I H 3 2 J

4 1 A B A D 4 4 B C B D 4 10 2 B C B J C E 4 2 1 1 5 C F D H A 4 E F 1 6 2 2 D J E G D 3 10 5 G 3 5 F G F I 5 6 3 4 3 4 I G I G J H 3 2 J 2 3 H J I J

Sort Edges (in reality they are placed in a priority queue - not sorted - but sorting them makes the algorithm easier to visualize) 1 1 A D C F 2 2 C E E G 4 2 3 B C H J F G 4 2 1 3 3 G I I J A 4 E F 1 4 4 2 A B B D D 3 10 5 G 4 4 B C G J 5 6 3 4 5 5 I F I D H H 3 2 J 6 10 D J B J

Add Edge 1 1 A D C F 2 2 C E E G 4 2 3 B C H J F G 4 2 1 3 3 G I I J A 10 5 G 4 4 B C G J 5 6 3 4 5 5 I F I D H H 3 2 J 6 10 D J B J

Add Edge 1 1 A D C F 2 2 C E E G 4 2 3 B C H J F G 4 2 1 3 3 G I I J A 10 5 G 4 4 B C G J 5 6 3 4 5 5 I F I D H H 3 2 J 6 10 D J B J

Add Edge 1 1 A D C F 2 2 C E E G 4 2 3 B C H J F G 4 2 1 3 3 G I I J A 10 5 G 4 4 B C G J 5 6 3 4 5 5 I F I D H H 3 2 J 6 10 D J B J

Add Edge 1 1 A D C F 2 2 C E E G 4 2 3 B C H J F G 4 2 1 3 3 G I I J A 10 5 G 4 4 B C G J 5 6 3 4 5 5 I F I D H H 3 2 J 6 10 D J B J

Add Edge 1 1 A D C F 2 2 C E E G 4 2 3 B C H J F G 4 2 1 3 3 G I I J A 10 5 G 4 4 B C G J 5 6 3 4 5 5 I F I D H H 3 2 J 6 10 D J B J

Cycle Don’t Add Edge 1 1 A D C F 2 2 C E E G 4 2 3 B C H J F G 4 2 1 3 I I J A 4 E F 1 4 4 2 A B B D D 3 10 5 G 4 4 B C G J 5 6 3 4 5 5 I F I D H H 3 2 J 6 10 D J B J

Add Edge 1 1 A D C F 2 2 C E E G 4 2 3 B C H J F G 4 2 1 3 3 G I I J A 10 5 G 4 4 B C G J 5 6 3 4 5 5 I F I D H H 3 2 J 6 10 D J B J

Add Edge 1 1 A D C F 2 2 C E E G 4 2 3 B C H J F G 4 2 1 3 3 G I I J A 10 5 G 4 4 B C G J 5 6 3 4 5 5 I F I D H H 3 2 J 6 10 D J B J

Add Edge 1 1 A D C F 2 2 C E E G 4 2 3 B C H J F G 4 2 1 3 3 G I I J A 10 5 G 4 4 B C G J 5 6 3 4 5 5 I F I D H H 3 2 J 6 10 D J B J

Cycle Don’t Add Edge 1 1 A D C F 2 2 C E E G 4 2 3 B C H J F G 4 2 1 3 I I J A 4 E F 1 4 4 2 A B B D D 3 10 5 G 4 4 B C G J 5 6 3 4 5 5 I F I D H H 3 2 J 6 10 D J B J

Add Edge 1 1 A D C F 2 2 C E E G 4 2 3 B C H J F G 4 2 1 3 3 G I I J A 10 5 G 4 4 B C G J 5 6 3 4 5 5 I F I D H H 3 2 J 6 10 D J B J

Minimum Spanning Tree Complete Graph 4 B C 4 B C 4 4 2 1 2 1 A E A 4 F D 2 D 3 10 G 5 G 3 5 6 3 4 I I H H 3 2 3 J 2 J

Prim's Algorithm This algorithm starts with one node. It then, one by one, adds a node that is unconnected to the new graph to the new graph, each time selecting the node whose connecting edge has the smallest weight out of the available nodes’ connecting edges.

Complete Graph 4 B C 4 2 1 A 4 E F 1 2 D 3 10 5 G 5 6 3 4 I H 3 2 J

Old Graph New Graph 4 B C 4 4 B C 2 1 4 2 1 A 4 E F 1 A 4 E F 1 2 D 3 10 D 3 5 G 10 5 G 5 6 3 5 6 3 4 I 4 H I H 3 2 J 3 2 J

Old Graph New Graph 4 B C 4 4 B C 2 1 4 2 1 A 4 E F 1 A 4 E F 1 2 D 3 10 D 3 5 G 10 5 G 5 6 3 5 6 3 4 I 4 H I H 3 2 J 3 2 J

Old Graph New Graph 4 B C 4 4 B C 2 1 4 2 1 A 4 E F 1 A 4 E F 1 2 D 3 10 D 3 5 G 10 5 G 5 6 3 5 6 3 4 I 4 H I H 3 2 J 3 2 J

Old Graph New Graph 4 B C 4 4 B C 2 1 4 2 1 A 4 E F 1 A 4 E F 1 2 D 3 10 D 3 5 G 10 5 G 5 6 3 5 6 3 4 I 4 H I H 3 2 J 3 2 J

Old Graph New Graph 4 B C 4 4 B C 2 1 4 2 1 A 4 E F 1 A 4 E F 1 2 D 3 10 D 3 5 G 10 5 G 5 6 3 5 6 3 4 I 4 H I H 3 2 J 3 2 J

Old Graph New Graph 4 B C 4 4 B C 2 1 4 2 1 A 4 E F 1 A 4 E F 1 2 D 3 10 D 3 5 G 10 5 G 5 6 3 5 6 3 4 I 4 H I H 3 2 J 3 2 J

Old Graph New Graph 4 B C 4 4 B C 2 1 4 2 1 A 4 E F 1 A 4 E F 1 2 D 3 10 D 3 5 G 10 5 G 5 6 3 5 6 3 4 I 4 H I H 3 2 J 3 2 J

Old Graph New Graph 4 B C 4 4 B C 2 1 4 2 1 A 4 E F 1 A 4 E F 1 2 D 3 10 D 3 5 G 10 5 G 5 6 3 5 6 3 4 I 4 H I H 3 2 J 3 2 J

Old Graph New Graph 4 B C 4 4 B C 2 1 4 2 1 A 4 E F 1 A 4 E F 1 2 D 3 10 D 3 5 G 10 5 G 5 6 3 5 6 3 4 I 4 H I H 3 2 J 3 2 J

Old Graph New Graph 4 B C 4 4 B C 2 1 4 2 1 A 4 E F 1 A 4 E F 1 2 D 3 10 D 3 5 G 10 5 G 5 6 3 5 6 3 4 I 4 H I H 3 2 J 3 2 J

Complete Graph Minimum Spanning Tree 4 B C 4 4 B C 2 1 4 2 1 A 4 E F 1 D 3 2 10 D 5 G G 5 6 3 3 4 I H I H 3 2 J 3 2 J

Boruvka's Algorithm This algorithm is similar to Prim’s, but nodes are added to the new graph in parallel all around the graph. It creates a list of trees, each containing one node from the original graph and proceeds to merge them along the smallest-weight connecting edges until there’s only one tree, which is, of course, the MST. It works rather like a merge sort.

Complete Graph 4 B C 4 2 1 A 4 E F 1 2 D 3 10 5 G 5 6 3 4 I H 3 2 J

Trees of the Graph at Beginning of Round 1 List of Trees A B C D E F G H I J 4 B C 4 2 1 A 4 E F 1 2 D 3 10 5 G 5 6 3 4 I H 3 2 J

Round 1 Tree A 4 B C B 4 4 2 1 A 4 E A F 1 1 2 D 3 D 10 5 G 5 6 3 4 I H 3 2 J

Round 1 Edge A-D 4 B C B 4 4 2 1 A 4 E A F 1 1 2 D 3 D 10 5 G 5 6 3 4 I H 3 2 J

Round 1 Tree B 4 B C 4 B C 4 4 2 1 A 4 E A 4 F 1 2 D 3 D 10 10 5 G 5 6 I H 3 2 J J

Round 1 Edge B-A 4 B C 4 B C 4 4 2 1 A 4 E A 4 F 1 2 D 3 D 10 10 5 G 5 6 3 4 I H 3 2 J J

Round 1 Tree C 4 B C 4 B C 4 2 1 2 1 A 4 E F E 1 F 2 D 3 10 5 G 5 6 3 I H 3 2 J

Round 1 Edge C-F 4 B C 4 B C 4 2 1 2 1 A 4 E F E 1 F 2 D 3 10 5 G 5 6 I H 3 2 J

Round 1 Tree D 4 B C B 4 2 1 A 4 E A 4 F 1 1 2 D 3 D 10 5 G 5 6 3 5 6 I H H 3 2 J J

Round 1 Edge D-A 4 B C B 4 2 1 A 4 E A 4 F 1 1 2 D 3 D 10 5 G 5 6 3 5 I H H 3 2 J J

Round 1 Tree E 4 B C C 4 2 1 2 A 4 E F E 1 2 D 3 2 10 5 G G 5 6 3 4 I H 3 2 J

Round 1 Edge E-C 4 B C C 4 2 1 2 A 4 E F E 1 2 D 3 2 10 5 G G 5 6 3 4 I H 3 2 J

Round 1 Tree F 4 B C C 4 2 1 1 A 4 E F 1 F 2 D 3 3 10 5 G 5 G 5 6 3 4 I I H 3 2 J

Round 1 Edge F-C 4 B C C 4 2 1 1 A 4 E F 1 F 2 D 3 3 10 5 G 5 G 5 6 3 I I H 3 2 J

Round 1 Tree G 4 B C 4 2 1 A 4 E F E 1 F 2 D 3 2 3 10 5 G G 5 6 3 3 4 I I H 3 2 J J

Round 1 Edge G-E 4 B C 4 2 1 A 4 E F E 1 F 2 D 3 2 3 10 5 G G 5 6 3 3 I I H 3 2 J J

Round 1 Tree H 4 B C 4 2 1 A 4 E F 1 2 D 3 D 10 5 G 5 6 3 5 4 I H H 3 J 2 J

Round 1 Edge H-J 4 B C 4 2 1 A 4 E F 1 2 D 3 D 10 5 G 5 6 3 5 4 I H H

Round 1 Tree I 4 B C 4 2 1 A 4 E F 1 F 2 D 3 10 5 G 5 G 5 6 3 3 4 I I H 3 2 3 J J

Round 1 Edge I-G 4 B C 4 2 1 A 4 E F 1 F 2 D 3 10 5 G 5 G 5 6 3 3 4 I H 3 2 3 J J

Round 1 Tree J 4 B C B 4 2 1 A 4 E F 1 2 D 3 D 10 10 5 G G 5 6 3 6 4 4 I I H H 3 2 3 J 2 J

Round 1 Edge J-H 4 B C B 4 2 1 A 4 E F 1 2 D 3 D 10 10 5 G G 5 6 3 6 4 I I H H 3 2 3 J 2 J

A-D B-A C-F D-A E-C F-C G-E H-J I-G J-H Round 1 Ends - Add Edges List of Edges to Add A-D B-A C-F D-A E-C F-C G-E H-J I-G J-H 4 B C 4 2 1 A 4 E F 1 2 D 3 10 5 G 5 6 3 4 I H 3 2 J

Trees of the Graph at Beginning of Round 2 List of Trees D-A-B F-C-E-G-I H-J 4 B C 4 2 1 A 4 E F 1 2 D 3 10 5 G 5 6 3 4 I H 3 2 J

Round 2 Tree D-A-B 4 B C 4 B C 4 4 2 1 2 1 A 4 E A 4 F E 1 F 1 2 D 3 2 10 10 5 G G 5 6 3 5 6 3 4 I I H H 3 2 J 2 J

Round 2 Edge B-C 4 B C 4 B C 4 4 2 1 2 1 A 4 E A 4 F E 1 F 1 2 D 3 2 D 10 10 5 G G 5 6 3 5 6 3 4 I I H H 3 2 J 2 J

Round 2 Tree F-C-E-G-I 4 B C 4 B C 4 4 2 1 2 1 A 4 E A F E 1 F 1 2 D 3 10 5 G 5 G 5 6 3 3 4 4 I I H H 3 2 3 J 2 J

Round 2 Edge I-J 4 B C 4 B C 4 4 2 1 2 1 A 4 E A F E 1 F 1 2 D 3 2 D 3 10 5 G 5 G 5 6 3 3 4 4 I I H H 3 2 3 J 2 J

Round 2 Tree H-J 4 B C B C 4 4 2 1 2 1 A 4 E A F E 1 F 1 2 D 3 2 D 10 5 G G 5 6 3 5 6 3 4 4 I I H H 3 2 3 J 2 J

Round 2 Edge J-I 4 B C B C 4 4 2 1 2 1 A 4 E A F E 1 F 1 2 D 3 2 D 10 5 G G 5 6 3 5 6 3 4 4 I I H H 3 2 3 J 2 J

B-C I-J J-I Round 2 Ends - Add Edges List of Edges to Add 4 B C 4 2 1 3 10 5 G 5 6 3 4 I H 3 2 J

Minimum Spanning Tree Complete Graph 4 B C 4 B C 4 4 2 1 2 1 A E A 4 F D 2 D 3 10 G 5 G 3 5 6 3 4 I I H H 3 2 3 J 2 J

Conclusion Kruskal’s and Boruvka’s have better running times if the number of edges is low, while Prim’s has a better running time if both the number of edges and the number of nodes are low. Boruvka’s avoids the complicated data structures needed for the other two algorithms. So, of course, the best algorithm depends on the graph and if you want to bear the cost of complex data structures. The best algorithm that I know of is a hybrid of Boruvka’s and Prim’s, which I did not examine here. It does O(log log n) passes of Boruvka’s and then switches to Prim’s, resulting in a running time of O(m log log n). So, it’s the fastest algorithm, but would, of course, require the Fibonacci heap for Prim’s which Boruvka’s avoids when used by itself. However, in order to keep things simple, I did not explore it here.