Lecture 23
Lecture 23
G 50
6
B
2 3 E
4 C 5
A 9
2
7
7 F
D
8
KruskalMST(Graph G)
foreach (V : vertices) {
makeMST(v); +? +V(makeMST)
}
sort edges in ascending order by weight +ElogE How many times will we call union?
foreach(edge (u, v)){
V–1
if(findMST(v) is not in findMST(u)){+?
union(u, v) +? +E(2findMST + union) -> +Vunion + EfindMST
}
}
Appendix: MST Properties, Another
MST Application
Whenever you add an edge to a tree you create exactly one cycle, you can then remove any edge
from that cycle and get another tree out.
This observation, combined with the cycle and cut properties form the basis of all of the greedy
algorithms for MSTs.
You have n rooms you need to show them, connected by the unfinished hallways.
Thanks to your generous donors you have n-1 construction crews, so you can assign one to each
of that many hallways.
- Sadly the hallways are narrow and you can’t have multiple crews working on the same hallway.
B B
2 2
3 3 C
C A
A
1 1
2 2
4 4
D D
Graph on the right is a minimum bottleneck spanning tree, but not a minimum
spanning tree.
CSE 373 SP 18 - KASEY CHAMPION 22
Finding MBSTs
Algorithm Idea: want to use smallest edges. Just start with the smallest edge and add it if it
connects previously unrelated things (and don’t if it makes a cycle).
Hey wait…that’s Kruskal’s Algorithm!
Every MST is an MBST (because Kruskal’s can find any MST when looking for MBSTs)
but not vice versa (see the example on the last slide).