kruskal mst: initialized the graph and sorted the edges ... · kruskal mst: initialized the graph...
TRANSCRIPT
![Page 1: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red](https://reader036.vdocument.in/reader036/viewer/2022062604/5fb57aca858902562320606b/html5/thumbnails/1.jpg)
Kruskal MST: initialized the graph and sorted the edges.Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K]
Weight of red edges = = 0
F
G
5
H
3
L
3 T
32
J
2
K
710 4
235
M
1
6
8
![Page 2: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red](https://reader036.vdocument.in/reader036/viewer/2022062604/5fb57aca858902562320606b/html5/thumbnails/2.jpg)
Considering edge (L, M)Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K]
Weight of red edges = = 0
F
G
5
H
3
L
3 T
32
J
2
K
710 4
235
M
1
6
8
![Page 3: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red](https://reader036.vdocument.in/reader036/viewer/2022062604/5fb57aca858902562320606b/html5/thumbnails/3.jpg)
Edge (L, M) spans disconnected components: OK.Disjoint sets: [H] [J] [F] [G] [L, M] [T] [K]
Weight of red edges = 1 = 1
F
G
5
H
3
L
3 T
32
J
2
K
710 4
235
M
1
6
8
![Page 4: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red](https://reader036.vdocument.in/reader036/viewer/2022062604/5fb57aca858902562320606b/html5/thumbnails/4.jpg)
Considering edge (H, J)Disjoint sets: [H] [J] [F] [G] [L, M] [T] [K]
Weight of red edges = 1 = 1
F
G
5
H
3
L
3 T
32
J
2
K
710 4
235
M
1
6
8
![Page 5: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red](https://reader036.vdocument.in/reader036/viewer/2022062604/5fb57aca858902562320606b/html5/thumbnails/5.jpg)
Edge (H, J) spans disconnected components: OK.Disjoint sets: [H, J] [F] [G] [L, M] [T] [K]
Weight of red edges = 1 + 2 = 3
F
G
5
H
3
L
3 T
32
J
2
K
710 4
235
M
1
6
8
![Page 6: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red](https://reader036.vdocument.in/reader036/viewer/2022062604/5fb57aca858902562320606b/html5/thumbnails/6.jpg)
Considering edge (F, H)Disjoint sets: [H, J] [F] [G] [L, M] [T] [K]
Weight of red edges = 1 + 2 = 3
F
G
5
H
3
L
3 T
32
J
2
K
710 4
235
M
1
6
8
![Page 7: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red](https://reader036.vdocument.in/reader036/viewer/2022062604/5fb57aca858902562320606b/html5/thumbnails/7.jpg)
Edge (F, H) spans disconnected components: OK.Disjoint sets: [F, H, J] [G] [L, M] [T] [K]Weight of red edges = 1 + 2 + 3 = 6
F
G
5
H
3
L
3 T
32
J
2
K
710 4
235
M
1
6
8
![Page 8: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red](https://reader036.vdocument.in/reader036/viewer/2022062604/5fb57aca858902562320606b/html5/thumbnails/8.jpg)
Considering edge (F, L)Disjoint sets: [F, H, J] [G] [L, M] [T] [K]Weight of red edges = 1 + 2 + 3 = 6
F
G
5
H
3
L
3 T
32
J
2
K
710 4
235
M
1
6
8
![Page 9: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red](https://reader036.vdocument.in/reader036/viewer/2022062604/5fb57aca858902562320606b/html5/thumbnails/9.jpg)
Edge (F, L) spans disconnected components: OK.Disjoint sets: [F, H, J, L, M] [G] [T] [K]
Weight of red edges = 1 + 2 + 3 + 3 = 9
F
G
5
H
3
L
3 T
32
J
2
K
710 4
235
M
1
6
8
![Page 10: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red](https://reader036.vdocument.in/reader036/viewer/2022062604/5fb57aca858902562320606b/html5/thumbnails/10.jpg)
Considering edge (T, J)Disjoint sets: [F, H, J, L, M] [G] [T] [K]
Weight of red edges = 1 + 2 + 3 + 3 = 9
F
G
5
H
3
L
3 T
32
J
2
K
710 4
235
M
1
6
8
![Page 11: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red](https://reader036.vdocument.in/reader036/viewer/2022062604/5fb57aca858902562320606b/html5/thumbnails/11.jpg)
Edge (T, J) spans disconnected components: OK.Disjoint sets: [G] [F, H, J, L, M, T] [K]
Weight of red edges = 1 + 2 + 3 + 3 + 4 = 13
F
G
5
H
3
L
3 T
32
J
2
K
710 4
235
M
1
6
8
![Page 12: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red](https://reader036.vdocument.in/reader036/viewer/2022062604/5fb57aca858902562320606b/html5/thumbnails/12.jpg)
Considering edge (J, L)Disjoint sets: [G] [F, H, J, L, M, T] [K]
Weight of red edges = 1 + 2 + 3 + 3 + 4 = 13
F
G
5
H
3
L
3 T
32
J
2
K
710 4
235
M
1
6
8
![Page 13: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red](https://reader036.vdocument.in/reader036/viewer/2022062604/5fb57aca858902562320606b/html5/thumbnails/13.jpg)
Edge (J, L) would introduce a cycle. Forget it.Disjoint sets: [G] [F, H, J, L, M, T] [K]
Weight of red edges = 1 + 2 + 3 + 3 + 4 = 13
F
G
5
H
3
L
3 T
32
J
2
K
710 4
235
M
1
6
8
![Page 14: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red](https://reader036.vdocument.in/reader036/viewer/2022062604/5fb57aca858902562320606b/html5/thumbnails/14.jpg)
Considering edge (F, G)Disjoint sets: [G] [F, H, J, L, M, T] [K]
Weight of red edges = 1 + 2 + 3 + 3 + 4 = 13
F
G
5
H
3
L
3 T
32
J
2
K
710 4
235
M
1
6
8
![Page 15: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red](https://reader036.vdocument.in/reader036/viewer/2022062604/5fb57aca858902562320606b/html5/thumbnails/15.jpg)
Edge (F, G) spans disconnected components: OK.Disjoint sets: [F, G, H, J, L, M, T] [K]
Weight of red edges = 1 + 2 + 3 + 3 + 4 + 5 = 18
F
G
5
H
3
L
3 T
32
J
2
K
710 4
235
M
1
6
8
![Page 16: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red](https://reader036.vdocument.in/reader036/viewer/2022062604/5fb57aca858902562320606b/html5/thumbnails/16.jpg)
Considering edge (M, H)Disjoint sets: [F, G, H, J, L, M, T] [K]
Weight of red edges = 1 + 2 + 3 + 3 + 4 + 5 = 18
F
G
5
H
3
L
3 T
32
J
2
K
710 4
235
M
1
6
8
![Page 17: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red](https://reader036.vdocument.in/reader036/viewer/2022062604/5fb57aca858902562320606b/html5/thumbnails/17.jpg)
Edge (M, H) would introduce a cycle. Forget it.Disjoint sets: [F, G, H, J, L, M, T] [K]
Weight of red edges = 1 + 2 + 3 + 3 + 4 + 5 = 18
F
G
5
H
3
L
3 T
32
J
2
K
710 4
235
M
1
6
8
![Page 18: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red](https://reader036.vdocument.in/reader036/viewer/2022062604/5fb57aca858902562320606b/html5/thumbnails/18.jpg)
Considering edge (H, K)Disjoint sets: [F, G, H, J, L, M, T] [K]
Weight of red edges = 1 + 2 + 3 + 3 + 4 + 5 = 18
F
G
5
H
3
L
3 T
32
J
2
K
710 4
235
M
1
6
8
![Page 19: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red](https://reader036.vdocument.in/reader036/viewer/2022062604/5fb57aca858902562320606b/html5/thumbnails/19.jpg)
Edge (H, K) spans disconnected components: OK.Disjoint sets: [F, G, H, J, K, L, M, T]
Weight of red edges = 1 + 2 + 3 + 3 + 4 + 5 + 7 = 25
F
G
5
H
3
L
3 T
32
J
2
K
710 4
235
M
1
6
8
![Page 20: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red](https://reader036.vdocument.in/reader036/viewer/2022062604/5fb57aca858902562320606b/html5/thumbnails/20.jpg)
Considering edge (M, T)Disjoint sets: [F, G, H, J, K, L, M, T]
Weight of red edges = 1 + 2 + 3 + 3 + 4 + 5 + 7 = 25
F
G
5
H
3
L
3 T
32
J
2
K
710 4
235
M
1
6
8
![Page 21: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red](https://reader036.vdocument.in/reader036/viewer/2022062604/5fb57aca858902562320606b/html5/thumbnails/21.jpg)
Edge (M, T) would introduce a cycle. Forget it.Disjoint sets: [F, G, H, J, K, L, M, T]
Weight of red edges = 1 + 2 + 3 + 3 + 4 + 5 + 7 = 25
F
G
5
H
3
L
3 T
32
J
2
K
710 4
235
M
1
6
8
![Page 22: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red](https://reader036.vdocument.in/reader036/viewer/2022062604/5fb57aca858902562320606b/html5/thumbnails/22.jpg)
Considering edge (T, G)Disjoint sets: [F, G, H, J, K, L, M, T]
Weight of red edges = 1 + 2 + 3 + 3 + 4 + 5 + 7 = 25
F
G
5
H
3
L
3 T
32
J
2
K
710 4
235
M
1
6
8
![Page 23: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red](https://reader036.vdocument.in/reader036/viewer/2022062604/5fb57aca858902562320606b/html5/thumbnails/23.jpg)
Edge (T, G) would introduce a cycle. Forget it.Disjoint sets: [F, G, H, J, K, L, M, T]
Weight of red edges = 1 + 2 + 3 + 3 + 4 + 5 + 7 = 25
F
G
5
H
3
L
3 T
32
J
2
K
710 4
235
M
1
6
8
![Page 24: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red](https://reader036.vdocument.in/reader036/viewer/2022062604/5fb57aca858902562320606b/html5/thumbnails/24.jpg)
Considering edge (J, K)Disjoint sets: [F, G, H, J, K, L, M, T]
Weight of red edges = 1 + 2 + 3 + 3 + 4 + 5 + 7 = 25
F
G
5
H
3
L
3 T
32
J
2
K
710 4
235
M
1
6
8
![Page 25: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red](https://reader036.vdocument.in/reader036/viewer/2022062604/5fb57aca858902562320606b/html5/thumbnails/25.jpg)
Edge (J, K) would introduce a cycle. Forget it.Disjoint sets: [F, G, H, J, K, L, M, T]
Weight of red edges = 1 + 2 + 3 + 3 + 4 + 5 + 7 = 25
F
G
5
H
3
L
3 T
32
J
2
K
710 4
235
M
1
6
8
![Page 26: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red](https://reader036.vdocument.in/reader036/viewer/2022062604/5fb57aca858902562320606b/html5/thumbnails/26.jpg)
Considering edge (H, T)Disjoint sets: [F, G, H, J, K, L, M, T]
Weight of red edges = 1 + 2 + 3 + 3 + 4 + 5 + 7 = 25
F
G
5
H
3
L
3 T
32
J
2
K
710 4
235
M
1
6
8
![Page 27: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red](https://reader036.vdocument.in/reader036/viewer/2022062604/5fb57aca858902562320606b/html5/thumbnails/27.jpg)
Edge (H, T) would introduce a cycle. Forget it.Disjoint sets: [F, G, H, J, K, L, M, T]
Weight of red edges = 1 + 2 + 3 + 3 + 4 + 5 + 7 = 25
F
G
5
H
3
L
3 T
32
J
2
K
710 4
235
M
1
6
8
![Page 28: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red](https://reader036.vdocument.in/reader036/viewer/2022062604/5fb57aca858902562320606b/html5/thumbnails/28.jpg)
Kruskal minimum spanning treeGenerated by $Id: kruskal.py 90 2010-11-16 01:33:02Z fms27 $
(c) 2006-2010 Frank StajanoUniversity of Cambridge Computer Laboratory