Does Prim’s algorithm always yield a minimum spanning tree? The answer
to this question is yes. Let us prove by induction that each of the subtrees Ti,
i = 0, . . . , n − 1, generated by Prim’s algorithm is a part (i.e., a subgraph) of some
minimum spanning tree. (This immediately implies, of course, that the last tree in
the sequence, Tn−1, is a minimum spanning tree itself because it contains all n
vertices of the graph.) The basis of the induction is trivial, since T0 consists of a
single vertex and hence must be a part of any minimum spanning tree. For the
inductive step, let us assume that Ti−1 is part of some minimum spanning tree T .
We need to prove that Ti, generated from Ti−1 by Prim’s algorithm, is also a part
of a minimum spanning tree.We prove this by contradiction by assuming that no
minimum spanning tree of the graph can contain Ti . Let ei
= (v, u) be the minimum
weight edge from a vertex in Ti−1 to a vertex not in Ti−1 used by Prim’s algorithm to
expand Ti−1 to Ti . By our assumption, ei cannot belong to any minimum spanning
tree, including T . Therefore, if we add ei to T , a cycle must be formed
In addition to edge ei
= (v, u), this cycle must contain another edge (v, u)
connecting a vertex v ∈ Ti−1 to a vertex u
that is not in Ti−1. (It is possible thatv
coincides with v or u
coincides with u but not both.) If we now delete the edge
(v, u) from this cycle, we will obtain another spanning tree of the entire graph
whose weight is less than or equal to the weight of T since the weight of ei is less
than or equal to the weight of (v, u). Hence, this spanning tree is a minimum
spanning tree, which contradicts the assumption that no minimum spanning tree
contains Ti .
In addition to edge ei
= (v, u), this cycle must contain another edge (v, u)
connecting a vertex v ∈ Ti−1 to a vertex u
that is not in Ti−1. (It is possible thatv
coincides with v or u
coincides with u but not both.) If we now delete the edge
(v, u) from this cycle, we will obtain another spanning tree of the entire graph
whose weight is less than or equal to the weight of T since the weight of ei is less
than or equal to the weight of (v, u). Hence, this spanning tree is a minimum
spanning tree, which contradicts the assumption that no minimum spanning tree
contains Ti .