Original article:
Http://www.wutianqi.com /? P = 1284
<Hr>
Given a weighted undirected connected graph, how to select a spanning tree to minimize the sum of the 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 of edge sets, and the edges with equal weights can be arranged in any order in the array. This method is not very useful for the relatively large number of edges and is a waste of time.
(2)Prim algorithm
The graph storage structure uses the adjacent matrix. this method is based on the steps of connecting each vertex. You need to use a vertex set to start as an empty set, and then add the connected vertex to the set one after another, add all vertices to the set 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 vertex to the 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 enter the set to find an edge with the minimum weight among all vertices outside the set.
① -- ② 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:
I have not found any templates for this question. I think this question is mainly about thinking. Of course, it is essential to give some questions to practice.
Hdoj 1233 or smooth Engineering
Hdoj 1863 smooth Engineering
Hdoj 1879 continuous smooth Engineering
Http://www.wutianqi.com /? P = 1286
Hdoj 1102 constructing roanalyticdb
Http://www.wutianqi.com /? P = 1313
Hdoj 1875 smooth engineering resumption
Http://www.wutianqi.com /? P = 1300