Prim algorithm of minimum spanning tree

Source: Internet
Author: User

Prim algorithm:

Suppose n = (v,{e}) is a connected network, TE is the set of edges in the smallest spanning tree on N. The algorithm starts with u={u0} (u0), te={}, and repeats the following: in all u belonging to the v-u side (U,V) belonging to E, find a cost-minimal edge (U0,V0) merged into the set TE, while V0 merged into U until U=v, There must be a n-1 bar edge in TE, then t= (V,{te}) is the smallest spanning tree of N.

To implement this algorithm, an auxiliary array Closedge should be attached to record edges with the lowest cost from u to v-u. For each vertex vi belonging to the v-u, there is a corresponding component in the secondary array closedge[i-1], which includes two domains, the Lowcost domain stores the Edge's right, and the Vex field stores the vertices of the side attached to the U.

Consider the following non-network:

Adjacency Matrix:

The minimum spanning tree is:

The prim algorithm process (the graph is represented by the adjacency matrix, assuming starting from vertex a):

1. Initialize the auxiliary array first, and the vertex u into the U set:

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.