SlideShare a Scribd company logo
Greedy
Minimum Spanning Tree: Prim's Algorithm
研究⽣生:鍾聖彥
教授: 許慶昇 ⽼老師
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.
什麼問題可以使⽤用greedy
algorithm來解?
1.如果做出⼀一個choice之後,	
  可以找到剩下要解的單⼀一個
subproblem	
  	
  
2.Greedy-choice property(必須證明最佳解裡⾯面⼀一定有
greedy choice)
3.有optimal substructure (必須證明⼤大問題的最佳解裡
⾯面有⼩小問題的最佳解)
Graphs
EXAMPLE:Weighted graph
A
C
D
F
E
B
G
H
Spanning Tree(⽣生成樹)
Minimum Spanning Tree
A
C
D
F
E
B
G
H
⺫⽬目的:移除weighted graph中的部份邊線,使得⼦子圖仍然
保持連通性,且邊線weight總和為最⼩小
權重最⼩小的⽣生成樹就是最⼩小⽣生成樹
Application
Optimal substructure
• ⼀一、兩棵 MST ,要合併成⼀一棵 MST 時,以兩棵 MST 之間權重最⼩小
的邊進⾏行連結,當然會是最好的。
• ⼆二、三棵 MST ,要合併成⼀一棵 MST 時,先連結其中兩棵連結權重
最⼩小的 MST ,然後才連結第三棵,總是⽐比較好。
• 三、⼀一個單獨的點,可以視作⼀一棵 MST 。
• 由以上三點,可以歸納出⼀一個 greedy 演算法:以權重最⼩小的邊連結
各棵 MST ,⼀一定⽐比較好。
Optimal substructure
MST T
Optimal substructure
MST T
Remove any edge (u,v) ∈ T
Optimal substructure
MST T
Remove any edge (u,v) ∈ T. Then it is partitioned into two
subtrees T1 and T2
T1
T2
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
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
–Greedy Agorithm
Greedy-choice property"
A locally optimal choice is globally optimal
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.
Proof of theorem
Consider the unique simple path from u to v in T
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
Proof of theorem
A lighter-weight spanning tree than T results.
Proving that greedy choice is good enough.
Prim’s Algorithm
Prim’s Algorithm
Use Priority Queue
Prim’s Algorithm
• 增加節點的觀念做為出發點。
• ⾸首先以某⼀一節點當作出發點,在與其相連且
尚未被選取的節點裡,選擇權重最⼩小的邊,
將新的節點加⼊入。
• 如此重覆加⼊入新節點,直到增加了n - 1條邊
為⽌止。(假設有 n 個節點)
Greedy minimum spanning tree- prim's algorithm
Greedy minimum spanning tree- prim's algorithm
Greedy minimum spanning tree- prim's algorithm
Greedy minimum spanning tree- prim's algorithm
Greedy minimum spanning tree- prim's algorithm
Greedy minimum spanning tree- prim's algorithm
Greedy minimum spanning tree- prim's algorithm

More Related Content

What's hot (20)

PPT
Limits
sarcia
 
PPTX
Pigeonhole Principle,Cardinality,Countability
Kiran Munir
 
PPT
Paper
khbsharat
 
PPTX
Limits and their applications
Haroun Elmir
 
PPT
Limit and continuity
Digvijaysinh Gohil
 
PPT
Lar calc10 ch01_sec4
Institute of Applied Technology
 
PDF
Ultra-efficient algorithms for testing well-parenthesised expressions by Tati...
Paris Women in Machine Learning and Data Science
 
PDF
Dataflow Analysis
Miller Lee
 
PDF
Day 8b examples
jchartiersjsd
 
PPT
Lecture 15 max min - section 4.2
njit-ronbrown
 
PPT
Limits And Derivative
Ashams kurian
 
PDF
Midterm I Review
Matthew Leingang
 
PDF
Argumentation in Artificial Intelligence: From Theory to Practice
Federico Cerutti
 
PDF
Special Elements of a Ternary Semiring
IJERA Editor
 
DOCX
Chapter 3
Eka Puspita Sari
 
PPT
Limits
admercano101
 
PPTX
Limits of functions
Louie Joy Rosit
 
PDF
The Fundamental theorem of calculus
AhsanIrshad8
 
PPTX
Recursion DM
Rokonuzzaman Rony
 
PPTX
Huffman analysis
Abubakar Sultan
 
Limits
sarcia
 
Pigeonhole Principle,Cardinality,Countability
Kiran Munir
 
Paper
khbsharat
 
Limits and their applications
Haroun Elmir
 
Limit and continuity
Digvijaysinh Gohil
 
Lar calc10 ch01_sec4
Institute of Applied Technology
 
Ultra-efficient algorithms for testing well-parenthesised expressions by Tati...
Paris Women in Machine Learning and Data Science
 
Dataflow Analysis
Miller Lee
 
Day 8b examples
jchartiersjsd
 
