next up previous
Next: Up: Previous:

Prim's Algorithm

Prim's Algorithm
$\;\;\;\;\;$repeat
$\;\;\;\;\;$ $\;\;\;\;\;$find minimal edge (u,v) connecting A to a vertex not in A
$\;\;\;\;\;$ $\;\;\;\;\;$A = A $\cup$ {(u,v)}
$\;\;\;\;\;$until all vertices are in A



Implementation

Maintain a priority queue Q of vertices of the form

parent points to neighbor vertex in A along smallest edge
key weight of smallest edge
(in Q) true or false

Starting from some root vertex r
Update key and parent slots of vertices on A adjacent to r
Extract minimum-key vertex v from those adjacent to r
r = V


next up previous
Next: Up: Previous: