Minimum Spanning Trees. 2 有權重的圖 * 很多圖形演算法的問題都假設其輸入為有權重 的圖形. * 這裡我們假設權重都定在邊上面, 且權重值都 為正, 例如請參考上圖所顯示的圖形. a b c d e f gh 3 5 1 1 9 5 4 7 3 2 2 4 G=(V,E)

Slides:



Advertisements
Similar presentations
Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm.
Advertisements

Minimum Spanning Tree CSE 331 Section 2 James Daly.
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.
Graph Theory Graph theory is the study of the properties of graph structures. It provides us with a language with which to talk about graphs.
Lecture 18: Minimum Spanning Trees Shang-Hua Teng.
Chapter 9: Greedy Algorithms The Design and Analysis of Algorithms.
1 Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
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.
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.
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. 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.
1.1 Data Structure and Algorithm Lecture 13 Minimum Spanning Trees Topics Reference: Introduction to Algorithm by Cormen Chapter 13: Minimum Spanning Trees.
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.
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.
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.
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.
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)
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.
1 Greedy Technique Constructs a solution to an optimization problem piece by piece through a sequence of choices that are: b feasible b locally optimal.
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.
1 Week 3: Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm.
Empirical Study on Finding Minimal Spanning Tree S. J. Shyu 4/29/2012.
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
Minimum Spanning Tree Graph Theory Basics - Anil Kishore.
Lecture ? The Algorithms of Kruskal and Prim
Minimum Spanning Trees
Introduction to Algorithms
Minimum Spanning Tree Chapter 13.6.
Spanning Trees Kruskel’s Algorithm Prim’s Algorithm
Minimum Spanning Trees
Minimum Spanning Tree Shortest Paths
Minimum Spanning Trees
Lecture 12 Algorithm Analysis
CISC 235: Topic 10 Graph Algorithms.
Minimum Spanning Trees
Connected Components Minimum Spanning Tree
Minimum Spanning Tree.
Algorithms and Data Structures Lecture XII
Data Structures – LECTURE 13 Minumum spanning trees
Greedy Algorithm (17.4/16.4) Greedy Algorithm (GA)
Chapter 23 Minimum Spanning Tree
CS 583 Analysis of Algorithms
Minimum Spanning Tree Algorithms
Minimum Spanning Tree.
Minimum Spanning Trees
Minimum spanning tree Shortest path algorithms
Lecture 12 Algorithm Analysis
Total running time is O(E lg E).
Advanced Algorithms Analysis and Design
Finding Minimum Spanning Trees
Chapter 23: Minimum Spanning Trees: A graph optimization problem
Presentation transcript:

Minimum Spanning Trees

2 有權重的圖 * 很多圖形演算法的問題都假設其輸入為有權重 的圖形. * 這裡我們假設權重都定在邊上面, 且權重值都 為正, 例如請參考上圖所顯示的圖形. a b c d e f gh G=(V,E)

Minimum Spanning Trees3 Minimum Spanning Trees (MST) *Find the lowest-cost way to connect all of the points (the cost is the sum of weights of the selected edges). *The solution must be a tree. (Why ?) *A spanning tree : a subgraph that is a tree and connect all of the points. *A graph may contains exponential number of spanning trees. (e.g. # spanning trees of a complete graph = n n-2.)

Minimum Spanning Trees4 A High-Level Greedy Algorithm for MST  The algorithm grows a MST one edge at a time and maintains that A is always a subset of some MST. *An edge is safe if it can be safely added to without destroying the invariant. *How to check that T is a spanning tree of G ? *How to select a “safe edge” edge ? A =  ; while(T=(V,A) is not a spanning tree of G) { select a safe edge for A ; }

Minimum Spanning Trees5 MST 基本引理 Let V = V 1 + V 2,  (V 1,V 2 ) = {uv | u  V 1 & v  V 2 }. if xy   (V 1,V 2 ) and w(xy) = min {w(uv)| uv   (V 1,V 2 )}, then xy is contained in a MST. a b c d e f gh V1V1 V2V2 

Minimum Spanning Trees6 Kruskal’s Algorithm (pseudo code 1) A=  ; for( each edge in order by nondecreasing weight ) if( adding the edge to A doesn't create a cycle ){ add it to A; if( | A| == n  1 ) break; } *How to check that adding an edge does not create a cycle?

Minimum Spanning Trees7 Kruskal’s Algorithm ( 例 1/3) a b c d e f g h

Minimum Spanning Trees8 Kruskal’s Algorithm ( 例 2/3) a b c d e f g h

Minimum Spanning Trees9 Kruskal’s Algorithm ( 例 3/3) a b c d e f g h MST cost = 17

Minimum Spanning Trees10 Kruskal’s Algorithm (pseudo code 2) A =  ; initial(n); // for each node x construct a set {x} for( each edge xy in order by nondecreasing weight) if ( ! find(x, y) ) { union(x, y); add xy to A; if( | A| == n  1 ) break; } find(x, y) = true iff. x and y are in the same set union(x, y): unite the two sets that contain x and y, respectively. find(x, y) = true iff. x and y are in the same set union(x, y): unite the two sets that contain x and y, respectively.

Minimum Spanning Trees11 Prim’s Algorithm (pseudo code 1) ALGORITHM Prim(G) // Input: A weighted connected graph G=(V,E) // Output: A MST T=(V, A) V T  { v 0 } // Any vertex will do; A   ; for i  1 to |V|  1 do find an edge xy   ( V T, V  V T ) s.t. its weight is minimized among all edges in  ( V T, V  V T ); V T  V T  { y } ; A  A  { xy } ;

Minimum Spanning Trees12 Prim’s Algorithm ( 例 1/8) a b c d e f g h

Minimum Spanning Trees13 Prim’s Algorithm ( 例 2/8) a b c d e f g h

Minimum Spanning Trees14 Prim’s Algorithm ( 例 3/8) a b c d e f g h

Minimum Spanning Trees15 Prim’s Algorithm ( 例 4/8) a b c d e f g h

Minimum Spanning Trees16 Prim’s Algorithm ( 例 5/8) a b c d e f g h

Minimum Spanning Trees17 Prim’s Algorithm ( 例 6/8) a b c d e f g h

Minimum Spanning Trees18 Prim’s Algorithm ( 例 7/8) a b c d e f g h

Minimum Spanning Trees19 Prim’s Algorithm ( 例 8/8) a b c d e f g h MST cost = 17

Minimum Spanning Trees20 Prim’s Algorithm (pseudo code 2) Built a priority queue Q for V with key[u] =   u  V ; key[v 0 ] = 0;  [v 0 ] = Nil; // Any vertex will do While ( Q   ) { u = Extract-Min( Q ); for( each v  Adj(u) ) if ( v  Q && w(u, v) < key[v] ) {  [v] = u ; key[v] = w(u, v) ; Change-Priority( Q, v, key[v] ); }

Minimum Spanning Trees21 Minimum Spanning Tree ( 分析 ) *Let n = |V( G)|, m =|E( G)|. *Execution time of Kruskal’s algorithm: (use union-find operations, or disjoint-set unions) O(m log m ) = O(m log n ) *Running time of Prim’s algorithm: ]adjacency lists + (binary or ordinary) heap: O((m+n) log n ) = O(m log n ) ]adjacency matrix + unsorted list: O(n 2 ) ]adjacency lists + Fibonacci heap: O(n log n + m)