1 / 41

Minimum Spanning Trees

Minimum Spanning Trees. Text Read Weiss, § 9.5 Prim’s Algorithm Weiss §9.5.1 Similar to Dijkstra’s Algorithm Kruskal’s Algorithm Weiss §9.5.2 Focuses on edges, rather than nodes. Definition.

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 Text • Read Weiss, §9.5 Prim’s Algorithm • Weiss §9.5.1 • Similar to Dijkstra’s Algorithm Kruskal’s Algorithm • Weiss §9.5.2 • Focuses on edges, rather than nodes

  2. Definition • A Minimum Spanning Tree (MST) is a subgraph of an undirected graph such that the subgraph spans (includes) all nodes, is connected, is acyclic, and has minimum total edge weight

  3. Algorithm Characteristics • Both Prim’s and Kruskal’s Algorithms work with undirected graphs • Both work with weighted and unweighted graphs but are more interesting when edges are weighted • Both are greedy algorithms that produce optimal solutions

  4. Prim’s Algorithm • Similar to Dijkstra’s Algorithm except that dv records edge weights, not path lengths

  5. Walk-Through 2 Initialize array 3 F C 10 A 7 3 4 8 18 4 B D 9 10 H 25 2 3 G E 7

  6. 2 Start with any node, say D 3 F C 10 A 7 3 4 8 18 4 B D 9 10 H 25 2 3 G E 7

  7. Update distances of adjacent, unselected nodes 2 3 F C 10 A 7 3 4 8 18 4 B D 9 10 H 25 2 3 G E 7

  8. Select node with minimum distance 2 3 F C 10 A 7 3 4 8 18 4 B D 9 10 H 25 2 3 G E 7

  9. Update distances of adjacent, unselected nodes 2 3 F C 10 A 7 3 4 8 18 4 B D 9 10 H 25 2 3 G E 7

  10. Select node with minimum distance 2 3 F C 10 A 7 3 4 8 18 4 B D 9 10 H 25 2 3 G E 7

  11. Update distances of adjacent, unselected nodes 2 3 F C 10 A 7 3 4 8 18 4 B D 9 10 H 25 2 3 G E 7

  12. Select node with minimum distance 2 3 F C 10 A 7 3 4 8 18 4 B D 9 10 H 25 2 3 G E 7

  13. Update distances of adjacent, unselected nodes 2 3 F C 10 A 7 3 4 8 18 4 B D 9 10 H 25 2 3 G E 7

  14. Select node with minimum distance 2 3 F C 10 A 7 3 4 8 18 4 B D 9 10 H 25 2 3 G E 7

  15. Update distances of adjacent, unselected nodes 2 3 F C 10 A 7 3 4 8 18 4 B D 9 10 H 25 2 3 G E 7 Table entries unchanged

  16. Select node with minimum distance 2 3 F C 10 A 7 3 4 8 18 4 B D 9 10 H 25 2 3 G E 7

  17. Update distances of adjacent, unselected nodes 2 3 F C 10 A 7 3 4 8 18 4 B D 9 10 H 25 2 3 G E 7

  18. Select node with minimum distance 2 3 F C 10 A 7 3 4 8 18 4 B D 9 10 H 25 2 3 G E 7

  19. Update distances of adjacent, unselected nodes 2 3 F C 10 A 7 3 4 8 18 4 B D 9 10 H 25 2 3 G E 7 Table entries unchanged

  20. Select node with minimum distance 2 3 F C 10 A 7 3 4 8 18 4 B D 9 10 H 25 2 3 G E 7

  21. Cost of Minimum Spanning Tree =  dv = 21 2 3 F C A 3 4 4 B D H 2 3 G E Done

  22. Kruskal’s Algorithm • Work with edges, rather than nodes • Two steps: • Sort edges by increasing edge weight • Select the first |V| – 1 edges that do not generate a cycle

  23. Walk-Through Consider an undirected, weight graph 3 F C 10 A 4 3 4 8 6 5 B D 4 4 H 1 2 3 G E 3

  24. Sort the edges by increasing edge weight 3 F C 10 A 4 3 4 8 6 5 B D 4 4 H 1 2 3 G E 3

  25. Select first |V|–1 edges which do not generate a cycle 3 F C 10 A 4 3 4 8 6 5 B D 4 4 H 1 2 3 G E 3

  26. Select first |V|–1 edges which do not generate a cycle 3 F C 10 A 4 3 4 8 6 5 B D 4 4 H 1 2 3 G E 3

  27. Select first |V|–1 edges which do not generate a cycle 3 F C 10 A 4 3 4 8 6 5 B D 4 4 H 1 2 3 G E 3 Accepting edge (E,G) would create a cycle

  28. Select first |V|–1 edges which do not generate a cycle 3 F C 10 A 4 3 4 8 6 5 B D 4 4 H 1 2 3 G E 3

  29. Select first |V|–1 edges which do not generate a cycle 3 F C 10 A 4 3 4 8 6 5 B D 4 4 H 1 2 3 G E 3

  30. Select first |V|–1 edges which do not generate a cycle 3 F C 10 A 4 3 4 8 6 5 B D 4 4 H 1 2 3 G E 3

  31. Select first |V|–1 edges which do not generate a cycle 3 F C 10 A 4 3 4 8 6 5 B D 4 4 H 1 2 3 G E 3

  32. Select first |V|–1 edges which do not generate a cycle 3 F C 10 A 4 3 4 8 6 5 B D 4 4 H 1 2 3 G E 3

  33. Select first |V|–1 edges which do not generate a cycle 3 F C 10 A 4 3 4 8 6 5 B D 4 4 H 1 2 3 G E 3

  34. Select first |V|–1 edges which do not generate a cycle 3 F C 10 A 4 3 4 8 6 5 B D 4 4 H 1 2 3 G E 3

  35. Select first |V|–1 edges which do not generate a cycle 3 F C 10 A 4 3 4 8 6 5 B D 4 4 H 1 2 3 G E 3

  36. Select first |V|–1 edges which do not generate a cycle 3 F C A 3 4 5 B D H 1 } 2 3 G E not considered Done Total Cost = dv = 21

  37. Detecting Cycles • Use Disjoint Sets (Chapter 8)

More Related