Prim’s_Algorithm
Prim’s_Algorithm
Prim’s Algorithm
• It is a greedy algorithm that finds a minimum
spanning tree for a weighted connected and
undirected graph.
Steps:
Step 1: (Consider all the vertices first)
Start with any vertex of the graph.
25
A BB
14
10
12
C
C F G
22
17
23 11
D 20 E
Example:
7
A B 11
E
4 9
3
C D
10
ALGORITHM:
VT ← {v0}
ET ← ∅
for i ← 1 to |V | − 1 do
find a minimum-weight edge e∗ = (v∗, u∗) among all
the edges (v, u)
such that v is in VT and u is in V − VT
VT ← VT ∪ {u∗}
ET ← ET ∪ {e∗}
return ET
APPLICATION: