Prim's algorithm
Procedure
MST-PRIM(G, w, r)
for each u ∈ G.V
u.key = ∞
u.π = NIL
r.key = 0
Q = G.V
while Q != ∅:
u = EXTRACT-MIN(Q)
for each v ∈ G.Adj[u]
if v ∈ Q and w(u, v) < v.key
v.π = u
v.key = w(u, v)
Reference(s)
- T. H. Cormen, C. E. Leiserson, R. L. Rivest and C. Stein, Introduction to Algorithms, 3rd ed. Cambridge, MA: The MIT Press, 2009.