Lecture 15 max min - section 4.2
njit-ronbrown
 
Limits And Derivative
Ashams kurian
 
Midterm I Review
Matthew Leingang
 
Argumentation in Artificial Intelligence: From Theory to Practice
Federico Cerutti
 
Special Elements of a Ternary Semiring
IJERA Editor
 
Chapter 3
Eka Puspita Sari
 
Limits
admercano101
 
Limits of functions
Louie Joy Rosit
 
The Fundamental theorem of calculus
AhsanIrshad8
 
Recursion DM
Rokonuzzaman Rony
 
Huffman analysis
Abubakar Sultan
 

Viewers also liked (20)

PDF
Prims Algorithm
Sriram Raj
 
PPT
Prim's Algorithm on minimum spanning tree
oneous
 
PPT
Minimum spanning tree
Hinal Lunagariya
 
PPT
ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra
Sahil Kumar
 
PPT
Kruskals prims shared by: geekssay.com
Hemant Gautam
 
PPTX
A presentation on prim's and kruskal's algorithm
Gaurav Kolekar
 
PDF
Prim algorithm
University of Potsdam
 
PPTX
Kruskal & Prim's Algorithm
Ifad Rahman
 
PPTX
Minimum Spanning Tree
zhaokatherine
 
PPTX
Kruskal Algorithm
Snehasis Panigrahi
 
DOC
Interviewtcs
Sriram Raj
 
PPT
Mst(engl)
yliu8698
 
PPT
minimum spanning trees Algorithm
sachin varun
 
PPTX
Linkers
Rahul Dhiman
 
PPT
Prim Algorithm and kruskal algorithm
Acad
 
PPT
Linkers
Koganti Ravikumar
 
PPTX
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
Madhu Bala
 
PPT
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Mohanlal Sukhadia University (MLSU)
 
PPT
9 cm402.18
myrajendra
 
PPT
Minimum spanning tree
Tanmay Baranwal
 
Prims Algorithm
Sriram Raj
 
Prim's Algorithm on minimum spanning tree
oneous
 
Minimum spanning tree
Hinal Lunagariya
 
ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra
Sahil Kumar
 
Kruskals prims shared by: geekssay.com
Hemant Gautam
 
A presentation on prim's and kruskal's algorithm
Gaurav Kolekar
 
Prim algorithm
University of Potsdam
 
Kruskal & Prim's Algorithm
Ifad Rahman
 
Minimum Spanning Tree
zhaokatherine
 
Kruskal Algorithm
Snehasis Panigrahi
 
Interviewtcs
Sriram Raj
 
Mst(engl)
yliu8698
 
minimum spanning trees Algorithm
sachin varun
 
Linkers
Rahul Dhiman
 
Prim Algorithm and kruskal algorithm
Acad
 
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
Madhu Bala
 
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Mohanlal Sukhadia University (MLSU)
 
9 cm402.18
myrajendra
 
Minimum spanning tree
Tanmay Baranwal
 
Ad

Similar to Greedy minimum spanning tree- prim's algorithm (20)

PPT
Approx
guest0264d3b
 
PPT
test pre
farazch
 
PPT
3 Greedy-lec.pptggggghhhhhhhyyyyyyyyyyyyyy
esraelman182
 
PPTX
Introduction to dynamic programming
Amisha Narsingani
 
PPTX
Dynamic programmng2
debolina13
 
PPTX
Undecidable Problems and Approximation Algorithms
Muthu Vinayagam
 
PPTX
DYNAMIC PROGRAMMING AND GREEDY TECHNIQUE
ssusered62011
 
PDF
Shortest Path Problem
Guillaume Guérard
 
PPTX
DAA UNIT 3
Dr. SURBHI SAROHA
 
PPT
Greedy Algorithms Chapter for new students 4.ppt
AKBARABBAS11
 
PPTX
Graph Traversal Algorithms - Breadth First Search
Amrinder Arora
 
PPT
Greedy algorithm pptxe file for computer
kerimu1235
 
PPTX
Minimum Spanning Tree using Kruskal's Algorithm
Mrunal Patil
 
PPTX
Presentation of daa on approximation algorithm and vertex cover problem
sumit gyawali
 
PDF
Review
cyberkushal
 
PDF
Algorithm review
chidabdu
 
PDF
4optmizationtechniques-150308051251-conversion-gate01.pdf
BechanYadav4
 
PPTX
Optmization techniques
Deepshika Reddy
 
PDF
optmizationtechniques.pdf
SantiagoGarridoBulln
 
PDF
Analysis and Design of Algorithms notes
Prof. Dr. K. Adisesha
 
Approx
guest0264d3b
 
test pre
farazch
 
3 Greedy-lec.pptggggghhhhhhhyyyyyyyyyyyyyy
esraelman182
 
Introduction to dynamic programming
Amisha Narsingani
 
Dynamic programmng2
debolina13
 
