Prims Algorithm: Difference between revisions
From Rice Wiki
(Created page with " Category:Algorithms") |
No edit summary |
||
Line 1: | Line 1: | ||
= Implementation = | |||
<pre> | |||
for each u in V: | |||
key[u] = infinity // cost array | |||
pi[u] = infinity // from array | |||
Q = new PriorityQueue(V) | |||
key[root] = 0 | |||
while Q is not empty: | |||
u = extractMin(Q) | |||
# Reduce nodes | |||
for v in adj[u]: | |||
if v in Q and w[u,v] < key[v]: | |||
key[v] = w[u,v] | |||
</pre> | |||
[[Category:Algorithms]] | [[Category:Algorithms]] |
Revision as of 01:47, 6 March 2024
Implementation
for each u in V: key[u] = infinity // cost array pi[u] = infinity // from array Q = new PriorityQueue(V) key[root] = 0 while Q is not empty: u = extractMin(Q) # Reduce nodes for v in adj[u]: if v in Q and w[u,v] < key[v]: key[v] = w[u,v]