Design and Analysis of Algorithms Minimum Spanning trees

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

Chapter 23 Minimum Spanning Tree
Design and Analysis of Algorithms Approximation algorithms for NP-complete problems Haidong Xue Summer 2012, at GSU.
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 Tree Sarah Brubaker Tuesday 4/22/8.
Greedy Algorithms Greed is good. (Some of the time)
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
Design and Analysis of Algorithms Single-source shortest paths, all-pairs shortest paths Haidong Xue Summer 2012, at GSU.
1 Greedy 2 Jose Rolim University of Geneva. Algorithmique Greedy 2Jose Rolim2 Examples Greedy  Minimum Spanning Trees  Shortest Paths Dijkstra.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 13 Minumum spanning trees Motivation Properties of minimum spanning trees Kruskal’s.
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.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Lecture 12 Minimum Spanning Tree. Motivating Example: Point to Multipoint Communication Single source, Multiple Destinations Broadcast – All nodes in.
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.
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 Trees What is a MST (Minimum Spanning Tree) and how to find it with Prim’s algorithm and Kruskal’s algorithm.
Minimum spanning tree Prof Amir Geva Eitan Netzer.
Minimum Spanning Tree Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
1.1 Data Structure and Algorithm Lecture 13 Minimum Spanning Trees Topics Reference: Introduction to Algorithm by Cormen Chapter 13: Minimum Spanning Trees.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Graph Algorithms: Minimum.
2IL05 Data Structures Fall 2007 Lecture 13: Minimum Spanning Trees.
Spring 2015 Lecture 11: Minimum Spanning Trees
0 Course Outline n Introduction and Algorithm Analysis (Ch. 2) n Hash Tables: dictionary data structure (Ch. 5) n Heaps: priority queue data structures.
Minimum Spanning Trees CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
7.1 and 7.2: Spanning Trees. A network is a graph that is connected –The network must be a sub-graph of the original graph (its edges must come from the.
Module 5 – Networks and Decision Mathematics Chapter 23 – Undirected Graphs.
1 Minimum Spanning Trees. Minimum- Spanning Trees 1. Concrete example: computer connection 2. Definition of a Minimum- Spanning Tree.
1 Greedy Algorithms and MST Dr. Ying Lu RAIK 283 Data Structures & Algorithms.
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.
Kruskal’s and Dijkstra’s Algorithm.  Kruskal's algorithm is an algorithm in graph theory that finds a minimum spanning tree for a connected weighted.
Minimum Spanning Trees CS 146 Prof. Sin-Min Lee Regina Wang.
Lecture19: Graph III Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
Minimum- Spanning Trees
Prims Algorithm for finding a minimum spanning tree
Lecture 12 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
Kruskal’s Algorithm for Computing MSTs Section 9.2.
Greedy Algorithms General principle of greedy algorithm
Minimum Spanning Trees
Chapter 9 : Graphs Part II (Minimum Spanning Trees)
Introduction to Algorithms
Minimum Spanning Tree Chapter 13.6.
Minimum Spanning Trees
Lecture 22 Minimum Spanning Tree
Minimum Spanning Trees
Lecture 12 Algorithm Analysis
Greedy Algorithms / Minimum Spanning Tree Yin Tat Lee
Short paths and spanning trees
Graph Algorithm.
Minimum Spanning Trees
Minimum Spanning Tree Neil Tang 3/25/2010
Connected Components Minimum Spanning Tree
Minimum Spanning Tree.
Minimum Spanning Tree.
Data Structures – LECTURE 13 Minumum spanning trees
Kruskal’s Minimum Spanning Tree Algorithm
Lecture 12 Algorithm Analysis
Minimum Spanning Tree Neil Tang 4/3/2008
Minimum Spanning Tree.
CSE 373: Data Structures and Algorithms
Greedy Algorithms Comp 122, Spring 2004.
Minimum Spanning Trees (MSTs)
Lecture 12 Algorithm Analysis
Prim’s Minimum Spanning Tree Algorithm Neil Tang 4/1/2008
CSE 373: Data Structures and Algorithms
Lecture 14 Minimum Spanning Tree (cont’d)
Minimum-Cost Spanning Tree
Presentation transcript:

Design and Analysis of Algorithms Minimum Spanning trees Haidong Xue Summer 2012, at GSU

What are trees in undirected graphs? We are familiar with a rooted directed tree, such as: Binary search tree Heap They look like: You know which one the root is Who the parent is Who the children are 3 6 5 4 2

What are trees in undirected graphs? However, in undirected graphs, there is another definition of trees Tree A undirected graph (V, E), where E is the set of undirected edges All vertices are connected |E|=|V|-1 3 5 6 4 2

What is a spanning tree? Unless otherwise specified, spanning tree is about a tree of a undirected graph A spanning tree of graph G=(V, E) is: A graph G’=(V’, E’), where 𝑉’=𝑉, 𝐸′⊆𝐸 G’ is a tree Given the following graph, are they spanning trees? b c d a i e h g f

What is a spanning tree? Given the following graph, are they spanning trees? b c d a i e h g f Is the red sub graph a tree? Yes Is the red sub graph a spanning tree? No. 𝑉’ ≠𝑉

What is a spanning tree? Given the following graph, are they spanning trees? b c d a i e h g f Is the red sub graph a tree? No. |E| ≠ 𝑉 ′ −1 Is the red sub graph a spanning tree? No. It is not a tree.

What is a spanning tree? Given the following graph, are they spanning trees? b c d a i e h g f Is the red sub graph a tree? No. Vertices are not all connected Is the red sub graph a spanning tree? No. It is not a tree.

What is a spanning tree? Given the following graph, are they spanning trees? b c d a i e h g f Is the red sub graph a tree? Yes Is the red sub graph a spanning tree? Yes

What is a spanning tree? Given the following graph, are they spanning trees? b c d a i e h g f Is the red sub graph a tree? Yes Is the red sub graph a spanning tree? Yes There could be more than one spanning trees

What is a minimum spanning tree? When edges are weighted A minimum spanning tree of G is: A spanning tree of G With a minimum sum of a edge weights sum among all spanning trees 8 7 b c d 4 9 2 11 14 a i 4 e 7 6 8 10 h g f 1 2

What is a minimum spanning tree? Spanning trees: 8 7 b c d The weight sum of this spanning tree? 4 9 2 11 14 a i 4 e 48 7 6 8 10 h g f 1 2 b c d The weight sum of this spanning tree? 4 9 2 11 14 47 a i 4 e 7 6 8 10 h g f 1 2

What is a minimum spanning tree? Spanning trees: 8 7 b c d The weight sum of this spanning tree? 4 9 2 11 14 a i 4 e 37 7 6 8 10 h g f 1 2 8 7 b c d The weight sum of this spanning tree? 4 9 2 11 14 37 a i 4 e 7 6 8 10 These 2 are minimum spanning trees since there is no spanning tree with a smaller total weight h g f 1 2

Minimum spanning tree problem Minimum spanning tree (MST) problem: given a undirected graph G, find a spanning tree with the minimum total edge weights. There are 2 classic greedy algorithms to solve this problem Kruskal’s algorithm Prim’s algorithm

Minimum spanning tree problem A application example of MST in computer network What if PC3 wants to communicate with PC7? By a routing protocol: PC3 broadcasts this requirement to PC2, PC4 PC2 broadcasts it to PC1, PC5 PC1 broadcasts it to PC5, PC6 … PC5 broadcasts it to PC2 At least, a package is in a deadlock: PC2->PC1->PC5-PC2->PC1-> ……………. PC1 PC2 PC3 PC6 PC5 PC4 Find and use a MST can solve this problem, since there is no cycle

Minimum spanning tree problem The MST algorithm can be considered as choose |V|-1 edges from E to form a minimum spanning tree Both Kruskal’s algorithm and Prim’s algorithm proposed a greedy choice about how to choose a edge They have greedy choice property because of textbook Corollary 23.2

Kruskal’s algorithm Input: G=(V, E) Output: a minimum spanning tree (V, A) Kruskal (G=(V, E)) Set each vertices in V as a vertex set; Set A as an empty set; while (there are more than 1 vertex set){ Add a smallest edge (u, v) to A where u, v are not in the same set; Merge the set contains u with the set contains v; } In most of the implementations, edges are sorted on weights at the beginning, and then scan them once The running time = O(|E|lg|V|)

Kruskal’s algorithm Kruskal (G=(V, E)) Set each vertices in V as a vertex set; Set A as an empty set; while (there are more than 1 vertex set){ Add a smallest edge (u, v) to A where u, v are not in the same set; Merge the set contains u with the set contains v; } Edge Weight (h, g) 1 (i, c) 2 (g, f) (c, f) 4 (a, b) (i, g) 6 (h, i) 7 (c, d) (a, h) 8 (b, c) (d, e) 9 (e, f) 10 (b, h) 11 (d, f) 14 8 7 b c d 4 9 2 11 14 a i 4 e 7 6 8 10 h g f 1 2 Total weight: 37

Prim’s algorithm Input: G=(V, E) Output: a minimum spanning tree (V, A) Prim(G=(V, E)) Set A as an empty set; Choose a vertex as the current MST; while (not all the vertices are added into the MST){ Choose the smallest edge crossing current MST vertices and other vertices, and put it to MST ; } The running time = O(|E|lg|V|)

Prim’s algorithm Prim(G=(V, E)) Set A as an empty set; Choose a vertex as the current MST; while (not all the vertices are added into the MST){ Choose the smallest safe edge, and put it to MST; } 8 7 b c d 4 9 2 11 14 a i 4 e 7 6 8 10 h g f 1 2 Total weight: 37

Summary Prim’s algorithm and Kruskal’s algorithm have the same asymptotically running time