日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

Kruskal(P)和Prim(K)算法

發(fā)布時(shí)間:2025/3/11 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Kruskal(P)和Prim(K)算法 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

最小生成樹(shù) (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是已連接的無(wú)向圖的邊的子集,該邊將所有頂點(diǎn)連接在一起,其中不形成循環(huán),因此總邊的權(quán)重應(yīng)最小。

  • 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.

    在該樹(shù)中,樹(shù)的權(quán)重定義為樹(shù)的所有相連邊的權(quán)重之和,但沒(méi)有形成循環(huán)。

  • 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的所有頂點(diǎn),則將樹(shù)T稱(chēng)為連通圖X的生成樹(shù)。

生成樹(shù)的應(yīng)用 (Application of Spanning Tree)

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

    生成樹(shù)在網(wǎng)絡(luò)設(shè)計(jì)等許多領(lǐng)域都有廣泛的應(yīng)用。

  • Spanning tree is important in designing routing algorithms.

    生成樹(shù)在設(shè)計(jì)路由算法時(shí)很重要。

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

    基于最小生成樹(shù)的實(shí)際應(yīng)用包括分類(lèi)法和聚類(lèi)分析。

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

    • It is an application of a greedy algorithm.

      它是貪婪算法的一種應(yīng)用。

    • In this edges are selected with minimum weight and added to MST till no cycle is formed.

      在這種情況下,以最小的重量選擇邊緣,并將其添加到MST中,直到?jīng)]有循環(huán)形成為止。

    • 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.

      它找到形成樹(shù)的邊緣子集,該樹(shù)包括每個(gè)頂點(diǎn),樹(shù)中所有邊緣的總權(quán)重最小。

    • Kruskal algorithm does not form a tree at each step.

      Kruskal算法并非在每個(gè)步驟都形成一棵樹(shù)。

    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.

    如果沒(méi)有形成電路,則應(yīng)添加邊緣。

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

    繼續(xù)這些步驟,直到訪問(wèn)了所有邊緣并形成了MST。

  • Add the cost of all edges in MST to get a minimum cost of a spanning tree.

    在MST中添加所有邊的成本,以獲取生成樹(shù)的最低成本。

  • 2)Prim的算法 (2) Prim’s algorithm)

    • This algorithm generally focused on vertices.

      該算法通常集中在頂點(diǎn)上。

    • Prim's algorithm always forms a tree at every step.

      Prim的算法總是在每一步都形成一棵樹(shù)。

    • It applies the nearest neighbor method to select new edges.

      它應(yīng)用最近鄰居方法來(lái)選擇新邊。

    • 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.

      當(dāng)我們必須找到密集圖的最低成本時(shí),通常會(huì)使用此算法,因?yàn)樵撨吘墧?shù)量很高。

    • Basically, Prim's algorithm is faster than the Kruskal's algorithm in the case of the complex graph.

      基本上,在復(fù)雜圖的情況下,Prim算法比Kruskal算法更快。

    Steps for the Prim’s algorithms are as follows:

    Prim算法的步驟如下:

  • Start with a vertex, say u.

    從頂點(diǎn)開(kāi)始,說(shuō)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.

    選擇另一個(gè)頂點(diǎn)v ,以使邊緣由u和v形成并具有最小權(quán)重,連接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.

    現(xiàn)在,集所有頂點(diǎn)中找到其他頂點(diǎn)v 是不包含在使得(V I,V j)為最小的標(biāo)記,是集合A中的所有頂點(diǎn)的近鄰,并沒(méi)有形成一個(gè)周期,加它到A。

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

    繼續(xù)執(zhí)行此過(guò)程,直到獲得MST為止,然后形成的MST成本最低。

  • Reference: Kruskal's algorithm

    參考: Kruskal算法

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

    總結(jié)

    以上是生活随笔為你收集整理的Kruskal(P)和Prim(K)算法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

    如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。