Undecidable Problems and Approximation Algorithms
Muthu Vinayagam
 
DYNAMIC PROGRAMMING AND GREEDY TECHNIQUE
ssusered62011
 
Shortest Path Problem
Guillaume Guérard
 
DAA UNIT 3
Dr. SURBHI SAROHA
 
Greedy Algorithms Chapter for new students 4.ppt
AKBARABBAS11
 
Graph Traversal Algorithms - Breadth First Search
Amrinder Arora
 
Greedy algorithm pptxe file for computer
kerimu1235
 
Minimum Spanning Tree using Kruskal's Algorithm
Mrunal Patil
 
Presentation of daa on approximation algorithm and vertex cover problem
sumit gyawali
 
Review
cyberkushal
 
Algorithm review
chidabdu
 
4optmizationtechniques-150308051251-conversion-gate01.pdf
BechanYadav4
 
Optmization techniques
Deepshika Reddy
 
optmizationtechniques.pdf
SantiagoGarridoBulln
 
Analysis and Design of Algorithms notes
Prof. Dr. K. Adisesha
 
Ad

More from Department of Information Management Ming Chuan University, Taiwan (9)

Recently uploaded (20)

PPTX
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
PPTX
MobileComputingMANET2023 MobileComputingMANET2023.pptx
masterfake98765
 
PPTX
265587293-NFPA 101 Life safety code-PPT-1.pptx
chandermwason
 
PPTX
site survey architecture student B.arch.
sri02032006
 
PDF
MOBILE AND WEB BASED REMOTE BUSINESS MONITORING SYSTEM
ijait
 
PDF
6th International Conference on Machine Learning Techniques and Data Science ...
ijistjournal
 
PPTX
Hashing Introduction , hash functions and techniques
sailajam21
 
PDF
Ethics and Trustworthy AI in Healthcare – Governing Sensitive Data, Profiling...
AlqualsaDIResearchGr
 
PPTX
Thermal runway and thermal stability.pptx
godow93766
 
PPTX
REINFORCEMENT AS CONSTRUCTION MATERIALS.pptx
mohaiminulhaquesami
 
PPT
Oxygen Co2 Transport in the Lungs(Exchange og gases)
SUNDERLINSHIBUD
 
PPTX
Pharmaceuticals and fine chemicals.pptxx
jaypa242004
 
PDF
Water Design_Manual_2005. KENYA FOR WASTER SUPPLY AND SEWERAGE
DancanNgutuku
 
DOCX
8th International Conference on Electrical Engineering (ELEN 2025)
elelijjournal653
 
PDF
POWER PLANT ENGINEERING (R17A0326).pdf..
haneefachosa123
 
PPTX
Types of Bearing_Specifications_PPT.pptx
PranjulAgrahariAkash
 
PDF
Unified_Cloud_Comm_Presentation anil singh ppt
anilsingh298751
 
PPTX
Introduction to Neural Networks and Perceptron Learning Algorithm.pptx
Kayalvizhi A
 
PPTX
Presentation on Foundation Design for Civil Engineers.pptx
KamalKhan563106
 
PPTX
Structural Functiona theory this important for the theorist
cagumaydanny26
 
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
MobileComputingMANET2023 MobileComputingMANET2023.pptx
masterfake98765
 
265587293-NFPA 101 Life safety code-PPT-1.pptx
chandermwason
 
site survey architecture student B.arch.
sri02032006
 
MOBILE AND WEB BASED REMOTE BUSINESS MONITORING SYSTEM
ijait
 
6th International Conference on Machine Learning Techniques and Data Science ...
ijistjournal
 
Hashing Introduction , hash functions and techniques
sailajam21
 
Ethics and Trustworthy AI in Healthcare – Governing Sensitive Data, Profiling...
AlqualsaDIResearchGr
 
Thermal runway and thermal stability.pptx
godow93766
 
REINFORCEMENT AS CONSTRUCTION MATERIALS.pptx
mohaiminulhaquesami
 
Oxygen Co2 Transport in the Lungs(Exchange og gases)
SUNDERLINSHIBUD
 
Pharmaceuticals and fine chemicals.pptxx
jaypa242004
 
Water Design_Manual_2005. KENYA FOR WASTER SUPPLY AND SEWERAGE
DancanNgutuku
 
8th International Conference on Electrical Engineering (ELEN 2025)
elelijjournal653
 
POWER PLANT ENGINEERING (R17A0326).pdf..
haneefachosa123
 
Types of Bearing_Specifications_PPT.pptx
PranjulAgrahariAkash
 
Unified_Cloud_Comm_Presentation anil singh ppt
anilsingh298751
 
Introduction to Neural Networks and Perceptron Learning Algorithm.pptx
Kayalvizhi A
 
Presentation on Foundation Design for Civil Engineers.pptx
KamalKhan563106
 
Structural Functiona theory this important for the theorist
cagumaydanny26
 

Greedy minimum spanning tree- prim's algorithm