Minimum spanning Tree prim

Source: Internet
Author: User

(1) The figure has 6 vertex v1-v6, each edge of the Benquan value is on the graph, in the prim algorithm, I randomly select a vertex as the starting point, of course, we generally choose V1 as the starting point, OK, now we set the U set for the currently found in the smallest spanning tree vertex, TE set as the found edge, Now the status is as follows:

U={V1}; te={};

(2) Now find a vertex in the U set, the other vertex in the V-u collection of the minimum weight, such as, the Red Line intersection of the lines to find the minimum value.

In the figure we can see that the weight of the edge v1-v3 is at least 1, then the V3 is added to the U set, (v1,v3) joins the TE, the state is as follows:

U={V1,V3}; te={(V1,v3)};

(3) Continue to look for, now the status is U={v1,v3}; te={(V1,v3)}; finds the minimum value on the edge that intersects the red line.

We can find the minimum weight of (V3,V6) = 4, then we add the V6 to the U set and add the smallest edge to the Te collection, then the join state is as follows:

U={V1,V3,V6}; te={(V1,v3), (V3,V6)}; So loop until all vertices are found.

(4) Like we showed all the search process:

Minimum spanning Tree prim

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.