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 (9)

PPTX
lec6.pptx
nuredinabdellah2
 
PPTX
Algorithm analysis Greedy method in algorithm.pptx
fekadeab34
 
PPT
algorthm analysis from computer scince.ppt
AbrehamHgiorgis
 
PPT
Unit 5 session 2 MinimumSpanningTrees.ppt
prithivr1
 
PPT
Greedy Approach in Design Analysis and Algorithms
NikunjGoyal20
 
PPTX
My presentation minimum spanning tree
Alona Salva
 
PPTX
DM Min SPan Tree Minimum spanning tree .pptx
mlnagaraju77
 
PDF
Daa chapter13
B.Kirron Reddi
 
PPT
Chapter 24 aoa
Hanif Durad
 
lec6.pptx
nuredinabdellah2
 
Algorithm analysis Greedy method in algorithm.pptx
fekadeab34
 
algorthm analysis from computer scince.ppt
AbrehamHgiorgis
 
Unit 5 session 2 MinimumSpanningTrees.ppt
prithivr1
 
Greedy Approach in Design Analysis and Algorithms
NikunjGoyal20
 
My presentation minimum spanning tree
Alona Salva
 
DM Min SPan Tree Minimum spanning tree .pptx
mlnagaraju77
 
Daa chapter13
B.Kirron Reddi
 
Chapter 24 aoa
Hanif Durad
 
Ad

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

Recently uploaded (20)

PPTX
Work at Height training for workers .pptx
cecos12
 
PDF
تقرير عن التحليل الديناميكي لتدفق الهواء حول جناح.pdf
محمد قصص فتوتة
 
PDF
Generative AI & Scientific Research : Catalyst for Innovation, Ethics & Impact
AlqualsaDIResearchGr
 
PDF
How to Buy Verified CashApp Accounts IN 2025
Buy Verified CashApp Accounts
 
PPTX
CST413 KTU S7 CSE Machine Learning Introduction Parameter Estimation MLE MAP ...
resming1
 
PDF
FSE-Journal-First-Automated code editing with search-generate-modify.pdf
cl144
 
PPTX
Computer network Computer network Computer network Computer network
Shrikant317689
 
PPT
دراسة حاله لقرية تقع في جنوب غرب السودان
محمد قصص فتوتة
 
PDF
Designing for Tomorrow – Architecture’s Role in the Sustainability Movement
BIM Services
 
PDF
May 2025: Top 10 Read Articles in Data Mining & Knowledge Management Process
IJDKP
 
PPTX
Stability of IBR Dominated Grids - IEEE PEDG 2025 - short.pptx
ssuser307730
 
PDF
NFPA 10 - Estandar para extintores de incendios portatiles (ed.22 ENG).pdf
Oscar Orozco
 
PDF
Validating a Citizen Observatories enabling Platform by completing a Citizen ...
Diego López-de-Ipiña González-de-Artaza
 
PPTX
Bharatiya Antariksh Hackathon 2025 Idea Submission PPT.pptx
AsadShad4
 
PPTX
Bharatiya Antariksh Hackathon 2025 Idea Submission PPT.pptx
AsadShad4
 
PPT
SF 9_Unit 1.ppt software engineering ppt
AmarrKannthh
 
PPTX
FSE_LLM4SE1_A Tool for In-depth Analysis of Code Execution Reasoning of Large...
cl144
 
PDF
Rapid Prototyping for XR: Lecture 6 - AI for Prototyping and Research Directi...
Mark Billinghurst
 
PPTX
CST413 KTU S7 CSE Machine Learning Clustering K Means Hierarchical Agglomerat...
resming1
 
PPTX
Introduction to Python Programming Language
merlinjohnsy
 
Work at Height training for workers .pptx
cecos12
 
تقرير عن التحليل الديناميكي لتدفق الهواء حول جناح.pdf
محمد قصص فتوتة
 
Generative AI & Scientific Research : Catalyst for Innovation, Ethics & Impact
AlqualsaDIResearchGr
 
How to Buy Verified CashApp Accounts IN 2025
Buy Verified CashApp Accounts
 
CST413 KTU S7 CSE Machine Learning Introduction Parameter Estimation MLE MAP ...
resming1
 
FSE-Journal-First-Automated code editing with search-generate-modify.pdf
cl144
 
Computer network Computer network Computer network Computer network
Shrikant317689
 
دراسة حاله لقرية تقع في جنوب غرب السودان
محمد قصص فتوتة
 
Designing for Tomorrow – Architecture’s Role in the Sustainability Movement
BIM Services
 
May 2025: Top 10 Read Articles in Data Mining & Knowledge Management Process
IJDKP
 
Stability of IBR Dominated Grids - IEEE PEDG 2025 - short.pptx
ssuser307730
 
NFPA 10 - Estandar para extintores de incendios portatiles (ed.22 ENG).pdf
Oscar Orozco
 
Validating a Citizen Observatories enabling Platform by completing a Citizen ...
Diego López-de-Ipiña González-de-Artaza
 
Bharatiya Antariksh Hackathon 2025 Idea Submission PPT.pptx
AsadShad4
 
Bharatiya Antariksh Hackathon 2025 Idea Submission PPT.pptx
AsadShad4
 
SF 9_Unit 1.ppt software engineering ppt
AmarrKannthh
 
FSE_LLM4SE1_A Tool for In-depth Analysis of Code Execution Reasoning of Large...
cl144
 
Rapid Prototyping for XR: Lecture 6 - AI for Prototyping and Research Directi...
Mark Billinghurst
 
CST413 KTU S7 CSE Machine Learning Clustering K Means Hierarchical Agglomerat...
resming1
 
Introduction to Python Programming Language
merlinjohnsy
 

Greedy minimum spanning tree- prim's algorithm