Basic structures needed:
T is the empty graph;
PQ is an empty priority queue;
Add s to T; mark s as visited in G;
Add each edge (s,v) of G to PQ with appropriate value
while (T.size() < G.size() and PQ not empty)
do
nextEdge = PQ.removeMin();
until(one vertex of nextEdge is visited and the other is unvisited)
or until there are no more edges in PQ
// assume nextEdge = (v,u) where v is visited (in T) and u is
unvisited (not in T)
Add u to T; mark u as visited in G;
Add (u,v) to T;
for each unvisited neighbor w of u
add (u,w) to PQ with appropriate weight
When the procedure finishes, T should contain all vertices reachable
from s, along with a shortest path from s to each such vertex.
Disclaimer: Many details still need to be considered, but this is the essential information needed to implement the algorithm.
Consider the following graph:
From that graph, the algorithm would construct the following tree for a start node of Williamstown. Costs on edges indicate total cost from the root.
