MIT 6.1220 — Lecture 8
Minimum Spanning Trees
Definition (Tree). A tree is a connected acyclic graph.
Definition (Spanning Tree). A spanning tree of a graph is a tree with .
Claim. Every connected graph has a spanning tree.
Proof: There are many proofs (induction, BFS, …). Here's an algorithmic proof:
Algorithm. Initialize . While contains a cycle , repeatedly pick edges from at random to remove from . Return when done.
This terminates and yields a connected, acyclic graph (i.e. a spanning tree), done. Here's another proof:
Algorithm. Initialize . While is not connected, repeatedly draw edges between connected components of . Return when done.
This terminates and yields a connected, acyclic graph (i.e. a spanning tree), done.
Problem. (Minimum Spanning Tree) Find the spanning tree of a weighted graph with least total edge weight.
Here's a useful fact for building spanning tree intuition, from the cycle perspective.
Claim. Say is a spanning tree of , and consider any edge . Then:
There is a unique path connecting and in .
There is a fundamental cycle of with respect to defined by .
For all , the subgraph is also a spanning tree.
Note that the first two bullet points don't really require , or care about at all, really.
And here's a similar fact, from the cutting perspective.
Claim. Say is a spanning tree of , and consider any edge . Then:
If we remove from , we get two connected components and (containing and , respectively).
For any connecting and , the subgraph is a spanning tree.
This inspires Kruskal's Algorithm, which constructs by adding edges to a forest.
Solution. (Kruskal's Algorithm) Here's the algorithm, in full.
Initialize . Initialize a data structure to store connected components. Sort by weight.
Scan through all edges for all , in increasing order of weight.
For each such that , add to and apply .
Finally, return .
Proof: It suffices to demonstrate by induction that is always a subset of some MST.
Suppose initially, for some MST . Now we draw an edge between the connected component of in and . (Intuitively, we should think of edge as bridging across the “cut” .)
If , we're fine. Otherwise, take the fundamental cycle of with respect to ; this cycle must bridge across the “cut” a second time along some edge .
You can now check that is also an MST, so remains a subset of an MST .
Here's our runtime analysis of Kruskal's Algorithm.
Solution. (Kruskal's Algorithm Runtime) There's only three major steps.
Initializing the data structure takes time.
Sorting takes time (since ).
All of the operations take time.
So in total, we can say the runtime of Kruskal's Algorithm is .
This also inspires Prim's Algorithm, which grows by connecting vertices to a tree.
Remark. Recall the following properties of a priority queue implemented by a Fibonacci heap.
A priority queue stores keys together with their values.
The method returns the lowest-value key of and deletes it in amortized time.
The methods and run in amortized time.
Solution. (Prim's Algorithm) Here's the algorithm, in full:
Initialize .
Initialize a and an array .
The queue will store keys with values .
The array will store for each the vertex with .
Initialize for all .
Pick some starting vertex , and initialize and for all .
While is nonempty…
Add the edge to , where .
(Add nothing when , as on the first iteration.)
Now that we've added to , we need to make some updates. For each neighboring still in …
Update , and update as needed.
If was updated, then also update .
Return when done.
Proof: Again, we wish to show is invariably a subset of some MST.
It's actually the same argument as before. Consider the cut . You can do whatever to bridge this cut and the result will still be an ST, minimal if you do the “whatever” with minimal weight.
This runs in time, since…
We have iterations of , each of which takes time.
The updates have amortized cost with a Fibonacci heap, total.