0
Upcoming SlideShare
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Standard text messaging rates apply

# Mst(engl)

230

Published on

Published in: Technology, Sports
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total Views
230
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
15
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Transcript

• 1. Minimum- Spanning Trees1. Concrete example: computer connection2. Definition of a Minimum- Spanning Tree3. The Crucial Fact about Minimum- Spanning Trees4. Algorithms to find Minimum- Spanning Trees - Kruskal‘s Algorithm - Prim‘s Algorithm - Barůvka‘s Algorithm Minimum-Spanning Trees
• 2. Concrete exampleImagine: You wish to connect all the computers in an office building using the least amount of cable a weighted graph problem !!- Each vertex in a graph G represents a computer- Each edge represents the amount of cable needed to connect all computers Minimum-Spanning Trees
• 3. We are interested in:Finding a tree T that contains all the verticesof a graph G spanning treeand has the least total weight over allsuch trees minimum-spanning tree (MST) w(T ) = ∑ w((v, u )) ( v ,u )∈T Minimum-Spanning Tree
• 4. The Crucial Fact about MST e V 1 min-weight V 2 “bridge“ edge Crucial Fact
• 5. The Crucial Fact about MST - The basis of the following algorithmsProposition: Let G = (V,E) be a weighted graph, and let V1 and V2 be two disjoint nonempty sets such that V = V1 ∪ V2 . Furthermore, let e be an edge with minimum weight from among those with one vertex in V1 and the other in V2 . There is a minimum- spanning tree T that has e as one of its edges. Crucial Fact
• 6. The Crucial Fact about MST - The basis of the following algorithmsJustification: There is no minimum- spanning tree that has e as one of of ist edges. The addition of e must create a cycle. There exists an edge f (one endpoint in V1 the other V2in ). w(e) ≤ w( f ) T ∪ {e} Choose: . By removing f from ,a spanning tree is created, whose total weight is no more than before. A new MSTcontaining e Contradiction!!! Crucial Fact There is a MST containing e after all!!!
• 7. MST-AlgorithmsInput: A weighted connected graph G = (V,E) with n vertices and m edgesOutput: A minimum- spanning tree T w(T ) = ∑ w((v, u)) ( v ,u )∈T MST-Algorithms
• 8. Kruskal‘s Algorithm1. Each vertex is in its own cluster2. Take the edge e with the smallest weight - if e connects two vertices in different clusters, then e is added to the MST and the two clusters, which are connected by e, are merged into a single cluster - if e connects two vertices, which are already in the same cluster, ignore it3. Continue until n-1 edges were selected Kruskals Algorithm
• 9. 5 A B 4 6 2 2 D 3C 3 1 2 E F 4 Kruskals Algorithm
• 10. 5 A B 4 6 2 2 D 3C 3 1 2 E F 4 Kruskals Algorithm
• 11. 5 A B 4 6 2 2 D 3C 3 1 2 E F 4 Kruskals Algorithm
• 12. 5 A B 4 6 2 2 D 3C 3 1 2 E F 4 Kruskals Algorithm
• 13. 5 A B 4 6 2 2 D 3C 3 1 2 E F 4 Kruskals Algorithm
• 14. 5 A B 4 6 2 2 D 3 cycle!!C 3 1 2 E F 4 Kruskals Algorithm
• 15. 5 A B 4 6 2 2 D 3C 3 1 2 E F 4 Kruskals Algorithm
• 16. 5 A B 4 6 2 2 D 3C 3 1 2 E F 4 Kruskals Algorithm
• 17. minimum- spanning tree A B 2 2 DC 3 1 2 E F Kruskals Algorithm
• 18. The correctness of Kruskal‘s Algorithm Crucial Fact about MSTsRunning time: O ( m log n )By implementing queue Q as a heap, Q could be initialized in O ( m )time and a vertex could be extracted in each iteration in O ( log n ) time Kruskals Algorithm
• 19. Code Fragment Input: A weighted connected graph G with n vertices and m edges Output: A minimum-spanning tree T for Gfor each vertex v in G do Define a cluster C(v) ← {v}.Initialize a priority queue Q to contain all edges in G, using weights as keys.T←∅while Q ≠ ∅ do Extract (and remove) from Q an edge (v,u) with smallest weight. Let C(v) be the cluster containing v, and let C(u) be the cluster containing u. if C(v) ≠ C(u) then Add edge (v,u) to T. Merge C(v) and C(u) into one cluster, that is, union C(v) and C(u).return tree T Kruskals Algorithm
• 20. Prim‘s Algorithm1. All vertices are marked as not visited2. Any vertex v you like is chosen as starting vertex and is marked as visited (define a cluster C)• The smallest- weighted edge e = (v,u), which connects one vertex v inside the cluster C with another vertex u outside of C, is chosen and is added to the MST.4. The process is repeated until a spanning tree is formed Prims Algorithm
• 21. 5 A B 4 6 2 2 D 3C 3 1 2 E F 4 Prims Algorithm
• 22. 5 A B 4 6 2 2 D 3C 3 1 2 E F 4 Prims Algorithm
• 23. We could delete these edges because ofDijkstra‘s label D[u] for each vertexoutside of the cluster 5 A B 4 6 2 2 D 3 C 3 1 2 E F 4 Prims Algorithm
• 24. A B 2 2 D 3C 3 1 2 E F 4 Prims Algorithm
• 25. A B 2 2 D 3C 3 1 2 E F Prims Algorithm
• 26. A B 2 2 D 3C 3 1 2 E F Prims Algorithm
• 27. A B 2 2 DC 3 1 2 E F Prims Algorithm
• 28. A B 2 2 DC 3 1 2 E F Prims Algorithm
• 29. minimum- spanning tree A B 2 2 D C 3 1 2 E F Prims Algorithm
• 30. The correctness of Prim‘s Algorithm Crucial Fact about MSTsRunning time: O ( m log n )By implementing queue Q as a heap, Q could be initialized in O ( m )time and a vertex could be extracted in each iteration in O ( log n ) time Prims Algorithm
• 31. Barůvka‘s Algorithm1. For all vertices search the edge with the smallest weight of this vertex and mark these edges4. Search connected vertices (clusters) and replace them by a “new“ vertex Ci (cluster)7. Remove the cycles and, if two vertices are connected by more than one edge, delete all edges except the “cheapest“ Baruvkas Algorithm
• 32. 5 A B 4 6 2 2 D 3C 3 1 2 E F 4 Baruvkas Algorithm
• 33. 5 A B 4 6 2 2 D 3C 3 1 2 E F 4 Baruvkas Algorithm
• 34. 5 A B 4 6 2 Ci 2 D 3C 3 1 2 E F 4 Baruvkas Algorithm
• 35. 5 A B 4 6 2 2 D 3C 3 1 2 E F 4 Baruvkas Algorithm
• 36. A B 2 2 DC 3 1 2 E F Baruvkas Algorithm
• 37. minimum- spanning tree A B 2 2 DC 3 1 2 E F Baruvkas Algorithm
• 38. The correctness of Barůvka‘s Algorithm Crucial Fact about MSTs Running time: O ( m log n ) The number of edges is at least reduced by half in each step. Number of steps: O ( log n ) Baruvkas Algorithm
• 39. ComparisonKruskal‘s, Prim‘s, and Borůvka‘s algorithm Comparison
• 40. ComparisonAlthough each of the above algorithms has the same worth-caserunning time, each one achieves this running time using different datastructures and different approaches to build the MST. there is no clear winner among these three algorithms Comparison