博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Kruskal(P)和Prim(K)算法
阅读量:2530 次
发布时间:2019-05-11

本文共 3120 字,大约阅读时间需要 10 分钟。

最小生成树 (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.

    如果TX的子图并且T包含X的所有顶点,则将树T称为连通图X的生成树。

生成树的应用 (Application of Spanning Tree)

  1. Spanning tree has wide applications in many areas like network design.

    生成树在网络设计等许多领域都有广泛的应用。

  2. Spanning tree is important in designing routing algorithms.

    生成树在设计路由算法时很重要。

  3. Practical application based on minimum spanning tree includes taxonomy and cluster analysis.

    基于最小生成树的实际应用包括分类法和聚类分析。

1)Kruskal算法 (1) Kruskal’s Algorithm)

  • It is an application of a .

    它是一种应用。

  • 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算法的步骤如下:

  1. Firstly arrange all the edges in increasing order of their weight.

    首先,以重量增加的顺序排列所有边缘。

  2. Then the edges should be added if it does not form a circuit.

    如果没有形成电路,则应添加边缘。

  3. Continue these steps till all the edges are visited and MST is formed.

    继续这些步骤,直到访问了所有边缘并形成了MST。

  4. 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算法的步骤如下:

  1. Start with a vertex, say u.

    从顶点开始,说u

  2. 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 ,以使边缘由uv形成并具有最小权重,连接uv并将其添加到边缘AMST集。

  3. 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。

  4. Continue this process till we get an MST, then the MST formed will be of minimum cost.

    继续执行此过程,直到获得MST为止,然后形成的MST成本最低。

Reference:

参考:

翻译自:

转载地址:http://pvtzd.baihongyu.com/

你可能感兴趣的文章
“==”运算符与equals()
查看>>
单工、半双工和全双工的定义
查看>>
Hdu【线段树】基础题.cpp
查看>>
时钟系统
查看>>
BiTree
查看>>
5个基于HTML5的加载动画推荐
查看>>
水平权限漏洞的修复方案
查看>>
静态链接与动态链接的区别
查看>>
Android 关于悬浮窗权限的问题
查看>>
如何使用mysql
查看>>
linux下wc命令详解
查看>>
敏捷开发中软件测试团队的职责和产出是什么?
查看>>
在mvc3中使用ffmpeg对上传视频进行截图和转换格式
查看>>
python的字符串内建函数
查看>>
Spring - DI
查看>>
微软自己的官网介绍 SSL 参数相关
查看>>
Composite UI Application Block (CAB) 概念和术语
查看>>
64位MATLAB和C混合编程以及联合调试
查看>>
原生js大总结二
查看>>
PHP基础
查看>>