Optimal Substructure of Prim's Algorithm

Proof:
There is an undirected graph G = ( V , E ) G =(\mathbf V, \mathbf E )G=(V,E ) , whereV = { v 1 , v 2 , … , vn } \mathbf V=\{ v_1,v_2,\dots,v_n\}V={ v1,v2,,vn}E = { e 1 , e 2 , … , em } \mathbf E=\{ e_1,e_2,\dots,e_m\}E={ e1,e2,,em} .The spanning tree isG ′ = ( V , E ′ ) G^{'} =(\mathbf V, \mathbf E^{'} )G=(V,E ),ifE ′ = { et 1 , et 2 , ... , etn − 1 } \mathbf E^{'}=\{ e_{t_1},e_{t_2},\dots,e_{t_n-1}\ } }E={ et1,et2,,etn1} .
(optimal substructure):
without loss of generality, let the initial node specified by the prim algorithm bev 1 v_1v1, Figure GGG has some minimum spanning treeTTT , where withv 1 v_1v1The connected node with the smallest edge weight is va v_ava, the corresponding side is e 1 a = ( v 1 , va ) e_{1a}=(v_1,v_a)e1a=(v1,va) . WillGGG andTTv 1 v_1in Tv1sum va v_avamerged into a new vertex vc v_cvc, delete edge e 1 a e_{1a}e1a, and for both and v 1 v_1v1sum va v_avaConnected nodes, keep the edge with the smallest weight and vc v_cvcGet G 1 G_1 after connectingG1and T 1 T_1T1. Now need to prove T 1 T_1T1for G 1 G_1G1The minimum spanning tree of .
Let T 1 T_1T1Not G 1 G_1G1The minimum spanning tree of T 2 T_2T2for G 1 G_1G1The minimum spanning tree of W ( T 2 ) < W ( T 1 ) W(T_2)<W(T_1)W(T2)<W(T1) . T2 T_2T2and T 1 T_1T1vc v_c invcNode reverts to v 1 v_1v1sum va v_ava节点,则有 W ( T 2 ) + W ( e 1 a ) < W ( T 1 ) + W ( e 1 a ) = W ( T ) W(T_2)+W(e_{1a})<W(T_1)+W(e_{1a})=W(T) W(T2)+W ( ie1a)<W(T1)+W ( ie1a)=W ( T ) andTTT is the minimum spanning tree contradiction. So the optimal substructure holds.

おすすめ

転載: blog.csdn.net/qq_40206924/article/details/129844976