Method of finding minimum spanning tree (Kruskal)

There are many ways to find the minimum spanning tree. Here we introduce the circle avoidance method ( K ruska I KruskaIK r u s k a I algorithm)
Set the graphGGG hasnnWith n nodes, the following algorithm produces a minimum spanning tree.
(1) Choose the least weighted edgee 1 e_1e1, If there are multiple such edges, choose the edge with the smallest serial number and set the edge number i ← 1 i\leftarrow1i1;
(2) i = n − 1 i=n- 1 i=n1 is over, otherwise go to (3);
(3) Set the selectede 1, e 2,..., Ei e_1,e_2,... ,e_ie1,e2,...,ei, In GGG middle selection unmatchede 1, e 2, .., ei e_1, e_2, .., e_ie1,e2..,ei; The side ei + 1 e_{i+1}ei+1使and 1, and 2 ,. . , ei; e_1, e_2 , .., e_i;e1,e2..,ei; No loop andei + 1 e_{i+1}ei+1Is the smallest edge that satisfies this condition. If there are multiple such edges, select the edge with the smallest sequence number.
(4) i ← i + 1 i←i + 1ii+1 , go to (2).
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_41870170/article/details/114750054