Explore Minimum Spanning Trees Algorithms

minimum spanning trees n.w
1 / 21
Embed
Share

Discover the concept of Minimum Spanning Trees (MST) in graph theory, focusing on finding the lowest-cost way to connect all points while ensuring the solution forms a tree structure. Learn about greedy algorithms like Kruskal's Algorithm and high-level approaches for constructing MST. Dive into the principles of selecting safe edges and avoiding cycles in MST construction.

  • Spanning Trees
  • Graph Theory
  • Minimum Spanning Trees
  • Greedy Algorithm
  • Kruskal

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Minimum Spanning Trees

  2. b 3 4 f a 5 2 G=(V,E) 1 1 e 5 7 2 c 9 d 3 g h 4 . , , . Minimum Spanning Trees 2

  3. 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 = nn-2.) Minimum Spanning Trees 3

  4. A High-Level Greedy Algorithm for MST A = ; while(T=(V,A) is not a spanning tree of G) { select a safe edge for A ; } 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 ? Minimum Spanning Trees 4

  5. MST Let V = V1 + V2, (V1,V2) = {uv | u V1& v V2}. if xy (V1,V2) and w(xy) = min {w(uv)| uv (V1,V2)}, then xy is contained in a MST. b 3 4 f a 5 2 1 1 e 5 7 2 c 9 d 3 g h 4 V2 V1 Minimum Spanning Trees 5

  6. Kruskals 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 Trees 6

  7. Kruskals Algorithm ( 1/3) b 3 4 f a 5 2 1 1 e 4 7 2 9 c d 3 4 g h Minimum Spanning Trees 7

  8. Kruskals Algorithm ( 2/3) b 3 4 f a 5 2 1 1 e 4 7 2 9 c d 3 4 g h Minimum Spanning Trees 8

  9. Kruskals Algorithm ( 3/3) b 3 4 f a 5 2 1 1 e 4 7 2 9 c d 3 4 g h MST cost = 17 Minimum Spanning Trees 9

  10. Kruskals 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. Minimum Spanning Trees 10

  11. Prims Algorithm (pseudo code 1) ALGORITHM Prim(G) // Input: A weighted connected graph G=(V,E) // Output: A MST T=(V, A) VT { v0} // Any vertex will do; A ; for i 1 to |V| 1 do find an edge xy (VT, V VT) s.t. its weight is minimized among all edges in (VT, V VT); VT VT { y} ; A A { xy} ; Minimum Spanning Trees 11

  12. Prims Algorithm ( 1/8) b 3 4 f a 5 2 1 1 e 4 7 2 9 c d 3 4 g h Minimum Spanning Trees 12

  13. Prims Algorithm ( 2/8) b 3 4 f a 5 2 1 1 e 4 7 2 9 c d 3 4 g h Minimum Spanning Trees 13

  14. Prims Algorithm ( 3/8) b 3 4 f a 5 2 1 1 e 4 7 2 9 c d 3 4 g h Minimum Spanning Trees 14

  15. Prims Algorithm ( 4/8) b 3 4 f a 5 2 1 1 e 4 7 2 9 c d 3 4 g h Minimum Spanning Trees 15

  16. Prims Algorithm ( 5/8) b 3 4 f a 5 2 1 1 e 4 7 2 9 c d 3 4 g h Minimum Spanning Trees 16

  17. Prims Algorithm ( 6/8) b 3 4 f a 5 2 1 1 e 4 7 2 9 c d 3 4 g h Minimum Spanning Trees 17

  18. Prims Algorithm ( 7/8) b 3 4 f a 5 2 1 1 e 4 7 2 9 c d 3 4 g h Minimum Spanning Trees 18

  19. Prims Algorithm ( 8/8) b 3 4 f a 5 2 1 1 e 4 7 2 9 c d 3 4 g h MST cost = 17 Minimum Spanning Trees 19

  20. Prims Algorithm (pseudo code 2) Built a priority queue Q for V with key[u] = u V; key[v0] = 0; [v0] = 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 Trees 20

  21. 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 logm ) = O(m logn ) Running time of Prim s algorithm: adjacency lists + (binary or ordinary) heap: O((m+n) logn ) = O(m logn ) adjacency matrix + unsorted list: O(n2) adjacency lists + Fibonacci heap: O(n logn + m) Minimum Spanning Trees 21

Related


More Related Content