Greedy minimum spanning tree- prim's algorithm
Upcoming SlideShare
Loading in...5

Like this? Share it with your network

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads


Total Views
On Slideshare
From Embeds
Number of Embeds



Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

    No notes for slide


  • 1. Greedy Minimum Spanning Tree: Prim's Algorithm 研究⽣生:鍾聖彥 教授: 許慶昇 ⽼老師
  • 2. Key ingredients of greedy algorithms • Optimal substructure: An optimal solution to the problem contains within it optimal solutions to subproblems. • Greedy-choice property: We can assemble a globally optimal solution by making locally optimal (greedy) choices.
  • 3. 什麼問題可以使⽤用greedy algorithm來解? 1.如果做出⼀一個choice之後,  可以找到剩下要解的單⼀一個 subproblem     2.Greedy-choice property(必須證明最佳解裡⾯面⼀一定有 greedy choice) 3.有optimal substructure (必須證明⼤大問題的最佳解裡 ⾯面有⼩小問題的最佳解)
  • 4. Graphs
  • 5. EXAMPLE:Weighted graph A C D F E B G H
  • 6. Spanning Tree(⽣生成樹)
  • 7. Minimum Spanning Tree A C D F E B G H ⺫⽬目的:移除weighted graph中的部份邊線,使得⼦子圖仍然 保持連通性,且邊線weight總和為最⼩小 權重最⼩小的⽣生成樹就是最⼩小⽣生成樹
  • 8. Application
  • 9. Optimal substructure • ⼀一、兩棵 MST ,要合併成⼀一棵 MST 時,以兩棵 MST 之間權重最⼩小 的邊進⾏行連結,當然會是最好的。 • ⼆二、三棵 MST ,要合併成⼀一棵 MST 時,先連結其中兩棵連結權重 最⼩小的 MST ,然後才連結第三棵,總是⽐比較好。 • 三、⼀一個單獨的點,可以視作⼀一棵 MST 。 • 由以上三點,可以歸納出⼀一個 greedy 演算法:以權重最⼩小的邊連結 各棵 MST ,⼀一定⽐比較好。
  • 10. Optimal substructure MST T
  • 11. Optimal substructure MST T Remove any edge (u,v) ∈ T
  • 12. Optimal substructure MST T Remove any edge (u,v) ∈ T. Then it is partitioned into two subtrees T1 and T2 T1 T2
  • 13. Optimal substructure MST T Theorem. The subtree T1 is MST of G1 = (V1,E1),the subgragh of G induced by the vertex of T1 Similarly for T2 T1 T2 G1
  • 14. Proof of Optimal substructure MST T T1 T2 G1 w(T) = w(u, v) + w(T1) + w(T2) If T1′ were a lower-weight spanning treat than T1 for G1, then T′ = {(u, v)} ∪ T1′ ∪ T2 would be a lower-weight spanning tree than T of G
  • 15. –Greedy Agorithm Greedy-choice property" A locally optimal choice is globally optimal
  • 16. Theorem Let T be the MST of G = (V,E), and let A ⊆ V. Suppose that (u,v)∈ E is the least-weight edge connecting A to V-A, then (u,v)∈ T The proof is by contradiction(⽭矛盾) Cut-and-Paste is a way used in proofing graph theory concepts, Idea: Assume you have solution for Problem A, you want to say some edge/node, should be available in solution. You will assume you have solution without specified edge/node, you try to reconstruct a solution by cutting an edge/node and pasting specified edge/node and say new solution benefit is at least as same as previous solution.
  • 17. Proof of theorem Consider the unique simple path from u to v in T
  • 18. Proof of theorem Swap(u, v) with the first edge on this path that connects a vertex in A to a vertex in V–A
  • 19. Proof of theorem A lighter-weight spanning tree than T results. Proving that greedy choice is good enough.
  • 20. Prim’s Algorithm
  • 21. Prim’s Algorithm Use Priority Queue
  • 22. Prim’s Algorithm • 增加節點的觀念做為出發點。 • ⾸首先以某⼀一節點當作出發點,在與其相連且 尚未被選取的節點裡,選擇權重最⼩小的邊, 將新的節點加⼊入。 • 如此重覆加⼊入新節點,直到增加了n - 1條邊 為⽌止。(假設有 n 個節點)