minimum Spanning TreeDefinition:Nthe spanning tree of a vertex network hasNa node,n-1branches of the bar. Suppose the network hasmStrip Edge(M≥n-1), withMSTrepresents a collection of many possible spanning trees, in each treen-1the sum of the weights on the branchesWG (T)indicates that it makesWG (Tmin) =MIN{WG (T) | TMST}the Spanning TreeTminis the smallest spanning tree of the network. algorithm for constructing the minimum spanning tree : Prime algorithm and Kruskal algorithm Kruskal algorithm definition: in order to minimize the weights on the top of the spanning tree, it is clear that the weights of each edge should be as small as possible. the Kruskal algorithm is to construct a sub-graph SGwith only n vertices,and then start with the expediency with the lowest value, if its addition does not make SG generates a loop in the SG Add this edge, so repeat, until you add n-1 edge of the bar. Features:Kruskal algorithm is actually a greedy (greedy) algorithm: The w greedy algorithm approaches a given target from an initial solution of the problem and obtains a better solution as soon as possible. The algorithm stops when a step in an algorithm can no longer move forward. The greedy algorithm always makes the best choice in the current view. Code:
constructing non-connected graphs ST = ( v,{} ); // The edge is empty at this time
k = I = 0;
//k The number of edges to be selected, I is the ordinal of an optional edge
while (k<n-1)
{ + +i;
Select The Edge (u,v ) with the lowest weight value from the edge set E );
if (u,v) joins St does not cause the circuit in the St ,
the output Edge (u,v), and k++;
}
Minimum spanning Tree--kruskal algorithm