Q. Minimum Spanning Tree. From a connected, undirected, edge-weighted Graph, make a subset graph that:
- connects all vertices together
- minimum possible total edge weight
- ⇒ will always be a Tree
- → there could be multiple spanning tree (MST is not unique)
alg. Prim’s Algorithm
- Idea: Gradually build one big tree
- Choose random vertex, then add all edges connected to it to a Priority Queue.
- Use the lightest edge in the priority queue and connect to that vertex.
alg. Kruskal’s Algorithm.
- Idea: Build many trees, and gradually combine them.
- Choose lightest edge, then create a tree with that (using a Disjoint Set)
- If the vertices are already part of a small tree…
- if they’re different trees, combine the two trees with that edge
- if they’re same trees, don’t connect.
- Time complexity:
lem. Exchange Argument. Correctness proof for both Prim’s and Kruskal’s algorithm.
- Idea: If we have MST, choosing the lightest edge to connect them (greedily) is MST.
- Assume MST .
- Split into two components .
- Among edges that connect you choose the lightest edge .
- ⇒ Then, is a minimum spanning tree.
Discussion
- Prim’s and Kruska’s algorithms are both Greedy Algorithms
- If edge weights are distinct, there is a unique minimum spanning tree
- Doesn’t have anything to do with Shortest Path algorithms.
Applications
Q. Minimal Edge Removal to Acyclic Graph. Given a connected, undirected, weighted graph we will remove edges such that the remaining graph will have no cycles. What is with the minimum total weight sum?
- Compute maximum spanning tree on
- this can be done by modifying Prim’s or Kruskal’s algorithm… 2….or by running minimum spanning tree on a new graph with negated edge weights
- is the set of edges not contained by this MST