Prim's Algorithm

1/0
1.0x

Prim's Algorithm

O((V+E) log V)Space: O(V)

Pseudocode

1procedure Prim(graph)
2 key[0] ← 0, key[v] ← ∞ for all other v
3 inMST[] ← false for all vertices
4 while there are vertices not in MST do
5 u ← vertex with minimum key not in MST
6 add u to MST
7 for each neighbor v of u do
8 if v not in MST and weight(u,v) < key[v]
9 key[v] ← weight(u, v)
10 parent[v] ← u
11 return MST edges