1 / 33

Minimum Spanning Tree

Minimum Spanning Tree. Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008. Minimum Spanning Tree. Example of MST. Problem: Laying Telephone Wire. Central office. Wiring: Naïve Approach. Central office. Expensive!. Wiring: Better Approach. Central office.

jereni
Download Presentation

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 Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008

  2. Minimum Spanning Tree

  3. Example of MST

  4. Problem: Laying Telephone Wire Central office

  5. Wiring: Naïve Approach Central office Expensive!

  6. Wiring: Better Approach Central office Minimize the total length of wire connecting the customers

  7. Growing an MST: general idea • GENERIC-MST(G,w) • A{} • while A does not form a spanning tree • do find an edge (u,v) that is safe for A • A A U {(u,v)} • return A

  8. Tricky part • How do you find a safe edge? • This safe edge is part of the minimum spanning tree

  9. Algorithms for MST • Prim’s • Grow a MST by adding a single edge at a time • Kruskal’s • Choose a smallest edge and add it to the forest • If an edge is formed a cycle, it is rejected

  10. Prim’s greedy algorithm • Start from some (any) vertex. • Build up spanning tree T, one vertex at a time. • At each step, add to T the lowest-weight edge in G that does not create a cycle. • Stop when all vertices in G are touched

  11. Prim’s MST algorithm

  12. Example C 4 1 B F 2 7 3 3 2 E A I 4 6 7 5 H D 9 8 G

  13. = in heap Min EdgePick a root C 4 1 B F 2 7 3 3 2 E A I 4 6 7 5 H D 9 8 G

  14. Min Edge = 1 C 4 1 B F 2 7 3 3 2 E A I 4 6 7 5 H D 9 8 G

  15. Min Edge = 2 C 4 1 B F 2 7 3 3 2 E A I 4 6 7 5 H D 9 8 G

  16. Min Edge = 2 C 4 1 B F 2 7 3 3 2 E A I 4 6 7 5 H D 9 8 G

  17. Min Edge = 3 C 4 1 B F 2 7 3 3 2 E A I 4 6 7 5 H D 9 8 G

  18. Min Edge = 4 C 4 1 B F 2 7 3 3 2 E A I 4 6 7 5 H D 9 8 G

  19. Min Edge = 3 C 4 1 B F 2 7 3 3 2 E A I 4 6 7 5 H D 9 8 G

  20. Min Edge = 4 C 4 1 B F 2 7 3 3 2 E A I 4 6 7 5 H D 9 8 G

  21. Min Edge = 6 C 4 1 B F 2 7 3 3 2 E A I 4 6 7 5 H D 9 8 G

  22. Example II

  23. Kruskal’s Algorithm • Choose the smallest edge and add it to a forest • Keep connecting components until all vertices connected • If an edge would form a cycle, it is rejected.

  24. Example C 4 1 B F 2 7 3 3 2 E A I 4 6 7 5 H D 9 8 G

  25. Min Edge = 1 C 4 1 B F 2 7 3 3 2 E A I 4 6 7 5 H D 9 8 G

  26. Min Edge = 2 C 4 1 B F 2 7 3 3 2 E A I 4 6 7 5 H D 9 8 G

  27. Min Edge = 2 C 4 1 B F 2 7 3 3 2 E A I 4 6 7 5 H D 9 8 G

  28. Min Edge = 3 C 4 1 B F 2 7 3 3 2 E A I 4 6 7 5 H D Now have 2 disjoint components: ABFG and CH 9 8 G

  29. Min Edge = 3 C 4 1 B F 2 7 3 3 2 E A I 4 6 7 5 H D 9 8 G

  30. Min Edge = 4 C 4 1 B F 2 7 3 3 2 E A I 4 6 7 5 H D Two components now merged into one. 9 8 G

  31. Min Edge = 4 C 4 1 B F 2 7 3 3 2 E A I 4 6 7 5 H D 9 8 G

  32. Min Edge = 5 C 4 1 B F Rejected due to a cycle BFGB 2 7 3 3 2 E A I 4 6 7 5 H D 9 8 G

  33. Min Edge = 6 C 4 1 B F 2 7 3 3 2 E A I 4 6 7 5 H D 9 8 G

More Related