SlideShare ist ein Scribd-Unternehmen logo
1 von 29
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

Limits
LimitsLimits
Limits
sarcia
 
Dataflow Analysis
Dataflow AnalysisDataflow Analysis
Dataflow Analysis
Miller Lee
 

Was ist angesagt? (20)

Limits
LimitsLimits
Limits
 
Pigeonhole Principle,Cardinality,Countability
Pigeonhole Principle,Cardinality,CountabilityPigeonhole Principle,Cardinality,Countability
Pigeonhole Principle,Cardinality,Countability
 
Paper
PaperPaper
Paper
 
Limits and their applications
Limits and their applicationsLimits and their applications
Limits and their applications
 
Limit and continuity
Limit and continuityLimit and continuity
Limit and continuity
 
Lar calc10 ch01_sec4
Lar calc10 ch01_sec4Lar calc10 ch01_sec4
Lar calc10 ch01_sec4
 
Ultra-efficient algorithms for testing well-parenthesised expressions by Tati...
Ultra-efficient algorithms for testing well-parenthesised expressions by Tati...Ultra-efficient algorithms for testing well-parenthesised expressions by Tati...
Ultra-efficient algorithms for testing well-parenthesised expressions by Tati...
 
Dataflow Analysis
Dataflow AnalysisDataflow Analysis
Dataflow Analysis
 
Day 8b examples
Day 8b examplesDay 8b examples
Day 8b examples
 
Lecture 15 max min - section 4.2
Lecture 15   max min - section 4.2Lecture 15   max min - section 4.2
Lecture 15 max min - section 4.2
 
Limits And Derivative
Limits And DerivativeLimits And Derivative
Limits And Derivative
 
Midterm I Review
Midterm I ReviewMidterm I Review
Midterm I Review
 
Argumentation in Artificial Intelligence: From Theory to Practice
Argumentation in Artificial Intelligence: From Theory to PracticeArgumentation in Artificial Intelligence: From Theory to Practice
Argumentation in Artificial Intelligence: From Theory to Practice
 
Special Elements of a Ternary Semiring
Special Elements of a Ternary SemiringSpecial Elements of a Ternary Semiring
Special Elements of a Ternary Semiring
 
Chapter 3
Chapter 3Chapter 3
Chapter 3
 
Limits
LimitsLimits
Limits
 
Limits of functions
Limits of functionsLimits of functions
Limits of functions
 
The Fundamental theorem of calculus
The Fundamental theorem of calculus The Fundamental theorem of calculus
The Fundamental theorem of calculus
 
Recursion DM
Recursion DMRecursion DM
Recursion DM
 
Huffman analysis
Huffman analysisHuffman analysis
Huffman analysis
 

Andere mochten auch

Prims Algorithm
Prims AlgorithmPrims Algorithm
Prims Algorithm
Sriram Raj
 
Minimum Spanning Tree
Minimum Spanning TreeMinimum Spanning Tree
Minimum Spanning Tree
zhaokatherine
 

Andere mochten auch (20)

Prims Algorithm
Prims AlgorithmPrims Algorithm
Prims Algorithm
 
Prim's Algorithm on minimum spanning tree
Prim's Algorithm on minimum spanning treePrim's Algorithm on minimum spanning tree
Prim's Algorithm on minimum spanning tree
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
 
ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra
ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra
ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra
 
Kruskals prims shared by: geekssay.com
Kruskals prims shared by: geekssay.comKruskals prims shared by: geekssay.com
Kruskals prims shared by: geekssay.com
 
A presentation on prim's and kruskal's algorithm
A presentation on prim's and kruskal's algorithmA presentation on prim's and kruskal's algorithm
A presentation on prim's and kruskal's algorithm
 
Prim algorithm
Prim algorithmPrim algorithm
Prim algorithm
 
Kruskal & Prim's Algorithm
Kruskal & Prim's AlgorithmKruskal & Prim's Algorithm
Kruskal & Prim's Algorithm
 
Minimum Spanning Tree
Minimum Spanning TreeMinimum Spanning Tree
Minimum Spanning Tree
 
Kruskal Algorithm
Kruskal AlgorithmKruskal Algorithm
Kruskal Algorithm
 
Interviewtcs
InterviewtcsInterviewtcs
Interviewtcs
 
Mst(engl)
Mst(engl)Mst(engl)
Mst(engl)
 
minimum spanning trees Algorithm
minimum spanning trees Algorithm minimum spanning trees Algorithm
minimum spanning trees Algorithm
 
Linkers
LinkersLinkers
Linkers
 
Prim Algorithm and kruskal algorithm
Prim Algorithm and kruskal algorithmPrim Algorithm and kruskal algorithm
Prim Algorithm and kruskal algorithm
 
