Midwestern State University Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm 1.

Slides:



Advertisements
Similar presentations
Comp 122, Spring 2004 Greedy Algorithms. greedy - 2 Lin / Devi Comp 122, Fall 2003 Overview  Like dynamic programming, used to solve optimization problems.
Advertisements

Greedy Algorithms Greed is good. (Some of the time)
Greedy Algorithms Spanning Trees Chapter 16, 23. What makes a greedy algorithm? Feasible –Has to satisfy the problem’s constraints Locally Optimal –The.
Greed is good. (Some of the time)
Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm.
More Graph Algorithms Minimum Spanning Trees, Shortest Path Algorithms.
1 Greedy 2 Jose Rolim University of Geneva. Algorithmique Greedy 2Jose Rolim2 Examples Greedy  Minimum Spanning Trees  Shortest Paths Dijkstra.
Chapter 23 Minimum 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.
Lecture 18: Minimum Spanning Trees Shang-Hua Teng.
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.
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.
Data Structures and Algorithms Graphs Minimum Spanning Tree PLSD210.
Midwestern State University Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm 1.
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.
Theory of Computing Lecture 10 MAS 714 Hartmut Klauck.
Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm Binary Search Trees1.
Algorithms: Design and Analysis Summer School 2013 at VIASM: Random Structures and Algorithms Lecture 3: Greedy algorithms Phan Th ị Hà D ươ ng 1.
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.
Minimum Spanning Trees Prof. Sin-Min Lee Dept. of Computer Science, San Jose State University.
1 Minimum Spanning Trees (some material adapted from slides by Peter Lee, Ananda Guna, Bettina Speckmann)
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)
Minimum Spanning Tree: Prim’s & Kruskal’s Algorithms Presenter: Michal Karpinski.
© 2007 Seth James Nielson Minimum Spanning Trees … or how to bring the world together on a budget.
 2004 SDU Lecture 6- Minimum Spanning Tree 1.The Minimum Spanning Tree Problem 2.Greedy algorithms 3.A Generic Algorithm 4.Kruskal’s Algorithm.
Minimum- Spanning Trees
© 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.
WEEK 12 Graphs IV Minimum Spanning Tree Algorithms.
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.
November 22, Algorithms and Data Structures Lecture XII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Lecture ? The Algorithms of Kruskal and Prim
Minimum Spanning Trees
Introduction to Algorithms
May 12th – Minimum Spanning Trees
Minimum Spanning Trees
Lecture 12 Algorithm Analysis
Greedy Algorithms / Minimum Spanning Tree Yin Tat Lee
CSCE350 Algorithms and Data Structure
Spanning Trees.
Minimum Spanning Trees
Minimum Spanning Tree.
CSE 373 Data Structures and Algorithms
Algorithms and Data Structures Lecture XII
Data Structures – LECTURE 13 Minumum spanning trees
Chapter 23 Minimum Spanning Tree
CS 583 Analysis of Algorithms
Minimum Spanning Tree Section 7.3: Examples {1,2,3,4}
Lecture 12 Algorithm Analysis
Minimum Spanning Tree Algorithms
Minimum Spanning Trees
Minimum Spanning Trees
CSE 373: Data Structures and Algorithms
Lecture 12 Algorithm Analysis
Chapter 23: Minimum Spanning Trees: A graph optimization problem
Minimum Spanning Trees
Presentation transcript:

Midwestern State University Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm 1

2 Definition of MST Let G=(V,E) be a connected, undirected graph. For each edge (u,v) in E, we have a weight w(u,v) specifying the cost (length of edge) to connect u and v. We wish to find a (acyclic) subset T of E that connects all of the vertices in V and whose total weight is minimized. Since the total weight is minimized, the subset T must be acyclic (no circuit). Thus, T is a tree. We call it a spanning tree. The problem of determining the tree T is called the minimum-spanning-tree problem.

3 Application of MST: an example In the design of electronic circuitry, it is often necessary to make a set of pins electrically equivalent by wiring them together. Running cable TV to a set of houses. What’s the least amount of cable needed to still connect all the houses?

What makes a greedy algorithm? Feasible –Has to satisfy the problem’s constraints Locally Optimal –The greedy part –Has to make the best local choice among all feasible choices available on that step If this local choice results in a global optimum then the problem has optimal substructure Irrevocable –Once a choice is made it can’t be un-done on subsequent steps of the algorithm Simple examples: –Playing chess by making best move without lookahead –Giving fewest number of coins as change Simple and appealing, but don’t always give the best solution

Spanning Tree Definition –A spanning tree of a graph G is a tree (acyclic) that connects all the vertices of G once i.e. the tree “spans” every vertex in G –A Minimum Spanning Tree (MST) is a spanning tree on a weighted graph that has the minimum total weight Where might this be useful? Can also be used to approximate some NP-Complete problems

6 Here is an example of a connected graph and its minimum spanning tree: a b h cd e fg i Notice that the tree is not unique: replacing (b,c) with (a,h) yields another spanning tree with the same minimum weight.

7 Growing a MST Set A is always a subset of some minimum spanning tree.. An edge (u,v) is a safe edge for A if by adding (u,v) to the subset A, we still have a minimum spanning tree. GENERIC_MST(G,w) 1A:={} 2while A does not form a spanning tree do 3find an edge (u,v) that is safe for A 4A:=A ∪ {(u,v)} 5return A

8 How to find a safe edge We need some definitions and a theorem. A cut (S,V-S) of an undirected graph G=(V,E) is a partition of V. An edge crosses the cut (S,V-S) if one of its endpoints is in S and the other is in V-S. An edge is a light edge crossing a cut if its weight is the minimum of any edge crossing the cut.

