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.
本文详细阐述了Prim算法如何找到一个连通加权图的最小生成树,并通过逐步添加边和顶点来构建一棵树,最终证明该树是最小生成树。
57

被折叠的 条评论
为什么被折叠?



