Kruskal(P)和Prim(K)算法

本文介绍了最小生成树的概念及其应用,详细讲解了Kruskal算法和Prim算法,包括它们的工作原理、适用场景和实现步骤。Kruskal算法通过贪心策略选择最小权重边,Prim算法则专注于顶点,每次迭代确保形成一棵树。这两种算法在解决网络设计和路由算法问题时发挥重要作用。
摘要由CSDN通过智能技术生成

最小生成树 (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 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算法的步骤如下:

  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: Kruskal's algorithm

参考: Kruskal算法

翻译自: https://www.includehelp.com/algorithms/p-and-k-algorithms.aspx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值