Minimum Spanning Tree Flashcards
Define a spanning tree
A spanning tree is an acyclic subset of edges that connects all nodes in a graph.
Define a minimum spanning tree
A spanning tree with the minimum weight.
Proof that a minimum spanning tree is acyclic.
If an MST is cyclic, that means there is an edge which we can remove to make the MST lighter. Thus, this proves the contradiction that the original cyclic spanning tree is an MST.
Is MST and shortest path the same? Explain.
MST and shortest path are not the same. An MST gives you a tree which traverse through all the nodes with the least weight. Shortest path does not need to traverse through all the nodes, it just gives the shortest path between two given nodes in the graph.
Basic properties of an MST.
- No cycles
- Cutting an MST produces two separate MSTs
- Cycle property: for every cycle, the maximum weight edge is NOT in the MST.
- Cut property: for every partition of the nodes, the minimum weight edge across the cut IS in the MST.
- For every vertex, the minimum outgoing edge is in the MST.
Explain the generic MST algorithm.
Red rule: if C is a cycle with no red arcs, color the max weight edge in C red.
Blue rule: if D is a cut with no blue arcs, color the min weight edge in D blue.
On termination, all edges will be colored either red or blue. All the blue edges will be our MST (otherwise there is a cut with no blue edge) and all cycles will have a red edge (there can not be a blue cycle).
Explain Prim’s algorithm.
- Start with a root node. Call this node R.
- Look at all the edges going out from this node, take the minimum one. Store the rest in a priority queue. These edges are the edges that crosses the cut which separates our R from the rest of the graph.
- The minimum edge connects R to another node, call this A. Now recurse the whole process in step 2 where the edges now are the edges that crosses the cut which separates our R and A from the rest of the graph.
- Recurse until we have covered all nodes. The edges we obtain forms our desired MST.
Why is Prim’s algorithm called the “blue” algorithm?
It’s because the basic idea stems from the blue rule, in which all the edges added during the recursion are each the lightest edge on some cut in the graph.
Explain Kruskal’s algorithm.
- Sort all the edges by their weight.
- From lightest to heaviest, check each edge and see if it connects two nodes which are a part of the same connected component (blue tree). If yes, color this edge red. If no, color this edge blue.
We also use Union-Find to find the nodes and check if they are in the same connected component and to merge two connected components.
Analyse the running time of Prim’s algorithm.
Constructing the priority queue takes O(VlogV) for V nodes. We will perform the decreaseKey at most E times which takes O(ElogV). Total: O(VlogV) + O(ElogV) and since E = O(V^2), the total is O(ElogV).
Analyse the running time of Kruskal’s algorithm.
Sorting all the edges by their weight will take O(ElogE) time. For each edge, using Union-Find will take O(α(V)).
Total: O(ElogE) + O(Eα(V)) and since E = O(V^2) and O(Eα(V)) is basically O(E), we can also rewrite this as O(ElogV).
Explain Boruvka’s algorithm.
One Boruvka’s step does:
- For each connected component. search for the minimum weight outgoing edge. This can be done using BFS or DFS which takes O(V + E).
- Add these selected edges.
- Merge the components which are connected by these edges.
Analyse the running time of Boruvka’s algorithm.
At most we have to perform logV Boruvka steps. This only happens when each merge only connected component to another. Thus, the worst case runtime is O((V+E)logV) = O(ElogV). But most of the time it will run much faster than this.
What if all the edges have the same weights?
We can just perform a DFS or BFS to find the shortest path which will also be our MST.
If the edges are all of cost X, what is the cost of the MST?
(V-1)X