Author: Hayden Smith 2021
Why?
What?
Applications? Electrical grids, networks. Essentially anything where we want to connect nodes assuming that edge lengths are costly.
How do we find the MSTs for a Graph?
One possible strategy is to just brute force: Generate all spanning trees, calculate total weight of each, and find the minimum. However, this is very expensive.
Thankfully, others have developed algorithms for us. Today we will explore just two of them.
Kruskal's algorithm is one approach for computing an MST:
KruskalMST(G):
MST=empty graph
sort edges(G) by weight
for each e ∈ sortedEdgeList:
MST = MST ∪ {e} // add edge
if MST has a cyle:
MST = MST \ {e} // drop edge
if MST has n-1 edges:
return MST
Rough time complexity analysis …
Possibilities for cycle checking: Use DFS?
Prim's algorithm is one approach for computing an MST:
PrimMST(G):
MST = empty graph
usedV = {0}
unusedE = edges(g)
while |usedV| < n:
find e = (s,t,w) ∈ unusedE such that {
s ∈ usedV ∧ t ∉ usedV
(∧ w is min weight of all such edges)
}
MST = MST ∪ {e}
usedV = usedV ∪ {t}
unusedE = unusedE \ {e}
return MSTRough time complexity analysis …
Note:
Read more about a comparison here.