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)

PDF
Chapter IV Algorithm for I3ab Ams at itc
PPT
communication system Chapter 2
PDF
A NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREE
PDF
A NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREE
PPT
Unit27_MinimumSpanningTree.ppt data structure programming
PPTX
8_MST_pptx.pptx
PDF
Fractal dimension versus Computational Complexity
PPTX
DYNAMIC PROGRAMMING AND GREEDY TECHNIQUE
PPTX
Data structure
PDF
torsionbinormalnotes
PDF
Minimum Spanning Trees Artificial Intelligence
PPT
Weighted graphs
PDF
Daa chapter13
PDF
Anlysis and design of algorithms part 1
PDF
Recurrent and Recursive Networks (Part 1)
PDF
Cs6402 daa-2 marks set 1
PDF
Unit3_1.pdf
PDF
2_GLMs_printable.pdf
PPT
analysis.ppt
Chapter IV Algorithm for I3ab Ams at itc
communication system Chapter 2
A NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREE
A NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREE
Unit27_MinimumSpanningTree.ppt data structure programming
8_MST_pptx.pptx
Fractal dimension versus Computational Complexity
DYNAMIC PROGRAMMING AND GREEDY TECHNIQUE
Data structure
torsionbinormalnotes
Minimum Spanning Trees Artificial Intelligence
Weighted graphs
Daa chapter13
Anlysis and design of algorithms part 1
Recurrent and Recursive Networks (Part 1)
Cs6402 daa-2 marks set 1
Unit3_1.pdf
2_GLMs_printable.pdf
analysis.ppt

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
Business Ethics Teaching Materials for college
PDF
Insiders guide to clinical Medicine.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Pharma ospi slides which help in ospi learning
PDF
Complications of Minimal Access Surgery at WLH
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
01-Introduction-to-Information-Management.pdf
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
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Basic Mud Logging Guide for educational purpose
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Business Ethics Teaching Materials for college
Insiders guide to clinical Medicine.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
PPH.pptx obstetrics and gynecology in nursing
Microbial diseases, their pathogenesis and prophylaxis
Pharma ospi slides which help in ospi learning
Complications of Minimal Access Surgery at WLH
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
Supply Chain Operations Speaking Notes -ICLT Program
01-Introduction-to-Information-Management.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 Đ...
Abdominal Access Techniques with Prof. Dr. R K Mishra
O7-L3 Supply Chain Operations - ICLT Program
Anesthesia in Laparoscopic Surgery in India
Basic Mud Logging Guide for educational purpose
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx

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.