1 / 39

Minimum Spanning Trees

Minimum Spanning Trees. c. b. a. d. e. g. f. c. b. a. d. e. g. f. c. b. a. d. e. g. f. c. 5. b. -1. 2. 7. 5. a. d. 0. e. 8. 0. 5. -3. 0. -1. g. f. c. 5. b. -1. 2. 7. 5. a. d. 0. e. 8. 0. 5. -3. 0. -1. g. f.

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

  2. c b a d e g f

  3. c b a d e g f

  4. c b a d e g f

  5. c 5 b -1 2 7 5 a d 0 e 8 0 5 -3 0 -1 g f

  6. c 5 b -1 2 7 5 a d 0 e 8 0 5 -3 0 -1 g f Minimum spanning tree weight = 0

  7. Systematic Approach: -Grow a spanning tree A -Always add a safe edgeto A that we know belongs to some minimal spanning tree

  8. c 5 R b -1 2 7 5 a d 0 e 8 0 5 -3 0 -1 g f

  9. c 5 R b -1 2 7 5 a d 0 e 8 0 5 -3 0 -1 g f There must go exactly one edge from b to the minimum spanning tree.Which edge should we choose?Are all three a possibility (maybe suboptimal)?Could the 7 edge be optimal to choose?What about the two 5 edges?

  10. c 5 R b -1 2 7 5 a d 0 e 8 0 5 -3 0 -1 g f There must go exactly one edge from b to the spanning tree.Which edge should we choose?Are all three a possibility? Yes, every vertex will connect to the tree Could the 7 edge be optimal to choose? No, we must connect with a light edgeWhat about the two 5 edges? The red is possible, but they both are !!

  11. c 5 R’ b -1 2 7 5 a d 0 e 8 0 5 -3 0 -1 g f

  12. c 5 R’ b -1 2 7 5 a d 0 e 8 0 5 -3 0 -1 g f

  13. c 5 R’ b -1 2 7 5 a d 0 e 8 0 5 -3 0 -1 g f

  14. c 5 R’ b -1 2 7 5 a d 0 e 8 0 5 -3 0 -1 g f

  15. c 5 R’ b -1 2 7 5 a d 0 e 8 0 5 -3 0 -1 g f

  16. c 5 R’ b -1 2 7 5 a d 0 e 8 0 5 -3 0 -1 g f

  17. c 5 R’ b -1 2 7 5 a d 0 e 8 0 5 -3 0 -1 g f

  18. c 5 R’ b -1 2 7 5 a d 0 e 8 0 5 -3 0 -1 g f

  19. c 5 R’’ b -1 2 7 5 a d 0 e 8 0 5 -3 0 -1 g f

  20. c 5 R’’ b -1 2 7 5 a d 0 e 8 0 5 -3 0 -1 g f

  21. c 5 R’’’ b -1 2 7 5 a d 0 e 8 0 5 -3 0 -1 g f

  22. Kruskal’s Algorithm

  23. Idea: Rethink the previous algorithm from vertices to edges-Initially each vertex forms a singleton tree -In each iteration add the lightest edge connecting two trees in the forest.

  24. c 5 b -1 2 7 5 a d 0 e 8 0 5 -3 0 -1 g f

  25. c 5 b -1 2 7 5 a d 0 e 8 0 5 -3 0 -1 g f

  26. c 5 b -1 2 7 5 a d 0 e 8 0 5 -3 0 -1 g f

  27. c 5 b -1 2 7 5 a d 0 e 8 0 5 -3 0 -1 g f

  28. c 5 b -1 2 7 5 a d 0 e 8 0 5 -3 0 -1 g f

  29. c 5 b -1 2 7 5 a d 0 e 8 0 5 -3 0 -1 g f

  30. c 5 b -1 2 7 5 a d 0 e 8 0 5 -3 0 -1 g f

  31. c 5 b -1 2 7 5 a d 0 e 8 0 5 -3 0 -1 g f

  32. c 5 R’’’ b -1 2 7 5 a d 0 e 8 0 5 -3 0 -1 g f

  33. MSTkruskal(G,w) • 1 AØ • for each vertex vV[G] • do MakeSet(v) • sort the edges of E into nondecreasing order by weight w • for each edge (u,v) E, taken in nondecreasing order by weight • doif FindSet(u) FindSet(v) • thenAA {(u,v)} • Union(u,v) • returnA

  34. MSTkruskal(G,w) • 1 AØ • for each vertex vV[G] • do MakeSet(v) • sort the edges of E into nondecreasing order by weight w • for each edge (u,v) E, taken in nondecreasing order by weight • doif FindSet(u) FindSet(v) • thenAA {(u,v)} • Union(u,v) • returnA Time?

  35. MSTkruskal(G,w) • 1 AØ • for each vertex vV[G] • doMakeSet(v) • sort the edges of E into nondecreasing order by weight w • for each edge (u,v) E, taken in nondecreasing order by weight • doifFindSet(u) FindSet(v) • thenAA {(u,v)} • Union(u,v) • returnA O(E*lgE) Time?

  36. MSTkruskal(G,w) • 1 AØ • for each vertex vV[G] • doMakeSet(v) • sort the edges of E into nondecreasing order by weight w • for each edge (u,v) E, taken in nondecreasing order by weight • doifFindSet(u) FindSet(v) • thenAA {(u,v)} • Union(u,v) • returnA O(E*lgE) Theorem 21.13: m FindSet, Union, and MakeSet operations of which n are MakeSet operations takes O(m*α(n)) Time?

  37. MSTkruskal(G,w) • 1 AØ • for each vertex vV[G] • doMakeSet(v) • sort the edges of E into nondecreasing order by weight w • for each edge (u,v) E, taken in nondecreasing order by weight • doifFindSet(u) FindSet(v) • thenAA {(u,v)} • Union(u,v) • returnA O(E*lg(E)) O(V+E*α(V)) =O(V+E*lg(V)) = O(V+E*lg(E)) =O(E*lg(E)) Time?

  38. MSTkruskal(G,w) • 1 AØ • for each vertex vV[G] • doMakeSet(v) • sort the edges of E into nondecreasing order by weight w • for each edge (u,v) E, taken in nondecreasing order by weight • doifFindSet(u) FindSet(v) • thenAA {(u,v)} • Union(u,v) • returnA O(E*lg(E)) O(V+E*α(V)) =O(V+E*lg(V)) = O(V+E*lg(E)) =O(E*lg(E)) O(E*lg(E))

  39. c 5 R b -1 2 7 5 a d 1 e 8 0 5 -3 0 -1 g f Obviously tree. Which edge should we choose?

More Related