SlideShare a Scribd company logo
Prim’s Algorithm
We consider a weighted connected graph G with n vertices. Prim’s algorithm finds a
minimum spanning tree of G.
procedure Prim(G: weighted connected graph with n vertices)
T := a minimum-weight edge
for i = 1 to n − 2
begin
e := an edge of minimum weight incident to a vertex in T and not forming a circuit
in T if added to T
T := T with e added
end
return(T)
Example: Use Prim’s algorithm to find a minimum spanning tree in the following
weighted graph. Use alphabetical order to break ties.
r.
....................................................................................................................................................................................................
r
.
....................................................................................................................................................................................................
r. ............................................................................................................................................................................................................................................................ r
. ............................................................................................................................................................................................................................................................ r.
....................................................................................................................................................................................................
r
.
.....................................................................................................................................................................................................
........................................................................................................................................................................
.
...................................................................................................................................................................................................................................................................................................................
.
........................................................................................................................................................................
a z
c e
b d
3 4
3
2
2 2
5
16
Solution: Prim’s algorithm will proceed as follows. First we add edge {d, e} of weight
1. Next, we add edge {c, e} of weight 2. Next, we add edge {d, z} of weight 2. Next, we
add edge {b, e} of weight 3. And finally, we add edge {a, b} of weight 2. This produces
a minimum spanning tree of weight 10. A minimum spanning tree is the following.
r.
....................................................................................................................................................................................................
r
r. ............................................................................................................................................................................................................................................................ r
r.
....................................................................................................................................................................................................
r
.
........................................................................................................................................................................
.
...................................................................................................................................................................................................................................................................................................................
a z
c e
b d
3
2
2 2
1
Gilles Cazelais. Typeset with LATEX on December 6, 2006.

More Related Content

PPT
ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra
PPT
minimum spanning trees Algorithm
PPT
KRUSKAL'S algorithm from chaitra
PDF
Minimum spanning tree
PDF
Treewidth and Applications
PPTX
Minimum spanning tree algorithms by ibrahim_alfayoumi
PDF
Paths and Polynomials
PDF
Iterative Compression
ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra
minimum spanning trees Algorithm
KRUSKAL'S algorithm from chaitra
Minimum spanning tree
Treewidth and Applications
Minimum spanning tree algorithms by ibrahim_alfayoumi
Paths and Polynomials
Iterative Compression

What's hot (20)

PPTX
Prims & kruskal algorithms
PDF
Bidimensionality
PDF
Important Cuts and (p,q)-clustering
PPTX
Minimum spanning tree
PDF
19 Minimum Spanning Trees
PDF
Brief summary of signals
PPT
Spanning trees
PDF
The Exponential Time Hypothesis
PPTX
Kruskal Algorithm
PPTX
Statistical Physics Assignment Help
PPTX
My presentation minimum spanning tree
PPTX
Merge sort and quick sort
PPTX
Signals Processing Assignment Help
PDF
Important Cuts
PPTX
Algorithm - Mergesort & Quicksort
PPTX
Chemistry Assignment Help
PPT
Chapter 8 Root Locus Techniques
PDF
2-rankings of Graphs
PDF
Topological sorting
PDF
Dynamic Programming Over Graphs of Bounded Treewidth
Prims & kruskal algorithms
Bidimensionality
Important Cuts and (p,q)-clustering
Minimum spanning tree
19 Minimum Spanning Trees
Brief summary of signals
Spanning trees
The Exponential Time Hypothesis
Kruskal Algorithm
Statistical Physics Assignment Help
My presentation minimum spanning tree
Merge sort and quick sort
Signals Processing Assignment Help
Important Cuts
Algorithm - Mergesort & Quicksort
Chemistry Assignment Help
Chapter 8 Root Locus Techniques
2-rankings of Graphs
Topological sorting
Dynamic Programming Over Graphs of Bounded Treewidth
Ad

Viewers also liked (20)

PDF
Prims Algorithm
PPT
Prim's Algorithm on minimum spanning tree
PDF
Greedy minimum spanning tree- prim's algorithm
PPTX
A presentation on prim's and kruskal's algorithm
DOC
Interviewtcs
PPT
Kruskals prims shared by: geekssay.com
PPT
Prim Algorithm and kruskal algorithm
PPTX
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
PPT
03 algorithm properties
PPTX
Kruskal & Prim's Algorithm
PPT
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
PPT
9 cm402.18
PPT
Minimum spanning tree
PPT
Minimum spanning tree
PPTX
Matrix multiplication
PPTX
Minimum Spanning Tree
PPT
Greedymethod
PPTX
Prim's algorithm
PPTX
Kruskal Algorithm
PDF
Origenes de la prensa leonesa
Prims Algorithm
Prim's Algorithm on minimum spanning tree
Greedy minimum spanning tree- prim's algorithm
A presentation on prim's and kruskal's algorithm
Interviewtcs
Kruskals prims shared by: geekssay.com
Prim Algorithm and kruskal algorithm
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
03 algorithm properties
Kruskal & Prim's Algorithm
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
9 cm402.18
Minimum spanning tree
Minimum spanning tree
Matrix multiplication
Minimum Spanning Tree
Greedymethod
Prim's algorithm
Kruskal Algorithm
Origenes de la prensa leonesa
Ad

Similar to Prim algorithm (20)

