next up previous
Next: Pseudocode Up: CSE 2320: Algorithms and Previous: Corollary 24.2

Prim's Algorithm

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


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

Copyright © 1998 The University of Texas at Arlington