Kruskal’s algorithm : Input graph weighted connected Graph
Initialize with and .
Select one of the smallest (in terms of weight) edges in . Call it .
If does not create a cycle, set
Set . If and , go to Step 2 else to Step 5.
Output .
The output of the Kruskal’s algorithm is a minimal spanning tree if is connected.
The proof consists of two steps - Firtly, we will show that the output is a spanning tree and then show it is of minimum weight.
Step 1 : is a spanning tree. Clearly does not contain a cycle. If has at least two components , then let an edge with minimal weight between and . exists as is connected. would have been added in Step 2 when it was considered. Thus, we derive a contradiction to the fact that is disconnected. Hence is connected and acyclic, i.e., a spanning tree.
Step 2 : has minimum weight. We shall show that the following claim holds by induction : At every stage of the algorithm, there is a minimal spanning tree such that .
The above claim suffices because at the last step, the output is the at the end of Step 3 and if it is a subgraph of a spanning tree , then it must be that as is a spanning tree from Step 1.
Induction argument : The claim holds in the beginning because . Assume that the claim holds at some stage of the algorithm for a and a .
Now, suppose that the next chosen edge creates a cycle, then does not change and the claim still holds.
So, let the next chosen edge not create a cycle and hence becomes . If , we are done. Suppose . Then has a cycle . This cycle contains edges which do not belong to , since does not form a cycle in but does in . Note that, there exists which has not been considered by the algorithms before and hence it must have weight at least as large as . If had been considered before in the algorithm, will not contain a cycle (as ) and so would have been added to already.
Then is a tree by the insertion property and it has the same or less weight as . If , then is a minimum spanning tree containing and again the claim holds. If , then is a spanning tree of strictly smaller weight than and leads to a contradiction. ∎
Prim-Dijkstra-Jarnik’s algorithm : Input graph weighted connected Graph
Initialize with and for some .
Select one of the smallest (in terms of weight) edges in . Call it and .
Say then set and
If , then go to Step 2 else to Step 5.
Output .
The output of Prim-Dijkstra-Jarnik’s algorithm is a minimal spanning tree if is connected.
Denote the output by . The proof of the fact that is a spanning tree is left as an exercise as the steps were sketched in the class. W e shall only show minimality here.
Claim : As with the proof of Kruskal’s algorithm, we shall show that at every step with the latter being a MST.
The claim is trivially true at the initial step when and since MST exists. Suppose the claim is true upto some step with already determined i.e., , a MST.
Let be the edge chosen by the Prim’s algorithm at this stage and suppose . Then, there exists a path from to in . This implies that there exists an edge . But since Prim’s algorithm selected instead of , we have that . But since is a cycle in , we can remove any edge from the cycle and still get a spanning tree. Thus, is also a spanning tree and since is a MST, we have that . Thus, we get that and , a MST. This proves the claim and completes the proof. ∎
The multi-set of weights for a minimal spanning tree is unique i.e., for any and any two MSTs , we have that
Define and suitably extend these notions to minimal spanning forests.
Given a connected graph with non-negative edge weights satisfying the following conditions : if and if . Fixing a starting vertex , show that the following algorithm computes the shortest paths from to all other vertices in .
Let for .
Select a such that . Change to and update for to .
Continue Step 2 until and set for all .
Show that .