![Page 1: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/1.jpg)
Minimum Spanning Trees
![Page 2: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/2.jpg)
a
b
d
f g
e
c
![Page 3: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/3.jpg)
a
b
d
f g
e
c
![Page 4: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/4.jpg)
a
b
d
f g
e
c
![Page 5: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/5.jpg)
a
b
d
f g
e
c
0
2
-3
-1
5
5
7
0
5
-1
8
0
![Page 6: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/6.jpg)
a
b
d
f g
e
c
0
2
-3
-1
5
5
7
0
5
-1
8
0
Minimum spanning tree weight = 0
![Page 7: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/7.jpg)
Systematic Approach:
-Grow a spanning tree A
-Always add a safe edge to A that we know belongs to some minimal spanning tree
![Page 8: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/8.jpg)
a
b
d
f g
e
c
0
2
-3
-1
5
5
7
0
5
-1
8
0
R
![Page 9: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/9.jpg)
a
b
d
f g
e
c
0
2
-3
-1
5
5
7
0
5
-1
8
0
R
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?
![Page 10: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/10.jpg)
a
b
d
f g
e
c
0
2
-3
-1
5
5
7
0
5
-1
8
0
R
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 !!
![Page 11: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/11.jpg)
a
b
d
f g
e
c
0
2
-3
-1
5
5
7
0
5
-1
8
0
R’
![Page 12: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/12.jpg)
a
b
d
f g
e
c
0
2
-3
-1
5
5
7
0
5
-1
8
0
R’
![Page 13: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/13.jpg)
a
b
d
f g
e
c
0
2
-3
-1
5
5
7
0
5
-1
8
0
R’
![Page 14: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/14.jpg)
a
b
d
f g
e
c
0
2
-3
-1
5
5
7
0
5
-1
8
0
R’
![Page 15: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/15.jpg)
a
b
d
f g
e
c
0
2
-3
-1
5
5
7
0
5
-1
8
0
R’
![Page 16: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/16.jpg)
a
b
d
f g
e
c
0
2
-3
-1
5
5
7
0
5
-1
8
0
R’
![Page 17: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/17.jpg)
a
b
d
f g
e
c
0
2
-3
-1
5
5
7
0
5
-1
8
0
R’
![Page 18: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/18.jpg)
a
b
d
f g
e
c
0
2
-3
-1
5
5
7
0
5
-1
8
0
R’
![Page 19: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/19.jpg)
a
b
d
f g
e
c
0
2
-3
-1
5
5
7
0
5
-1
8
0
R’’
![Page 20: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/20.jpg)
a
b
d
f g
e
c
0
2
-3
-1
5
5
7
0
5
-1
8
0
R’’
![Page 21: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/21.jpg)
a
b
d
f g
e
c
0
2
-3
-1
5
5
7
0
5
-1
8
0
R’’’
![Page 22: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/22.jpg)
Kruskal’s Algorithm
![Page 23: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/23.jpg)
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.
![Page 24: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/24.jpg)
a
b
d
f g
e
c
0
2
-3
-1
5
5
7
0
5
-1
8
0
![Page 25: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/25.jpg)
a
b
d
f g
e
c
0
2
-3
-1
5
5
7
0
5
-1
8
0
![Page 26: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/26.jpg)
a
b
d
f g
e
c
0
2
-3
-1
5
5
7
0
5
-1
8
0
![Page 27: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/27.jpg)
a
b
d
f g
e
c
0
2
-3
-1
5
5
7
0
5
-1
8
0
![Page 28: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/28.jpg)
a
b
d
f g
e
c
0
2
-3
-1
5
5
7
0
5
-1
8
0
![Page 29: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/29.jpg)
a
b
d
f g
e
c
0
2
-3
-1
5
5
7
0
5
-1
8
0
![Page 30: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/30.jpg)
a
b
d
f g
e
c
0
2
-3
-1
5
5
7
0
5
-1
8
0
![Page 31: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/31.jpg)
a
b
d
f g
e
c
0
2
-3
-1
5
5
7
0
5
-1
8
0
![Page 32: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/32.jpg)
a
b
d
f g
e
c
0
2
-3
-1
5
5
7
0
5
-1
8
0
R’’’
![Page 33: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/33.jpg)
MSTkruskal(G,w)
1 A Ø
2 for each vertex v V[G]
3 do MakeSet(v)
4 sort the edges of E into nondecreasing order by weight w
5 for each edge (u,v) E, taken in nondecreasing order by weight
6 do if FindSet(u) FindSet(v)
7 then A A {(u,v)}
8 Union(u,v)
9 return A
![Page 34: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/34.jpg)
MSTkruskal(G,w)
1 A Ø
2 for each vertex v V[G]
3 do MakeSet(v)
4 sort the edges of E into nondecreasing order by weight w
5 for each edge (u,v) E, taken in nondecreasing order by weight
6 do if FindSet(u) FindSet(v)
7 then A A {(u,v)}
8 Union(u,v)
9 return A
Time?
![Page 35: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/35.jpg)
MSTkruskal(G,w)
1 A Ø
2 for each vertex v V[G]
3 do MakeSet(v)
4 sort the edges of E into nondecreasing order by weight w
5 for each edge (u,v) E, taken in nondecreasing order by weight
6 do if FindSet(u) FindSet(v)
7 then A A {(u,v)}
8 Union(u,v)
9 return A
Time?
O(E*lgE)
![Page 36: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/36.jpg)
MSTkruskal(G,w)
1 A Ø
2 for each vertex v V[G]
3 do MakeSet(v)
4 sort the edges of E into nondecreasing order by weight w
5 for each edge (u,v) E, taken in nondecreasing order by weight
6 do if FindSet(u) FindSet(v)
7 then A A {(u,v)}
8 Union(u,v)
9 return A
Time?
O(E*lgE)
Theorem 21.13: m FindSet, Union, and MakeSet operations of which n are MakeSet operations takes O(m*α(n))
![Page 37: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/37.jpg)
MSTkruskal(G,w)
1 A Ø
2 for each vertex v V[G]
3 do MakeSet(v)
4 sort the edges of E into nondecreasing order by weight w
5 for each edge (u,v) E, taken in nondecreasing order by weight
6 do if FindSet(u) FindSet(v)
7 then A A {(u,v)}
8 Union(u,v)
9 return A
Time?
O(E*lg(E))
O(V+E*α(V)) =O(V+E*lg(V)) = O(V+E*lg(E)) =O(E*lg(E))
![Page 38: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/38.jpg)
MSTkruskal(G,w)
1 A Ø
2 for each vertex v V[G]
3 do MakeSet(v)
4 sort the edges of E into nondecreasing order by weight w
5 for each edge (u,v) E, taken in nondecreasing order by weight
6 do if FindSet(u) FindSet(v)
7 then A A {(u,v)}
8 Union(u,v)
9 return A
O(E*lg(E))
O(E*lg(E))
O(V+E*α(V)) =O(V+E*lg(V)) = O(V+E*lg(E)) =O(E*lg(E))
![Page 39: Minimum Spanning Trees. a b d f g e c a b d f g e c](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649d805503460f94a64087/html5/thumbnails/39.jpg)
a
b
d
f g
e
c
0
2
-3
-1
5
5
7
1
5
-1
8
0
R
Obviously tree. Which edge should we choose?