Min spanning tree (split algorithm, cruise Karl algorithm)

Source: Internet
Author: User

Given a weighted undirected connected graph, how to select a spanning tree to minimize the total number of weights on all sides of the tree is calledMinimum Spanning Tree.

Algorithm for Minimum Spanning Tree
(1)Cruise Karl Algorithm
The storage structure of the graph uses the number groups of edge sets, and the edges with equal weights can be arranged randomly in the array. this method is not very useful for edge comparison and is a waste of time.
(2)Prim algorithm
The storage structure of the graph uses the adjacent matrix. this method is based on the steps of connecting each vertex. You need to use a vertex set and start with an empty set. Later, the connected vertex will be added to the set one after another, add a set of all vertices to obtain the required minimum spanning tree.

The following is a detailed description:
Cruise Karl Algorithm
Method: select the edges in the order of their weights from small to large. If no loop is formed after the edges are selected, the edges are retained as one edge. If a loop is formed, the edges are removed. select (n-1) edges in order to obtain the minimum spanning tree. (N is the number of vertices)

Step 1: select the first edge from the number group of edge Sets

Step 2: select the second edge, that is, the edge with the weight of 2.

Step 3: select the third edge, that is, the edge with the weight of 3.

Step 4: select the fourth edge, that is, the edge with the weight of 4.

Step 5: select the fifth edge

 

Prim algorithm
Method: Add a set from the specified vertex, then, an edge with the smallest weight value is selected from the vertex in the set and all the edges composed of the vertex outside the set as the edges of the Spanning Tree, add the vertex outside the set to the set, indicating that the vertex is connected. find the smallest edge in the edge composed of the vertex in the Set and the vertex outside the set, and add the corresponding vertex to the set until all vertices are added to the set, the Minimum Spanning Tree is obtained.
In this example, the Minimum Spanning Tree of the graph is obtained from, and the vertex and weight are entered into the table in the order of the edge of the Spanning Tree.

-------> Write out its adjacent matrix first

Step 1: Start from ① and start from ①. Use an edge that can be formed by all vertices outside the set to find an edge with the minimum weight.
① -- ② 6
① -- ③ Weight 1> ① -- ③ edge
① -- ④ Privilege 5

 

Step 2: ③ enter the set, ①, ③ and ②, ④, ⑤, and ⑥. The smallest edge is
① -- ④ Privilege 5
③ -- ⑥ Right 4-> take ③ -- 6th edge

Step 3: Step 6: add the smallest edge of the Set, ①, ③, ⑥ and ②, ④, and ⑤.
① -- ② 6
③ -- ② Privilege 5
⑥ -- ④ Right 2-> take ⑥ -- ④ edge

Step 4: ④ Add the smallest edge of the Set, ①, ③, ⑥, ④ and ②, ⑤
① -- ② 6
③ -- ② Right 5-> take ③ -- ② edge
⑥ -- ⑤ Privilege 6

Step 4: ② Add the smallest edge of the Set, ①, ③, ⑥, ②, ④ and ⑤
② -- ⑤ Right 3-> take ② -- ⑤ side

This is also a Kruskal and prim Construction Process Diagram found on the Internet, posted:

 

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.