9 V-S↓ a b h cd e fg i S↑S↑ ↑ S ↓ V-S This figure shows a cut (S,V-S) of the graph. The edge (d,c) is the unique light edge crossing the cut.

10 The algorithms of Kruskal and Prim The two algorithms are elaborations of the generic algorithm. They each use a specific rule to determine a safe edge in the GENERIC_MST. In Kruskal's algorithm, –The set A is a forest. –The safe edge added to A is always a least-weight edge in the graph that connects two distinct components. In Prim's algorithm, –The set A forms a single tree. –The safe edge added to A is always a least-weight edge connecting the tree to a vertex not in the tree.

11 Kruskal's algorithm (simple) (Sort the edges in an increasing order) A:={} while (E is not empty do) { take an edge (u, v) that is shortest in E and delete it from E If (u and v are in different components)then add (u, v) to A } Note: each time a shortest edge in E is considered.

12 Kruskal's algorithm 1 function Kruskal(G = : graph; length: A → R+): set of edges 2 Define an elementary cluster C(v) ← {v}. 3 Initialize a priority queue Q to contain all edges in G, using the weights as keys. 4 Define a forest T ← Ø //T will ultimately contain the edges of the MST 5 // n is total number of vertices 6 while T has fewer than n-1 edges do 7 // edge u,v is the minimum weighted route from u to v 8 (u,v) ← Q.removeMin() 9 // prevent cycles in T. add u,v only if T does not already contain a path // between u and v. 10 // the vertices has been added to the tree. 11 Let C(v) be the cluster containing v, and let C(u) be the cluster containing u. 13 if C(v) ≠ C(u) then 14 Add edge (v,u) to T. 15 Merge C(v) and C(u) into one cluster, that is, union C(v) and C(u). 16 return tree T

13 This is our original graph. The numbers near the arcs indicate their weight. None of the arcs are highlighted. Kruskal's algorithm

14 AD and CE are the shortest arcs, with length 5, and AD has been arbitrarily chosen, so it is highlighted. Kruskal's algorithm

15 CE is now the shortest arc that does not form a cycle, with length 5, so it is highlighted as the second arc. Kruskal's algorithm

16 The next arc, DF with length 6, is highlighted using much the same method. Kruskal's algorithm

17 The next-shortest arcs are AB and BE, both with length 7. AB is chosen arbitrarily, and is highlighted. The arc BD has been highlighted in red, because there already exists a path (in green) between B and D, so it would form a cycle (ABD) if it were chosen. Kruskal's algorithm

18 The process continues to highlight the next-smallest arc, BE with length 7. Many more arcs are highlighted in red at this stage: BC because it would form the loop BCE, DE because it would form the loop DEBA, and FE because it would form FEBAD. Kruskal's algorithm

19 Finally, the process finishes with the arc EG of length 9, and the minimum spanning tree is found. Kruskal's algorithm

20 Prim's algorithm (simple) MST_PRIM(G,w,r){ A={} S:={r} (r is an arbitrary node in V) Q=V-{r}; while Q is not empty do { take an edge (u, v) such that u  S and v  Q (v  S ) and (u,v) is the shortest edge add (u, v) to A, add v to S and delete v from Q }

21 Prim's algorithm for each vertex in graph set min_distance of vertex to ∞ set parent of vertex to null set minimum_adjacency_list of vertex to empty list set is_in_Q of vertex to true set min_distance of initial vertex to zero add to minimum-heap Q all vertices in graph, keyed by min_distance Initialization inputs: A graph, a function returning edge weights weight-function, and an initial vertex Initial placement of all vertices in the 'not yet seen' set, set initial vertex to be added to the tree, and place all vertices in a min-heap to allow for removal of the min distance from the minimum graph. Wikipedia

22 Prim's algorithm while latest_addition = remove minimum in Q set is_in_Q of latest_addition to false add latest_addition to (minimum_adjacency_list of (parent of latest_addition)) add (parent of latest_addition) to (minimum_adjacency_list of latest_addition) for each adjacent of latest_addition if ((is_in_Q of adjacent){ and (weight-function(latest_addition, adjacent) < min_distance of adjacent)) set parent of adjacent to latest_addition set min_distance of adjacent to weight-function(latest_addition, adjacent) } update adjacent in Q, order by min_distance Wikipedia The while loop will fail when remove minimum returns null. The adjacency list is set to allow a directional graph to be returned. time complexity: V for loop, log(V) for the remove function time complexity: E/V, the average number of vertices time complexity: log(V), the height of the heap

23 Grow the minimum spanning tree from the root vertex r. Q is a priority queue, holding all vertices that are not in the tree now. key[v] is the minimum weight of any edge connecting v to a vertex in the tree. parent[v] names the parent of v in the tree. When the algorithm terminates, Q is empty; the minimum spanning tree A for G is thus A={(v,parent[v]):v ∈ V-{r}}. Running time: O(||E||lg |V|). Prim's algorithm

24 Prim's algorithm

25 Prim's algorithm

26 Prim's algorithm

27 Prim's algorithm

28 Prim's algorithm

29 Prim's algorithm

30 Prim's algorithm

31 Prim's algorithm

32 Prim's algorithm

33 Prim's algorithm

34 Prim's algorithm

35 Prim's algorithm

36 Prim's algorithm

37 Prim's algorithm

38 Prim's algorithm

39 Prim's algorithm

40 Prim's algorithm

41 Prim's algorithm