LetPbeaconnected,weightedgraph.
AteveryiterationofPrim'salgorithm,
anedgemustbefoundthatconnects
avertexinasubgraphtoavertex
outsidethesubgraph.SincePis
connected,therewillalwaysbea
pathtoeveryvertex.TheoutputY
ofPrim'salgorithmisatree,because
theedgeandvertexaddedtotreeY
areconnected.LetY1beaminimum
spanningtreeofgraphP.IfY1=Ythen
Yisaminimumspanningtree.Otherwise,
letebethefirstedgeaddedduringthe
constructionoftreeYthatisnotin
treeY1,andVbethesetofvertices
onnectedbytheedgesaddedbefore
edgee.Thenoneendpointofedge
eisinsetVandtheotherisnot.
SincetreeY1isaspanningtreeof
graphP,thereisapathintreeY1
joiningthetwoendpoints.Asone
travelsalongthepath,onemust
encounteranedgefjoiningavertex
insetVtoonethatisnotinsetV.
Now,attheiterationwhenedgee
wasaddedtotreeY,edgefcould
alsohavebeenaddedanditwould
beaddedinsteadofedgeeifits
weightwaslessthane(weknow
weencounteredtheopportunity
totake"f"before"e"because"f"is
connectedtoV,andwevisitedevery
vertexofVbeforethevertexto
whichweconnected"e"["e"is
connectedtothelastvertexwe
visitedinV]).Sinceedgefwas
notadded,weconcludethat
ω(f)≥ω(e)
LettreeY2bethegraphobtained
byremovingedgeffromand
addingedgeetotreeY1.Itis
easytoshowthattreeY2isconnected,
hasthesamenumberofedgesas
treeY1,andthetotalweightsofits
edgesisnotlargerthanthatoftreeY1,
thereforeitisalsoaminimumspanning
treeofgraphPanditcontainsedge
eandalltheedgesaddedbeforeit
duringtheconstructionofsetV.
Repeatthestepsaboveandwewill
eventuallyobtainaminimum
spanningtreeofgraphPthatis
identicaltotreeY.Thisshows
Yisaminimumspanningtree.