Kruskal algorithm (a) C language detailed

Source: Internet
Author: User

Minimum spanning tree

Selecting the n-1 edge in a connected graph with n vertices, constituting a minimum connected subgraph, and minimizing the sum of the weights on the n-1 edge of the connected subgraph, it is called the minimum spanning tree of the connected network.

For example, a connected network, as shown in the above figure G4, can have multiple spanning trees with different weights combined.

Introduction to Kruskal algorithm

Kruskal (Kruskal) algorithm is used to calculate the minimum spanning tree of weighted connected graphs.

Basic idea : According to the weight value from small to large order to select the n-1 edge, and ensure that the n-1 edge does not constitute a circuit.

The concrete approach : first constructs a forest which contains only n vertices, then chooses the edge from the connected network from small to large to join in the forest, and causes the forest to not produce the loop, until the forest becomes a tree.

Kruskal algorithm diagram

The above figure G4 as an example to demonstrate the Kruskal (assuming that the most niche tree result is saved with an array R).

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

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.