4.4 ***Kruskal and other algorithms ***

Kruskal’s algorithm : Input graph weighted connected Graph G=(V,E,w).

  • Step 1:

    Initialize with D=E and M=(V(G),).

  • Step 2:

    Select one of the smallest (in terms of weight) edges in ED. Call it e.

  • Step 3:

    If Me does not create a cycle, set M=Me.

  • Step 4:

    Set D=De. If |E(M)|<n1 and DE, go to Step 2 else to Step 5.

  • Step 5:

    Output M.

Theorem 4.20.

The output of the Kruskal’s algorithm is a minimal spanning tree if G is connected.

Proof.

The proof consists of two steps - Firtly, we will show that the output M is a spanning tree and then show it is of minimum weight.

Step 1 : M is a spanning tree. Clearly M does not contain a cycle. If M has at least two components C1,C2, then let e an edge with minimal weight between C1 and C2. e exists as G is connected. e would have been added in Step 2 when it was considered. Thus, we derive a contradiction to the fact that M is disconnected. Hence M is connected and acyclic, i.e., a spanning tree.

Step 2 : M 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 T such that MT.

The above claim suffices because at the last step, the output M is the M at the end of Step 3 and if it is a subgraph of a spanning tree T, then it must be that M=T as M is a spanning tree from Step 1.

Induction argument : The claim holds in the beginning because M=. Assume that the claim holds at some stage of the algorithm for a M and a T.

Now, suppose that the next chosen edge creates a cycle, then M does not change and the claim still holds.

So, let the next chosen edge not create a cycle and hence M becomes M+e. If eT, we are done. Suppose eT. Then T+e has a cycle C. This cycle contains edges which do not belong to M, since e does not form a cycle in M but does in T. Note that, there exists fCM which has not been considered by the algorithms before and hence it must have weight at least as large as e. If f had been considered before e in the algorithm, Me+f will not contain a cycle (as Me+fT) and so f would have been added to M already.

Then Tf+e is a tree by the insertion property and it has the same or less weight as T. If w(f)=w(e), then Tf+e is a minimum spanning tree containing M+e and again the claim holds. If w(f)>w(e), then Tf+e is a spanning tree of strictly smaller weight than T and leads to a contradiction. ∎

Prim-Dijkstra-Jarnik’s algorithm : Input graph weighted connected Graph G=(V,E,w).

  • Step 1:

    Initialize with M=D= and S={v},T=VS for some vV.

  • Step 2:

    Select one of the smallest (in terms of weight) edges in E(S×T). Call it e and M=Me.

  • Step 3:

    Say e=(v1,v2)S×T then set S=S{v2} and T=VS.

  • Step 4:

    If T, then go to Step 2 else to Step 5.

  • Step 5:

    Output M.

Theorem 4.21.

The output of Prim-Dijkstra-Jarnik’s algorithm is a minimal spanning tree if G is connected.

Proof.

Denote the output by M~. The proof of the fact that M~ 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 MM with the latter being a MST.

The claim is trivially true at the initial step when M= and since MST exists. Suppose the claim is true upto some step with M,T,S already determined i.e., MM, a MST.

Let e=(u,v) be the edge chosen by the Prim’s algorithm at this stage and suppose eM. Then, there exists a path P from u to v in M. This implies that there exists an edge eP(T×S). But since Prim’s algorithm selected e instead of e, we have that w(e)w(e). But since P+e is a cycle in M+e, we can remove any edge from the cycle and still get a spanning tree. Thus, M+ee is also a spanning tree and since M is a MST, we have that w(e)w(e). Thus, we get that w(e)=w(e) and M+eM+ee, a MST. This proves the claim and completes the proof. ∎

Exercise* 4.22.

The multi-set of weights for a minimal spanning tree is unique i.e., for any s and any two MSTs M,M, we have that |{eM:w(e)=s}|=|{eM:w(e)=s}|.

Exercise 4.23 (Minimal Spanning Forests).

Define and suitably extend these notions to minimal spanning forests.

Exercise* 4.24.

Given a connected graph (G,E) with non-negative edge weights w satisfying the following conditions : w(u,v)= if (u,v)E and w(u,v)>0 if uv. Fixing a starting vertex x, show that the following algorithm computes the shortest paths from x to all other vertices in G.

  1. Step 1 :

    Let S={x},t(x)=0,t(u)=w(u,x) for uS.

  2. Step 2 :

    Select a uS such that t(u)=minzSt(z). Change S to S{u} and update t(z) for zS to min{t(z),t(u)+w(u,z)}.

  3. Step 3 :

    Continue Step 2 until S=V(G) and set d(u,x)=t(u) for all u.

Show that d(u,v)=dG(u,v).