Kruskal's algorithm: Difference between revisions

From formulasearchengine
Jump to navigation Jump to search
en>Gareth Jones
move reference inline, add template for reference
en>Runner1928
→‎See also: Added links
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
{{graph search algorithm}}
== 「ブラックエンジンブラザー、行きましょう ==
In [[computer science]], '''Prim's algorithm''' is a [[greedy algorithm]] that finds a [[minimum spanning tree]] for a [[Connected graph|connected]] [[Weighted graph|weighted]] [[undirected graph]].  This means it finds a subset of the [[edge (graph theory)|edge]]s that forms a [[Tree (graph theory)|tree]] that includes every [[Vertex (graph theory)|vertex]], where the total weight of all the [[graph theory|edges]] in the tree is minimized. The algorithm was developed in 1930 by [[Czech people|Czech]] mathematician [[Vojtěch Jarník]] and later independently by [[computer scientist]] [[Robert C. Prim]] in 1957 and rediscovered by [[Edsger Dijkstra]] in 1959. Therefore it is also sometimes called the '''DJP algorithm''', the '''Jarník algorithm''', or the '''Prim–Jarník algorithm'''.


Other algorithms for this problem include [[Kruskal's algorithm]] and [[Borůvka's algorithm]]. These algorithms find the minimum spanning forest in a possibly disconnected graph. By running Prim's algorithm for each [[Connected component (graph theory)| connected component]] of the graph, it can also be used to find the minimum spanning forest.
の禁止。 「Harengulaはささやいた。<br><br>'ではないその時間 [http://www.ispsc.edu.ph/nav/japandi/casio-rakuten-2.html casio 腕時計 デジタル]。'<br><br>シャオヤンは、女1ちらっと見首を横に振った、時間のために、彼にもあまりにも怠惰な実践的なレッスンを押す [http://www.ispsc.edu.ph/nav/japandi/casio-rakuten-6.html casio 腕時計 メンズ]。<br><br>「ブラックエンジンブラザー、行きましょう。 '<br><br>シャオヤンは、彼の頭を回したと黒のエンジンを見て、言った。<br>「ああ [http://www.ispsc.edu.ph/nav/japandi/casio-rakuten-13.html カシオ アナログ 腕時計]。」<br><br><br>黒エンジンは宇宙計画の前に、手のひらを首を縦に振った空間が亀裂から引き裂かれ、シャオヤンとHarengula身長フラッシュは中に穿孔されている [http://www.ispsc.edu.ph/nav/japandi/casio-rakuten-9.html casio 腕時計 ゴールド]。<br><br>はとても少数の人々が花のブロケードは、悪意を持って不正なパスのお腹の中で、緩和されるが、ちょうど黒い空のスペース亀裂ギャングゆう清足音に入ったことが、彼らの心に響き非難することを左シャオヤンを見ましたそれは食事ですが、振り返ってみることはありません、彼の手を振った、直接そよ風オープンスペースを破った恐怖の波は、一瞬、体が花のブロケードの上に落ちたということです。<br><br>「プチ! [http://www.ispsc.edu.ph/nav/japandi/casio-rakuten-2.html カシオ 時計 プロトレック] '
相关的主题文章:
<ul>
 
  <li>[http://www.hula.tv/cgi-bin/joyful/joyful.cgi http://www.hula.tv/cgi-bin/joyful/joyful.cgi]</li>
 
  <li>[http://www.meyfang.com/bbs/thread-18004-1-1.html http://www.meyfang.com/bbs/thread-18004-1-1.html]</li>
 
  <li>[http://www.luphen.org.uk/cgi-bin/guestbook/guestbook.cgi http://www.luphen.org.uk/cgi-bin/guestbook/guestbook.cgi]</li>
 
</ul>


[[File:Prim's algorithm.svg|left|120px|thumb|Prim's algorithm starting at vertex A. In the second step, BD is chosen to add to the tree instead of AB arbitrarily, as both have weight 2. Afterwards, AB is excluded because it is between two nodes that are already in the tree.]]
== 彼女が去った後 ==
== Description ==
===Informal===
{|
|
# Initialize a tree with a single vertex, chosen arbitrarily from the graph.
# Grow the tree by one edge: Of the edges that connect the tree to vertices not yet in the tree, find the minimum-weight edge, and transfer it to the tree.
# Repeat step 2 (until all vertices are in the tree).
|}


===Technical===
Guysは穏やかなようですが、まれに人、特に女性は、またはそのようなムードの「露」を [http://www.ispsc.edu.ph/nav/japandi/casio-rakuten-12.html カシオ 時計 電波]。<br><br>そして、この感情が、この感情の源「さらさ」この愛、少しでも医療セント、彼女はテーブルを見た後にいくつかのシャオヤン、シャオヤン以来の理解から、すべての心を助けることがうらやましいことができなかった、それがある今では彼の腕、青衣の少女<br><br>シャオヤンは猛烈に人の子の腕、戦後、彼は疲れていたように、ソフトな姿勢、少女と活力を注入される心の少しを抱きしめた [http://www.ispsc.edu.ph/nav/japandi/casio-rakuten-10.html カシオの時計]。<br>彼女が去った後<br>が苦難を経験したどのように、、シャオヤンは子供たちが、いくつかの同情の間で渡す明るい約束をしがみついてやる彼女ははっきりと知っているだけではシャオヤンを吸って、家族が狭く破壊を免れ、メンターだった戦闘のこれらの種類をキャッチすることが悩んでいる子どもたちを吸ったように、すべての激しく、その若者の肩、元少年の上で押されている<br><br>しかし、彼女はそれを喜んでいた、シャオヤン
If a graph is empty then we are done immediately. Thus, we assume otherwise.
相关的主题文章:
<ul>
 
  <li>[http://www.apjc.cc/forum.php?mod=viewthread&tid=16233 http://www.apjc.cc/forum.php?mod=viewthread&tid=16233]</li>
 
  <li>[http://shuangyinghe.com/plus/feedback.php?aid=10 http://shuangyinghe.com/plus/feedback.php?aid=10]</li>
 
  <li>[http://www.isjdlm.com/home.php?mod=space&uid=5296 http://www.isjdlm.com/home.php?mod=space&uid=5296]</li>
 
</ul>


The algorithm starts with a tree consisting of a single vertex, and continuously increases its size one edge at a time, until it spans all vertices.
== 「一時的に呼吸が止まる ==


{|
人々が有毒な酒は、下のキャストでの強さのほとんどメドゥーサは、実際にこの人が勝つことは困難である影を恐れたが、状況を見て、さらには行き詰まりトレンドので多分それはある [http://www.ispsc.edu.ph/nav/japandi/casio-rakuten-12.html 時計 カシオ]<br>「この人とは?メドゥーサは、ハード再生することができましたし、上を向く上下? [http://www.ispsc.edu.ph/nav/japandi/casio-rakuten-13.html カシオ アナログ 腕時計] '2影崖Shanlueを見ているhuan​​hangrn、シャオヤンの目は次第に、あなたが知っている、タッチが威厳メデューサを浮上している強さは、偶数ラインで、私はこの神秘的な影を期待していなかった、オリジナルの雲山の違いであるためには、彼らと競合することが可能であった。<br>少しめまい彼の額、頭をなで<br>は「この男は良いと強く、色が妹をスケーリング実際にあまりにも長い間プレーすることができ、そして彼の体の味、本当にめまいの後ろに臭い [http://www.ispsc.edu.ph/nav/japandi/casio-rakuten-15.html カシオ ソーラー 腕時計]。「パープル研究マイクロしかめ、手。<br><br>ウェンヤン、シャオヤン李鄭、臭いに負担をかけますが、それは恐怖では非常に軽い臭いの痕跡を持っているときに空気が私にはわからないことがわかった [http://www.ispsc.edu.ph/nav/japandi/casio-rakuten-1.html カシオ 腕時計 チタン]<br><br>「一時的に呼吸が止まる! [http://www.ispsc.edu.ph/nav/japandi/casio-rakuten-7.html カシオ 腕時計 gps] '
|
相关的主题文章:
* Input: A non-empty connected weighted graph with vertices ''V'' and edges ''E'' (the weights can be negative).
<ul>
* Initialize: ''V''<sub>new</sub> = {''x''}, where ''x'' is an arbitrary node (starting point) from ''V'', ''E''<sub>new</sub> = {}
 
* Repeat until ''V''<sub>new</sub> = ''V'':
  <li>[http://top100.rambler.ru/cgi-bin/stats_top100.cgi http://top100.rambler.ru/cgi-bin/stats_top100.cgi]</li>
** Choose an edge {''u'', ''v''} with minimal weight such that ''u'' is in ''V''<sub>new</sub> and ''v'' is not (if there are multiple edges with the same weight, any of them may be picked)
 
** Add ''v'' to ''V''<sub>new</sub>, and {''u'', ''v''} to ''E''<sub>new</sub>
  <li>[http://lab.huaxi100.com/forum.php?mod=viewthread&tid=780753 http://lab.huaxi100.com/forum.php?mod=viewthread&tid=780753]</li>
* Output: ''V''<sub>new</sub> and ''E''<sub>new</sub> describe a minimal spanning tree
 
|}
  <li>[http://mbafj.cn/?action-viewnews-itemid-670 http://mbafj.cn/?action-viewnews-itemid-670]</li>
 
 
== Time complexity ==
</ul>
[[File:MAZE 30x20 Prim.ogv|thumb|Prim's algorithm has many applications, such as in the [[maze generation|generation]] of this maze, which applies Prim's algorithm to a randomly weighted [[grid graph]].]]
 
{| class="wikitable"
! Minimum edge weight data structure !! Time complexity (total)
|-
| [[adjacency matrix]], searching || O(<nowiki>|</nowiki>V<nowiki>|</nowiki><sup>2</sup>)
|-
| [[binary heap]] and [[adjacency list]] || O((<nowiki>|</nowiki>V<nowiki>|</nowiki> + <nowiki>|</nowiki>E<nowiki>|</nowiki>) log <nowiki>|</nowiki>V<nowiki>|</nowiki>) = O(<nowiki>|</nowiki>E<nowiki>|</nowiki> log <nowiki>|</nowiki>V<nowiki>|</nowiki>)
|-
| [[Fibonacci heap]] and [[adjacency list]] || O(<nowiki>|</nowiki>E<nowiki>|</nowiki> + <nowiki>|</nowiki>V<nowiki>|</nowiki> log <nowiki>|</nowiki>V<nowiki>|</nowiki>)
|}
A simple implementation using an [[adjacency matrix]] graph representation and searching an array of weights to find the minimum weight edge to add requires [[Big-O notation|O]](<nowiki>|</nowiki>V<nowiki>|</nowiki><sup>2</sup>) running time. Using a simple [[binary heap]] data structure and an [[adjacency list]] representation, Prim's algorithm can be shown to run in time [[Big-O notation|O]](<nowiki>|</nowiki>E<nowiki>|</nowiki> log <nowiki>|</nowiki>V<nowiki>|</nowiki>) where <nowiki>|</nowiki>E<nowiki>|</nowiki> is the number of edges and <nowiki>|</nowiki>V<nowiki>|</nowiki> is the number of vertices. Using a more sophisticated [[Fibonacci heap]], this can be brought down to [[Big-O notation|O]](<nowiki>|</nowiki>E<nowiki>|</nowiki> + <nowiki>|</nowiki>V<nowiki>|</nowiki> log <nowiki>|</nowiki>V<nowiki>|</nowiki>), which is [[Asymptotic computational complexity|asymptotically faster]] when the graph is [[Dense graph|dense]] enough that <nowiki>|</nowiki>E<nowiki>|</nowiki> is [[Big-O notation#Family_of_Bachmann.E2.80.93Landau_notations|ω]](<nowiki>|</nowiki>V<nowiki>|</nowiki>).
 
[[File:Prim's_algorithm_proof.svg|thumb|150px|Demonstration of proof. In this case, the graph ''Y<sub>2</sub>'' = ''Y<sub>1</sub>'' − ''f'' + ''e'' is already equal to ''Y''. In general, the process may need to be repeated.]]
== Proof of correctness ==
Let ''P'' be a connected, weighted [[graph theory|graph]].  At every iteration of Prim's algorithm, an edge must be found that connects a vertex in a subgraph to a vertex outside the subgraph. Since  ''P'' is connected, there will always be a path to every vertex.  The output ''Y'' of Prim's algorithm is a [[Tree (graph theory)|tree]], because the edge and vertex added to tree ''Y'' are connected. Let ''Y<sub>1</sub>'' be a minimum spanning tree of graph P. If ''Y<sub>1</sub>''=''Y'' then ''Y'' is a minimum spanning tree. Otherwise, let ''e'' be the first edge added during the construction of tree ''Y'' that is not in tree ''Y<sub>1</sub>'', and ''V'' be the set of vertices connected by the edges added before edge ''e''. Then one endpoint of edge ''e'' is in set ''V'' and the other is not.  Since tree ''Y<sub>1</sub>'' is a spanning tree of graph ''P'', there is a path in tree ''Y<sub>1</sub>'' joining the two endpoints.  As one travels along the path, one must encounter an edge ''f'' joining a vertex in set ''V'' to one that is not in set ''V''.  Now, at the iteration when edge ''e'' was added to tree ''Y'', edge ''f'' could also have been added and it would be added instead of edge ''e'' if its weight was less than ''e'', and since edge ''f'' was not added, we conclude that
 
:<math>w(f) \ge w(e).</math>
 
Let tree ''Y<sub>2</sub>'' be the graph obtained by removing edge ''f'' from and adding edge ''e'' to tree ''Y<sub>1</sub>''.  It is easy to show that tree ''Y<sub>2</sub>'' is connected, has the same number of edges as tree ''Y<sub>1</sub>'', and the total weights of its edges is not larger than that of tree ''Y<sub>1</sub>'', therefore it is also a minimum spanning tree of graph ''P'' and it contains edge ''e'' and all the edges added before it during the construction of set ''V''.  Repeat the steps above and we will eventually obtain a minimum spanning tree of graph ''P'' that is identical to tree ''Y''.  This shows ''Y'' is a minimum spanning tree.
 
== See also ==
* [[Kruskal's algorithm]]
 
== References ==
{{Reflist}}
* V. Jarník: ''O jistém problému minimálním'' [About a certain minimal problem], Práce Moravské Přírodovědecké Společnosti, 6, 1930, pp.&nbsp;57–63. (in Czech)
* R. C. Prim: ''Shortest connection networks and some generalizations''. In: ''Bell System Technical Journal'', 36 (1957), pp.&nbsp;1389–1401
* [[David Cheriton|D. Cheriton]] and [[Robert Tarjan|R. E. Tarjan]]: ''Finding minimum spanning trees''. In: ''[[SIAM Journal on Computing]]'', 5 (Dec. 1976), pp.&nbsp;724–741
* [[Thomas H. Cormen]], [[Charles E. Leiserson]], [[Ronald L. Rivest]], and [[Clifford Stein]]. ''[[Introduction to Algorithms]]'', Third Edition. MIT Press, 2009. ISBN 0-262-03384-4. Section 23.2: The algorithms of Kruskal and Prim, pp.&nbsp;631&ndash;638.
 
==External links==
{{commons category|Prim's Algorithm}}
* [http://scanftree.com/Data_Structure/prim's-algorithm Prim's algorithm with 'C' implementation]
* [http://students.ceid.upatras.gr/~papagel/project/prim.htm Animated example of Prim's algorithm]
* [http://www.mincel.com/java/prim.html Prim's Algorithm (Java Applet)]
* [http://people.csail.mit.edu/rivest/programs.html Minimum spanning tree demonstration Python program by Ronald L. Rivest]
* [http://code.google.com/p/annas/ Open Source Java Graph package with implementation of Prim's Algorithm]
* [http://code.google.com/p/ngenerics/ Open Source C# class library with implementation of Prim's Algorithm]
* [https://github.com/monmohan/mgraphlib/ Open Source Java graph library with implementation of Prim's Algorithm]
 
[[Category:Graph algorithms]]
[[Category:Spanning tree]]
[[Category:Articles containing proofs]]

Latest revision as of 01:29, 13 December 2014

「ブラックエンジンブラザー、行きましょう

の禁止。 「Harengulaはささやいた。

'ではないその時間 casio 腕時計 デジタル。'

シャオヤンは、女1ちらっと見首を横に振った、時間のために、彼にもあまりにも怠惰な実践的なレッスンを押す casio 腕時計 メンズ

「ブラックエンジンブラザー、行きましょう。 '

シャオヤンは、彼の頭を回したと黒のエンジンを見て、言った。
「ああ カシオ アナログ 腕時計。」


黒エンジンは宇宙計画の前に、手のひらを首を縦に振った空間が亀裂から引き裂かれ、シャオヤンとHarengula身長フラッシュは中に穿孔されている casio 腕時計 ゴールド

はとても少数の人々が花のブロケードは、悪意を持って不正なパスのお腹の中で、緩和されるが、ちょうど黒い空のスペース亀裂ギャングゆう清足音に入ったことが、彼らの心に響き非難することを左シャオヤンを見ましたそれは食事ですが、振り返ってみることはありません、彼の手を振った、直接そよ風オープンスペースを破った恐怖の波は、一瞬、体が花のブロケードの上に落ちたということです。

「プチ! カシオ 時計 プロトレック ' 相关的主题文章:

彼女が去った後

Guysは穏やかなようですが、まれに人、特に女性は、またはそのようなムードの「露」を カシオ 時計 電波

そして、この感情が、この感情の源「さらさ」この愛、少しでも医療セント、彼女はテーブルを見た後にいくつかのシャオヤン、シャオヤン以来の理解から、すべての心を助けることがうらやましいことができなかった、それがある今では彼の腕、青衣の少女

シャオヤンは猛烈に人の子の腕、戦後、彼は疲れていたように、ソフトな姿勢、少女と活力を注入される心の少しを抱きしめた カシオの時計
彼女が去った後
が苦難を経験したどのように、、シャオヤンは子供たちが、いくつかの同情の間で渡す明るい約束をしがみついてやる彼女ははっきりと知っているだけではシャオヤンを吸って、家族が狭く破壊を免れ、メンターだった戦闘のこれらの種類をキャッチすることが悩んでいる子どもたちを吸ったように、すべての激しく、その若者の肩、元少年の上で押されている

しかし、彼女はそれを喜んでいた、シャオヤン 相关的主题文章:

「一時的に呼吸が止まる

人々が有毒な酒は、下のキャストでの強さのほとんどメドゥーサは、実際にこの人が勝つことは困難である影を恐れたが、状況を見て、さらには行き詰まりトレンドので多分それはある 時計 カシオ
「この人とは?メドゥーサは、ハード再生することができましたし、上を向く上下? カシオ アナログ 腕時計 '2影崖Shanlueを見ているhuan​​hangrn、シャオヤンの目は次第に、あなたが知っている、タッチが威厳メデューサを浮上している強さは、偶数ラインで、私はこの神秘的な影を期待していなかった、オリジナルの雲山の違いであるためには、彼らと競合することが可能であった。
少しめまい彼の額、頭をなで
は「この男は良いと強く、色が妹をスケーリング実際にあまりにも長い間プレーすることができ、そして彼の体の味、本当にめまいの後ろに臭い カシオ ソーラー 腕時計。「パープル研究マイクロしかめ、手。

ウェンヤン、シャオヤン李鄭、臭いに負担をかけますが、それは恐怖では非常に軽い臭いの痕跡を持っているときに空気が私にはわからないことがわかった カシオ 腕時計 チタン

「一時的に呼吸が止まる! カシオ 腕時計 gps ' 相关的主题文章: