1 / 32

Minimum Spanning Tree

Minimum Spanning Tree. Graph Theory Basics. - Anil Kishore. Definition. A spanning graph is a sub-graph that contains all the vertices of the graph If a spanning sub-graph is connected and has no cycles, its a tree, a spanning tree. 2. 5. 2. 5. 1. 1. 4. 4. 6. 6. 3. 3. MST.

Télécharger la présentation

Minimum Spanning Tree

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Minimum Spanning Tree Graph Theory Basics - Anil Kishore

  2. Definition • A spanning graph is a sub-graph that containsall the vertices of the graph • If a spanning sub-graph is connected and has no cycles, its a tree, a spanning tree 2 5 2 5 1 1 4 4 6 6 3 3

  3. MST • A graph can have many Spanning Trees • Given a weighted ( edge weights ) graph, our goal is to find a spanning tree with minimum sum of edge weights in it, Minimum Spanning Tree (MST) 3 3 B E B E 2 2 1 4 1 4 A 7 A 7 D D F 5 F 5 10 10 C C

  4. Simple application • Government is planning to connect cities by roads and has estimated the cost of construction of roads between some pairs of cities • Find the minimum cost to construct roads such that any city is reachable from any other city

  5. Prim’s Algorithm Algorithm Prim(G) Initialize an empty priority queue Q Initialize an empty set S to mark already finished vertices FOR-each u in V f[u] := +infinity Insert u into Q end-for WHILE Q is not empty u := delete minimum element from Q add u to S FOR-each edge e = ( u, v ) if ( v not in S ) and ( w(e) < f[v] ) decrease f[v] to w(e) end-if end-for end-while End-Prim

  6. Running Prim’s Algorithm 3 E B 2 1 4 A 7 D 5 F 10 C

  7. Running Prim’s Algorithm 3 E B 2 1 4 A 0 7 D 5 F 10 C

  8. Running Prim’s Algorithm 2 3 E B 2 1 4 A 0 7 7 D 5 F 10 C

  9. Running Prim’s Algorithm 2 3 E B 2 1 4 A 0 7 7 D 5 F 10 C

  10. Running Prim’s Algorithm 2 3 3 E B 2 1 4 A 0 7 7 D 5 F 10 C

  11. Running Prim’s Algorithm 2 3 3 E B 2 1 4 A 0 7 7 D 5 F 10 C

  12. Running Prim’s Algorithm 2 3 3 E B 2 1 4 A 0 1 7 D 4 5 F 10 C

  13. Running Prim’s Algorithm 2 3 3 E B 2 1 4 A 0 1 7 D 4 5 F 10 C

  14. Running Prim’s Algorithm 2 3 3 E B 2 1 4 A 0 1 7 D 4 5 F 10 10 C

  15. Running Prim’s Algorithm 2 3 3 E B 2 1 4 A 0 1 7 D 4 5 F 10 10 C

  16. Running Prim’s Algorithm 2 3 3 E B 2 1 4 A 0 1 7 D 4 5 F 10 10 C

  17. Running Prim’s Algorithm 3 E B 2 1 4 A 7 D 5 F 10 C MST

  18. Complexity of Prim’s Algorithm • Using an array • O(m) decrease key operations, each O(1) • O(n) min-key operations, each O(n) • O( m + n2 ) • Using a binary heap ( priority queue • O(m) decrease key operations, each O(log n) • O(n) min-key operations, each O(log n) • O( m logn + n logn )

  19. Kruskal’s Algorithm Algorithm Kruskal (G) Sort the edges of G in non-decreasing order of edge weights Initialize an empty tree T FOR-each edge e in sorted order if adding e to T does not for a cycle in T Add e to T end-if end-for End-Kruskal

  20. Running Kruskal’s Algorithm 3 E B 2 1 4 A 7 D 5 F 10 C

  21. Running Kruskal’s Algorithm 3 E B 2 1 4 A 7 D 5 F 10 C

  22. Running Kruskal’s Algorithm 3 E B 2 1 4 A 7 D 5 F 10 C

  23. Running Kruskal’s Algorithm 3 E B 2 1 4 A 7 D 5 F 10 C

  24. Running Kruskal’s Algorithm 3 E B 2 1 4 A 7 D 5 F 10 C

  25. Running Kruskal’s Algorithm 3 E B 2 1 4 A 7 D 5 F 10 C

  26. Running Kruskal’s Algorithm 3 E B 2 1 4 A 7 D 5 F 10 C

  27. Running Kruskal’s Algorithm 3 E B 2 1 4 A 7 D 5 F 10 C

  28. Running Kruskal’s Algorithm 3 E B 2 1 4 A 7 D 5 F 10 C

  29. Running Kruskal’s Algorithm 3 E B 2 1 4 A 7 D 5 F 10 C

  30. Running Kruskal’s Algorithm 3 E B 2 1 4 A 7 D 5 F 10 C MST

  31. Complexity of Kruskal’s Algorithm • Using the union-find data structure • O(m logn) for sorting edges • Simple implementation of union-find : O(log n) to find representative of a set • O(m logn) • Using Path compression of union-find : almost a constant per operation • O( m )

  32. References • Introduction to Algorithms • Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein • http://cgm.cs.mcgill.ca/~avis/courses/251/2012/slides/04mst.pdf • http://ww3.algorithmdesign.net/handouts/MST.pdf - End -

More Related