Graph algorithm the best niche into a tree

Source: Internet
Author: User

Connected undirected graph g= (v,e), for each edge is given a weight w, want to find the edge of the collection is all points can be connected, and the weight of these edges can be minimized.

Because these edges are ring-free and can connect all the nodes, it eventually makes up a tree. This tree of Figure G is called the spanning tree, and the problem of finding the tree is called the minimum spanning tree problem.

What you need to learn here is the Kruskal algorithm and the prim algorithm.

Both of these algorithms are greedy algorithms, each of which must choose one of several possible choices.

This strategy does not necessarily find a spanning tree with the least weight.

The greedy algorithm grows one edge of the smallest spanning tree at all times and, throughout the implementation of the strategy, manages a set a that follows the following cyclic invariant:

Before each cycle, a is a subset of the smallest spanning tree in a section.

Before each step, an edge that is not part of collection A is selected to be added to the collection A, so that a new collection of a and that edge is still a subset of the smallest spanning tree.

The addition of this side to a does not destroy the cyclic invariant of a, so it is also called a secure edge.

Here's how to find the rules for identifying secure edges and build a minimum spanning tree algorithm using this rule.

Secure Edge Identification rules

Kruskal algorithm

Prim algorithm

Graph algorithm the best niche into a tree

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.