Linkers
LinkersLinkers
Linkers
 
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
 
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
 
9 cm402.18
9 cm402.189 cm402.18
9 cm402.18
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
 

Ähnlich wie Greedy minimum spanning tree- prim's algorithm

Algorithm review
Algorithm reviewAlgorithm review
Algorithm review
chidabdu
 
4optmizationtechniques-150308051251-conversion-gate01.pdf
4optmizationtechniques-150308051251-conversion-gate01.pdf4optmizationtechniques-150308051251-conversion-gate01.pdf
4optmizationtechniques-150308051251-conversion-gate01.pdf
BechanYadav4
 

Ähnlich wie Greedy minimum spanning tree- prim's algorithm (20)

Approx
ApproxApprox
Approx
 
test pre
test pretest pre
test pre
 
Introduction to dynamic programming
Introduction to dynamic programmingIntroduction to dynamic programming
Introduction to dynamic programming
 
Dynamic programmng2
Dynamic programmng2Dynamic programmng2
Dynamic programmng2
 
Undecidable Problems and Approximation Algorithms
Undecidable Problems and Approximation AlgorithmsUndecidable Problems and Approximation Algorithms
Undecidable Problems and Approximation Algorithms
 
Shortest Path Problem
Shortest Path ProblemShortest Path Problem
Shortest Path Problem
 
DAA UNIT 3
DAA UNIT 3DAA UNIT 3
DAA UNIT 3
 
Graph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First SearchGraph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First Search
 
Greedy algorithm pptxe file for computer
Greedy algorithm pptxe file for computerGreedy algorithm pptxe file for computer
Greedy algorithm pptxe file for computer
 
Minimum Spanning Tree using Kruskal's Algorithm
Minimum Spanning Tree using Kruskal's Algorithm Minimum Spanning Tree using Kruskal's Algorithm
Minimum Spanning Tree using Kruskal's Algorithm
 
Presentation of daa on approximation algorithm and vertex cover problem
Presentation of daa on approximation algorithm and vertex cover problem Presentation of daa on approximation algorithm and vertex cover problem
Presentation of daa on approximation algorithm and vertex cover problem
 
Review
ReviewReview
Review
 
Algorithm review
Algorithm reviewAlgorithm review
Algorithm review
 
4optmizationtechniques-150308051251-conversion-gate01.pdf
4optmizationtechniques-150308051251-conversion-gate01.pdf4optmizationtechniques-150308051251-conversion-gate01.pdf
4optmizationtechniques-150308051251-conversion-gate01.pdf
 
Optmization techniques
Optmization techniquesOptmization techniques
Optmization techniques
 
optmizationtechniques.pdf
optmizationtechniques.pdfoptmizationtechniques.pdf
optmizationtechniques.pdf
 
Analysis and Design of Algorithms notes
Analysis and Design of Algorithms  notesAnalysis and Design of Algorithms  notes
Analysis and Design of Algorithms notes
 
A Regularized Simplex Method
A Regularized Simplex MethodA Regularized Simplex Method
A Regularized Simplex Method
 
Greedy Algorithms
Greedy AlgorithmsGreedy Algorithms
Greedy Algorithms
 
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWERUndecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
 

Mehr von Department of Information Management Ming Chuan University, Taiwan (9)

Android googlemapv2 keyApplicance
Android googlemapv2 keyApplicanceAndroid googlemapv2 keyApplicance
Android googlemapv2 keyApplicance
 
Dynamic programming lcs
Dynamic programming lcsDynamic programming lcs
Dynamic programming lcs
 
類神經網路
類神經網路類神經網路
類神經網路
 
Examining the impact of rich media on consumer willingness to pay in online ...
Examining the impact of rich media  on consumer willingness to pay in online ...Examining the impact of rich media  on consumer willingness to pay in online ...
Examining the impact of rich media on consumer willingness to pay in online ...
 
How online social ties and product-related risks influence purchase intention...
How online social ties and product-related risks influence purchase intention...How online social ties and product-related risks influence purchase intention...
How online social ties and product-related risks influence purchase intention...
 
Android google mapv2
Android google mapv2Android google mapv2
Android google mapv2
 
No sql
No sqlNo sql
No sql
 
Page rank
Page rankPage rank
Page rank
 
Semantic web
Semantic webSemantic web
Semantic web
 

Kürzlich hochgeladen

notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
MsecMca
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
HenryBriggs2
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
mphochane1998
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 

Kürzlich hochgeladen (20)

2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Air Compressor reciprocating single stage
Air Compressor reciprocating single stageAir Compressor reciprocating single stage
Air Compressor reciprocating single stage
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
 

Greedy minimum spanning tree- prim's algorithm