Minimum spanning Tree--kruskal algorithm

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.