PPTX
11L_2024_DSCS_EN_Trees2_Prim_Kraskal.pptx
PPTX
Data Algorithms And Analysis
PPTX
Grady approach prim's spanning tree
PPT
Unit27_MinimumSpanningTree.ppt data structure programming
PPTX
Prim's Algorithm Presentation for prims algorithm (1).pptx
PDF
minimum spanning tree from wangshusen2.pdf
PPTX
Decision Maths 1 Chapter 3 Algorithms on Graphs (including Floyd A2 content)....
PDF
Skiena algorithm 2007 lecture13 minimum spanning trees
PPTX
Lecture 5.2 - 6.1 MINIMUM SPANNING TREE.pptx
PPT
Minimum Spanning Tree
PDF
DATA STRUCTURES & ALGORITHMS MINIMUM SPANNING TREE
PPTX
Minimum Spanning Tree.pptx
PDF
Topological Sort
PPTX
Dijkstra’s Algorithm and Prim’s Algorithm in Graph Theory and Combinatorics
PPTX
lec6.pptx
PPTX
_A C program for Prim's Minimum Spanning Tree (MST) algorithm. The program is...
PPT
Greedy Algorithms Chapter for new students 4.ppt
PPTX
Greedy technique - Algorithm design techniques using data structures
PPTX
7. Spanning trees
11L_2024_DSCS_EN_Trees2_Prim_Kraskal.pptx
Data Algorithms And Analysis
Grady approach prim's spanning tree
Unit27_MinimumSpanningTree.ppt data structure programming
Prim's Algorithm Presentation for prims algorithm (1).pptx
minimum spanning tree from wangshusen2.pdf
Decision Maths 1 Chapter 3 Algorithms on Graphs (including Floyd A2 content)....
Skiena algorithm 2007 lecture13 minimum spanning trees
Lecture 5.2 - 6.1 MINIMUM SPANNING TREE.pptx
Minimum Spanning Tree
DATA STRUCTURES & ALGORITHMS MINIMUM SPANNING TREE
Minimum Spanning Tree.pptx
Topological Sort
Dijkstra’s Algorithm and Prim’s Algorithm in Graph Theory and Combinatorics
lec6.pptx
_A C program for Prim's Minimum Spanning Tree (MST) algorithm. The program is...
Greedy Algorithms Chapter for new students 4.ppt
Greedy technique - Algorithm design techniques using data structures
7. Spanning trees

More from University of Potsdam (20)

PPTX
Computer fundamentals 01
PPTX
Workshop on android apps development
PDF
Transparency and concurrency
PDF
Database System Architecture
PDF
Functional dependency and normalization
PDF
indexing and hashing
PDF
data recovery-raid
PDF
Query processing
PDF
Machine Learning for Data Mining
PPTX
Tree, function and graph
PDF
Sets in discrete mathematics
PPT
Set in discrete mathematics
PPT
Series parallel ac rlc networks
PPT
Series parallel ac networks
PPT
PDF
PPT
Propositional logic
PDF
Propositional logic
PPT
Predicate & quantifier
Computer fundamentals 01
Workshop on android apps development
Transparency and concurrency
Database System Architecture
Functional dependency and normalization
indexing and hashing
data recovery-raid
Query processing
Machine Learning for Data Mining
Tree, function and graph
Sets in discrete mathematics
Set in discrete mathematics
Series parallel ac rlc networks
Series parallel ac networks
Propositional logic
Propositional logic
Predicate & quantifier

Recently uploaded (20)

PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Introduction and Scope of Bichemistry.pptx
PPTX
Open Quiz Monsoon Mind Game Final Set.pptx
PPTX
NOI Hackathon - Summer Edition - GreenThumber.pptx
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Insiders guide to clinical Medicine.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Open Quiz Monsoon Mind Game Prelims.pptx
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
English Language Teaching from Post-.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
STATICS OF THE RIGID BODIES Hibbelers.pdf
Microbial disease of the cardiovascular and lymphatic systems
Introduction and Scope of Bichemistry.pptx
Open Quiz Monsoon Mind Game Final Set.pptx
NOI Hackathon - Summer Edition - GreenThumber.pptx
Week 4 Term 3 Study Techniques revisited.pptx
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Insiders guide to clinical Medicine.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Open Quiz Monsoon Mind Game Prelims.pptx
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Microbial diseases, their pathogenesis and prophylaxis
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
TR - Agricultural Crops Production NC III.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
English Language Teaching from Post-.pdf

Prim algorithm

  • 1. Prim’s Algorithm We consider a weighted connected graph G with n vertices. Prim’s algorithm finds a minimum spanning tree of G. procedure Prim(G: weighted connected graph with n vertices) T := a minimum-weight edge for i = 1 to n − 2 begin e := an edge of minimum weight incident to a vertex in T and not forming a circuit in T if added to T T := T with e added end return(T) Example: Use Prim’s algorithm to find a minimum spanning tree in the following weighted graph. Use alphabetical order to break ties. r. .................................................................................................................................................................................................... r . .................................................................................................................................................................................................... r. ............................................................................................................................................................................................................................................................ r . ............................................................................................................................................................................................................................................................ r. .................................................................................................................................................................................................... r . ..................................................................................................................................................................................................... ........................................................................................................................................................................ . ................................................................................................................................................................................................................................................................................................................... . ........................................................................................................................................................................ a z c e b d 3 4 3 2 2 2 5 16 Solution: Prim’s algorithm will proceed as follows. First we add edge {d, e} of weight 1. Next, we add edge {c, e} of weight 2. Next, we add edge {d, z} of weight 2. Next, we add edge {b, e} of weight 3. And finally, we add edge {a, b} of weight 2. This produces a minimum spanning tree of weight 10. A minimum spanning tree is the following. r. .................................................................................................................................................................................................... r r. ............................................................................................................................................................................................................................................................ r r. .................................................................................................................................................................................................... r . ........................................................................................................................................................................ . ................................................................................................................................................................................................................................................................................................................... a z c e b d 3 2 2 2 1 Gilles Cazelais. Typeset with LATEX on December 6, 2006.