Kruskal(P)和Prim(K)算法

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

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/540966.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/540966.shtml
英文地址,請注明出處:http://en.pswp.cn/news/540966.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

java get post 注解,GET/POST接收或發送數據的問題

在文章開始,先來回憶一下GET、POST這兩種請求方式的區別。?Http定義了與服務器交互的不同方法,最基本的方法有4種,分別是GET,POST,PUT,DELETE。URL全稱是資源描述符,我們可以這樣認為&#xff…

mybatis中sql語句傳入多個參數方法

1 使用map <select id"selectRole" parameterType"map" resultType"RoleMap">SELECT id, roleName, noteFROM roleWHERE roleName LIKE Concat(%,#{roleName},%)and note like Concat(%,#{note},%)</select> 在接口中如下定義 List&…

kotlin半生對象_Kotlin程序| 隨播對象特征

kotlin半生對象伴侶對象 (Companion object) If you need a function or a property to be tied to a class rather than to instances of it (similar to static in java), you can declare it inside a companion object: 如果需要將函數或屬性綁定到類而不是實例(類似于java…

mysql安裝注意步驟,mysql安裝步驟

mysql安裝步驟1、在官網下載對應的壓縮文件&#xff0c;放到本地文件夾下&#xff0c;解壓縮。2、配置Path環境變量&#xff1a;新增mysql的bin文件夾路徑&#xff0c;C:\software\mysql-8.0.23-winx64\bin。3、在mysql根目錄下新增my.ini配置文件。內容如下&#xff0c;basedi…

maven插件介紹之tomcat7-maven-plugin

tomcat7-maven-plugin插件的pom.xml依賴為&#xff1a; <dependency><groupId>org.apache.tomcat.maven</groupId><artifactId>tomcat7-maven-plugin</artifactId><version>2.2</version> </dependency>一&#xff1a;直接執行…

在Python中模擬do-while循環

Python as a language doesnt support the do-while loop. However, we can have a workaround to emulate the do-while loop. Python作為一種語言不支持do-while循環。 但是&#xff0c;我們可以采用一種變通方法來模擬do-while循環 。 The syntax for do-while is as follo…

織夢cms生成首頁html的php文件,織夢DedeCMS定時自動生成首頁HTML的實現方法

只需要制作一個文件然后在首頁模板添加一句代碼就可以實現讓織夢DedeCMS自動生成首頁html&#xff0c;具體方法如下&#xff1a;第一步、需要在首頁調用隨機文章&#xff0c;這樣每次自動更新才會有更新的效果&#xff0c;隨機文章調用標簽如下&#xff1a;{dede:arclist sortr…

Linux下安裝Flume

1 下載Flume Welcome to Apache Flume — Apache Flume 下載1.9.0版本 2 上傳服務器并解壓安裝 3 刪除lib目錄下的guava-11.0.2.jar &#xff08;如同服務器安裝了hadoop&#xff0c;則刪除&#xff0c;如沒有安裝hadoop則保留這個文件&#xff0c;否則無法啟動flume&#…

Apple新發布的APFS文件系統對用戶意味著什么

2016年WWDC大會上&#xff0c;Apple除了公布watchOS、tvOS、macOS以及iOS等一系列系統和軟件更新外&#xff0c;還公布了一個名為APFS&#xff08;Apple File System&#xff09;的文件系統。 這一全新文件系統專門針對閃存/SSD進行優化&#xff08;但依然可用于傳統機械硬盤&a…

chown –r mysql:mysql,mysql部署,操作及異常處理

1、將mysql-5.1.50-linux-x86_64-glibc23.tar.gz移至/usr/local/目錄下&#xff0c;并改名為mysql增加mysql組#groupadd mysql建mysql用戶&#xff0c;并加入到mysql組中#useradd –g mysql mysql源碼包解壓#tar mysql-5.1.50-linux-x86_64-glibc23.tar.gz將解壓后的源碼包放置…

光伏等新能源信用風險事件頻繁爆發

2016年以來&#xff0c;伴隨著供給側改革相關政策陸續出臺和落地&#xff0c;去產能、去杠桿誘發信用風險事件陸續爆出。而在“11天威NTN1”、“15云峰PPN001”及“15云峰PPN003”等信用風險事件上&#xff0c;大股東“棄車保帥”行為再現&#xff0c;令本就失去造血能力的企業…

ruby array_Ruby中帶有示例的Array.zip()方法

ruby arrayArray.zip()方法 (Array.zip() Method) In this article, we will study about Array.zip() Method. You all must be thinking the method must be doing something which is related to zipping values of the Array instance. It is not as simple as it looks. W…

matlab中迪杰斯特拉算法,dijkstra算法(迪杰斯特拉算法)

單源最短路徑算法——Dijkstra算法&lpar;迪杰斯特拉算法&rpar;一 綜述 Dijkstra算法(迪杰斯特拉算法)主要是用于求解有向圖中單源最短路徑問題.其本質是基于貪心策略的(具體見下文).其基本原理如下: (1)初始化:集合vertex_set初始為{sourc ...Dijkstra【迪杰斯特拉算法…

關于概率算法的問題,不知道邏輯錯在哪里,求debug

做個骰子成功幾率的分析&#xff0c;投n顆骰子&#xff0c;第一次投成功的幾率是a,然后投成功的骰子&#xff0c;需要再投1次&#xff0c;這次成功的幾率是b。第二次成功的骰子才算最終成功。 要分析出n顆骰子&#xff0c;最終成功0到n顆的概率。 我寫了個算法&#xff0c;求出…

tps 交易量_交易處理系統(TPS)

tps 交易量A transaction is a simple process that takes place during business operations. The transaction processing system (TPS) manages the business transactions of the client and therefore helps a companys operations. A TPS registers, as well as all of i…

matlab for循環不覆蓋,將輸出保存到文本文件而不覆蓋和打印矩陣中的N個條目[matlab]...

這是代碼&#xff1a;for i 1:4;fileID fopen(testdata.txt, at);fprintf(fileID, this is answer %d\n,i);fprintf(fileID, %5.3e\n, v{i});fclose(fileID);end在記事本中回答&#xff1a;this is answer 11.000e0001.000e0001.000e0001.000e0001.000e0001.000e0000.000e0001…

(轉)Redis研究(一)—簡介

http://blog.csdn.net/wtyvhreal/article/details/41855327 Redis是一個開源的高性能鍵值對數據庫。它通過提供多種鍵值數據類型來適應不同場景下的存儲需求&#xff0c;并借助許多高層級的接口使其可以勝任如緩存、隊列系統等不同的角色。 1.1歷史和發展 2008年&#xff0c;意…

c bitset get_Java BitSet get()方法與示例

c bitset getBitSet類的get()方法 (BitSet Class get() method) Syntax: 句法&#xff1a; public boolean get(int bit_in);public BitSet get(int st_in, int en_in);get() method is available in java.util package. get()方法在java.util包中可用。 get(int bit_in) meth…

有擾動的閉環傳遞函數 matlab,(d)閉環系統的誤差傳遞函數.PPT

(d)閉環系統的誤差傳遞函數3. 控制系統的方框圖模型 若已知控制系統的方框圖,使用MATLAB函數可實現方框圖轉換。 a).串聯 如圖所示G1(s)和G2(s)相串聯,在MATLAB中可用串聯函數series( )來求G1(s)G2(s),其調用格式為 [num,den]series(num1,den1,num2,den2) 其中&#xff1a; b)并…

CYQ.Data 輕量數據層之路 自定義MDataTable綁定續章(七)

本章起&#xff0c;將續章講解整框架當初的設計思路&#xff1a; 本章既為續章&#xff0c;說明我以前寫過&#xff0c;是的&#xff0c;以前我寫過內部整個MDataTable的構造&#xff0c;不過&#xff0c;當初匆匆寫完后&#xff0c; 最后一步的實現MDataTable綁定GridView/Dat…