You are on page 1of 16

Kruskal’s algorithm

Prof. Tathagata Ray


Cut Property
Assume that all edge costs are distinct.
Let S be any subset of nodes that is
neither empty nor equal to all of V, and let
edge e = (v, w) be the minimum cost edge
with one end in S and the other in V − S.
Then every minimum spanning tree
contains the edge e.
Proof.
S V-S

20

10

12

14
Proof
Let T be any spanning tree of G which
doesn’t contain e(v,w). Then in T there
must be a path P from v to w.
Let w’ be the first encountered in V-S
while walking from v to w on P.
Let v’ be the previous vertex to w’ in P.
Thus v’ is in S and w’ is in V-S.
Proof.
T

v’ 20 w’

10
w

12
v
14
Proof
T’ = T – {e’} U {e}
Let w’ be the first encountered in V-S
while walking from v to w on P.
Let v’ be the previous vertex to w’ in P.
Thus v’ is in S and w’ is in V-S.
Proof.
T’

v’ 20 w’

10
w

12
v
14
Proof
 Claim: T’ is a spanning tree.
 Note that (V,T’) is connected and any path in (V,T)
that used the edge e’(v’,w’) can rerouted in (V,T’),
 Let there be a path P from vertex a to b in (V,T) which
used e(v’,w’).
 So there was a path from a to v’ and w’ to b.
 Also there is a path from v to v’ in T’. So reroute the
path from a to v.
 Similarly there was a path from w’ to w in T’. So
reroute it from w to b.
 So now we have a path from a to b using the edge
e(v,w).
Proof.
T

v’ 20 w’

10
w

b
2
a
12
v
14
Proof.
T’

v’ 20 w’

10
w

2
a b
12
v
14
Proof
T’ willacyclic because adding e created
one single cycle in (V, T’ U{e}) but then
we deleted e’ removing that single cycle.

Now since w(e) < w(e’), the cost of T’ is


cheaper than that of T.
So MST contains e.
Proof.
T

v’ 20 w’

10
w

b
2
a
12
v
14
Kruskal’s Correctness
Theorem: Kruskal’s algorithm produces a
spanning tree of G.
Proof:
Consider any edge e(v,w) added by
Kruskal’s algorithm.
Let S be the set of nodes to which v has a
path at this moment.
Clearly vϵ S and w ϵ V-S, since adding e
does not create a cycle.
V-S

S
v w
Proof
Moreover, no edge from S to V-S has
been encountered yet, since any such edge
could have been added without creating a
cycle, and hence would have added
Kruskal’s algorithm.
Thus e is the cheapest edge with one end
point in S and other end point in V-S.
Thus by Cut Property e belongs to MST.
Also,the output of Kruskal’s algorithm is a
spanning tree.

It is a tree because we explicitly check to avoid


cycles.
If (V,T) were not connected then there would
exist a non-empty set S of nodes such that there
is no edge from S to V-S. But that cannot happen
as G is connected. There is at least one edge
between S and V-S and algorithm will add first of
these that algorithm encounters.

You might also like