1 / 27

Minimum Spanning Trees

Minimum Spanning Trees. Section 8.3. Definition. For a undirected graph G=(V,E), a spanning tree T is a sub-graph that is a tree covering all vertices in V. In an undirected weighted, a Minimum Spanning Tree (MST) is the spanning tree with the min sum of weights.

wilmer
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 Section 8.3

  2. Definition • For a undirected graph G=(V,E), a spanning tree T is a sub-graph that is a tree covering all vertices in V. • In an undirected weighted, a Minimum Spanning Tree (MST) is the spanning tree with the min sum of weights. • We shall assume that |V|=n and G is connected. • Note that MST may not be unique • And there is n-1 vertices in MST.

  3. Problem • Given a weighted undirected graph, find a MST. • Solution • Kruskal’s Algorithm • Prim’s Algorithm

  4. Kruskal’s Algorithm • Sort the edges non-decreasingly • add the edge with the min weight to the tree if it doesn’t make a cycle, otherwise skip it. • Repeat • Note:We can’t just take the first n-1 edges with the min weights. Choose as long as it’s a tree.

  5. Kruskal’s Algorithm Input: weighted connected undirected G=(V,E) Output: MST T • Sort the edges in E non-decreasingly • For each vertex v V makeset({v}) End for • T  { } • While (|T| < n-1) • let (x,y) be the next edge in E • if find(x)  find(y) then • add(x,y) to T • union(x,y) • end if • End while

  6. Analysis • Running Time= (m log n) • Because we need (m log m) for sorting the edges and (m log* n) for the find union operations

  7. Example 7 2 4 1 3 5 4 2 6 1 7 1 3 2 3 5 4

  8. Prim’s Algorithm • Divide V into disjoint X & Y • Find xX and yY such that (x,y) has the min weight among all such pairs • Add the edge to the tree and move y to X • Repeat

  9. Prim’s Algorithm Input: weighted connected undirected G=(V,E) Output: MST T T  { }; X  {1 }; Y  V - {1 }; While Y  { } let (x,y) be the edge of min weight such that xX & yY X  {y }  X; Y  Y - {y }; T  T  {(x,y)} End while

  10. More Details X Y • N[y] is closest vertex adjacent to y in X • C[y]=c[N[y],y] cost of incident edge of y y C[y] N[y]

  11. Prim’s Algorithm Input: weighted connected undirected G=(V,E) Output: MST T T  { }; X  {1 }; Y  V - {1 }; For y  2 to n if y adjacent to 1 then N[y]  1; C[y] c[1,y] else C[y]   end if End for For j  1 to n-1 let yY be s.t. C[y] is min T  T  {y, N[y] }; X  X  {y }; Y  Y - {y }; for each vertex w Y if c[y,w]  C[w] then N[w]  y; C[w] c[y,w] end if end for End for

  12. Analysis • Running Time = (m+ n2) • But can be improved by using the min-heap to find min C[y]. • Improved running time = (m log n) which is good if m=o(n2/log n)

  13. Example 7 2 4 1 3 5 4 2 6 1 7 1 3 2 3 5 4

  14. Example 7 2 4 1 3 5 4 2 6 1 7 1 3 2 3 5 4

  15. Example 7 2 4 1 3 5 4 2 6 1 7 1 3 2 3 5 4

  16. Example 7 2 4 1 3 5 4 2 6 1 7 1 3 2 3 5 4

  17. Example 7 2 4 1 3 5 4 2 6 1 7 1 3 2 3 5 4

  18. Example 7 2 4 1 3 5 4 2 6 1 7 1 3 2 3 5 4

  19. Example 7 2 4 1 3 5 4 2 6 1 7 1 3 2 3 5 4

  20. Example 7 2 4 1 3 5 4 2 6 1 7 1 3 2 3 5 4

  21. Example 7 2 4 1 3 5 4 2 6 1 7 1 3 2 3 5 4

  22. Example 7 2 4 1 3 5 4 2 6 1 7 1 3 2 3 5 4

  23. Example 7 2 4 1 3 5 4 2 6 1 7 1 3 2 3 5 4

  24. Example 7 2 4 1 3 5 4 2 6 1 7 1 3 2 3 5 4

  25. Example 7 2 4 1 3 5 4 2 6 1 7 1 3 2 3 5 4

  26. Example 7 2 4 1 3 5 4 2 6 1 7 1 3 2 3 5 4

  27. Example 7 2 4 1 3 5 4 2 6 1 7 1 3 2 3 5 4

More Related