1 / 25

Minimum Spanning Trees

Minimum Spanning Trees. Minimum Spanning Trees. Create a Tree that connect all vertices If is weight between u and v , then: Our job: minimize w ( T ) We can use a greedy approach. General Proof for MSTs. General idea for loop invariant:

bruis
Download Presentation

Minimum Spanning Trees

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 Trees Jeff Chastine

  2. Minimum Spanning Trees • Create a Tree that connect all vertices • If is weight between u and v, then: • Our job: minimize w(T) • We can use a greedy approach Jeff Chastine

  3. General Proof for MSTs • General idea for loop invariant: • “Prior to each iteration, A is a subset of a MST” • Do this by finding safe edges that don’t violate this property • Other terms • A cut is a partitioning of V • A crossing edge crosses a cut • A light edge is a minimally weighted edge crossing the cut Jeff Chastine

  4. A Tale of Two Algorithms • Pretty simple… • Kruskal’s: forms a forest • Prim’s: forms a single tree • Both: • Sort edges by weight • Add edges by increasing order if connects a new vertex Jeff Chastine

  5. 8 7 b c d 4 9 2 Kruskal’s 11 a i 4 14 e 7 6 10 8 h g f 1 2 8 7 b c d 4 9 2 11 a i 4 14 e Prim’s 7 6 10 8 h g f 1 2 Jeff Chastine

  6. 8 7 b c d 4 9 2 Kruskal’s 11 a i 4 14 e 7 6 10 8 h g f 1 2 8 7 b c d 4 9 2 11 a i 4 14 e Prim’s 7 6 10 8 h g f 1 2 Jeff Chastine

  7. 8 7 b c d 4 9 2 Kruskal’s 11 a i 4 14 e 7 6 10 8 h g f 1 2 8 7 b c d 4 9 2 11 a i 4 14 e Prim’s 7 6 10 8 h g f 1 2 Jeff Chastine

  8. 8 7 b c d 4 9 2 Kruskal’s 11 a i 4 14 e 7 6 10 8 h g f 1 2 8 7 b c d 4 9 2 11 a i 4 14 e Prim’s 7 6 10 8 h g f 1 2 Jeff Chastine

  9. 8 7 b c d 4 9 2 Kruskal’s 11 a i 4 14 e 7 6 10 8 h g f 1 2 8 7 b c d 4 9 2 11 a i 4 14 e Prim’s 7 6 10 8 h g f 1 2 Jeff Chastine

  10. 8 7 b c d 4 9 2 Kruskal’s 11 a i 4 14 e 7 6 10 8 h g f 1 2 8 7 b c d 4 9 2 11 a i 4 14 e Prim’s 7 6 10 8 h g f 1 2 Jeff Chastine

  11. 8 7 b c d 4 9 2 Kruskal’s 11 a i 4 14 e 7 6 10 8 h g f 1 2 8 7 b c d 4 9 2 11 a i 4 14 e Prim’s 7 6 10 8 h g f 1 2 Jeff Chastine

  12. 8 7 b c d 4 9 2 Kruskal’s 11 a i 4 14 e 7 6 10 8 h g f 1 2 8 7 b c d 4 9 2 11 a i 4 14 e Prim’s 7 6 10 8 h g f 1 2 Jeff Chastine

  13. 8 7 b c d 4 9 2 Kruskal’s 11 a i 4 14 e 7 6 10 8 h g f 1 2 8 7 b c d 4 9 2 11 a i 4 14 e Prim’s 7 6 10 8 h g f 1 2 Jeff Chastine

  14. 8 7 b c d 4 9 2 Kruskal’s 11 a i 4 14 e 7 6 10 8 h g f 1 2 8 7 b c d 4 9 2 11 a i 4 14 e Prim’s 7 6 10 8 h g f 1 2 Jeff Chastine

  15. 8 7 b c d 4 9 2 Kruskal’s 11 a i 4 14 e 7 6 10 8 h g f 1 2 8 7 b c d 4 9 2 11 a i 4 14 e Prim’s 7 6 10 8 h g f 1 2 Jeff Chastine

  16. 8 7 b c d 4 9 2 Kruskal’s 11 a i 4 14 e 7 6 10 8 h g f 1 2 8 7 b c d 4 9 2 11 a i 4 14 e Prim’s 7 6 10 8 h g f 1 2 Jeff Chastine

  17. 8 7 b c d 4 9 2 Kruskal’s 11 a i 4 14 e 7 6 10 8 h g f 1 2 8 7 b c d 4 9 2 11 a i 4 14 e Prim’s 7 6 10 8 h g f 1 2 Jeff Chastine

  18. 8 7 b c d 4 9 2 Kruskal’s 11 a i 4 14 e 7 6 10 8 h g f 1 2 8 7 b c d 4 9 2 11 a i 4 14 e Prim’s 7 6 10 8 h g f 1 2 Jeff Chastine

  19. 8 7 b c d 4 9 2 Kruskal’s 11 a i 4 14 e 7 6 10 8 h g f 1 2 8 7 b c d 4 9 2 11 a i 4 14 e Prim’s 7 6 10 8 h g f 1 2 Jeff Chastine

  20. 8 7 b c d 4 9 2 Kruskal’s 11 a i 4 14 e 7 6 10 8 h g f 1 2 8 7 b c d 4 9 2 11 a i 4 14 e Prim’s 7 6 10 8 h g f 1 2 Jeff Chastine

  21. 8 7 b c d 4 9 2 Kruskal’s 11 a i 4 14 e 7 6 10 8 h g f 1 2 8 7 b c d 4 9 2 11 a i 4 14 e Prim’s 7 6 10 8 h g f 1 2 Jeff Chastine

  22. 8 7 b c d 4 9 2 Kruskal’s 11 a i 4 14 e 7 6 10 8 h g f 1 2 8 7 b c d 4 9 2 11 a i 4 14 e Prim’s 7 6 10 8 h g f 1 2 Jeff Chastine

  23. 8 7 b c d 4 9 2 Kruskal’s 11 a i 4 14 e 7 6 10 8 h g f 1 2 Note: the algorithms still run on the remaining edges! 8 7 b c d 4 9 2 11 a i 4 14 e Prim’s 7 6 10 8 h g f 1 2 Jeff Chastine

  24. 7 b c d 4 9 2 Kruskal’s a i 4 e 8 h g f 1 2 Why do we get different shapes? 8 7 b c d 4 9 2 a i 4 e Prim’s h g f 1 2 Jeff Chastine

  25. Summary • Minimum Spanning Trees • Calculate smallest weighted tree to connect all vertices • Use greedy algorithms • Prim’s algorithm (single tree) • Kruskal’s algorithm (forest) • Must sort the edges Jeff Chastine

More Related