Minimum spanning tree algorithm

Source: Internet
Author: User

Given a weighted undirected graph, how to select a spanning tree so that the sum of all the edges on the tree is minimal, which is called the minimum spanning tree.

1. Kruskal algorithm

Methods: The edges of the graph are selected by the order of their weights from small to large, and if the edges are not formed, the loops are retained as an edge, and if the loop is formed, the loops are removed. Select enough (n-1) edges, which is the minimum spanning tree. (n is the number of vertices)

Cruscalfa for the edge of a particular situation, consumption time is more, not very practical.

2. Primm Algorithm

Method: Add it to the collection starting at the specified vertex, and then select one of the lowest weights in all edges of the collection to the vertices that are outside the collection as the edge of the spanning tree, and add that vertex outside the collection to the collection. Indicates that the vertex is connected. The smallest edges are found in the edges of the vertices in the collection and the vertices outside the set, and the corresponding vertices are added to the collection, so that all vertices are added to the collection, which is the smallest spanning tree.

Minimum spanning tree 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.