最小生成树 (Minimum Spanning Tree)
An MST is a subset of the edges of the connected, undirected graph that connect all the vertices together, in which there is no forming of a cycle and there should be minimum possible total edge weight.
MST是已连接的无向图的边的子集,该边将所有顶点连接在一起,其中不形成循环,因此总边的权重应最小。
In this weight of a tree is defined as the sum of the weight of all its edges which are connected but no formation of the cycle is there.
在该树中,树的权重定义为树的所有相连边的权重之和,但没有形成循环。
A tree T is said to be a spanning tree of a connected graph X if T is a subgraph of X and T contains all vertices of X.
如果T是X的子图并且T包含X的所有顶点,则将树T称为连通图X的生成树。
生成树的应用 (Application of Spanning Tree)
Spanning tree has wide applications in many areas like network design.
生成树在网络设计等许多领域都有广泛的应用。
Spanning tree is important in designing routing algorithms.
生成树在设计路由算法时很重要。
Practical application based on minimum spanning tree includes taxonomy and cluster analysis.
基于最小生成树的实际应用包括分类法和聚类分析。
1)Kruskal算法 (1) Kruskal’s Algorithm)
It is an application of a greedy algorithm.
它是贪婪算法的一种应用。
In this edges are selected with minimum weight and added to MST till no cycle is formed.
在这种情况下,以最小的重量选择边缘,并将其添加到MST中,直到没有循环形成为止。
It is used to find a minimum cost.
它用于查找最低成本。
It finds a subset of the edges that forms a tree that includes every vertex, where the total weight of all the edges in the tree is minimized.
它找到形成树的边缘子集,该树包括每个顶点,树中所有边缘的总权重最小。
Kruskal algorithm does not form a tree at each step.
Kruskal算法并非在每个步骤都形成一棵树。
Steps for the kruskal’s algorithm are as follows:
kruskal算法的步骤如下:
Firstly arrange all the edges in increasing order of their weight.
首先,以重量增加的顺序排列所有边缘。
Then the edges should be added if it does not form a circuit.
如果没有形成电路,则应添加边缘。
Continue these steps till all the edges are visited and MST is formed.
继续这些步骤,直到访问了所有边缘并形成了MST。
Add the cost of all edges in MST to get a minimum cost of a spanning tree.
在MST中添加所有边的成本,以获取生成树的最低成本。
2)Prim的算法 (2) Prim’s algorithm)
This algorithm generally focused on vertices.
该算法通常集中在顶点上。
Prim's algorithm always forms a tree at every step.
Prim的算法总是在每一步都形成一棵树。
It applies the nearest neighbor method to select new edges.
它应用最近邻居方法来选择新边。
This algorithm is generally used when we have to find a minimum cost of a dense graph because this number of edges will be high.
当我们必须找到密集图的最低成本时,通常会使用此算法,因为该边缘数量很高。
Basically, Prim's algorithm is faster than the Kruskal's algorithm in the case of the complex graph.
基本上,在复杂图的情况下,Prim算法比Kruskal算法更快。
Steps for the Prim’s algorithms are as follows:
Prim算法的步骤如下:
Start with a vertex, say u.
从顶点开始,说u 。
Select another vertex v such that edges are formed from u and v and are of minimum weight, connect uv and add it to set of MST for edges A.
选择另一个顶点v ,以使边缘由u和v形成并具有最小权重,连接uv并将其添加到边缘A的MST集。
Now among the set of all vertices find other vertex vi that is not included in A such that (vi, vj) is minimum labeled and is the nearest neighbor of all vertices in set A and it does not form a cycle, add it to A.
现在,集所有顶点中找到其他顶点v 我是不包含在使得(V I,V j)为最小的标记,是集合A中的所有顶点的近邻,并没有形成一个周期,加它到A。
Continue this process till we get an MST, then the MST formed will be of minimum cost.
继续执行此过程,直到获得MST为止,然后形成的MST成本最低。
Reference: Kruskal's algorithm
参考: Kruskal算法
翻译自: https://www.includehelp.com/algorithms/p-and-k-algorithms.aspx