A way to understand Dijkstra's Algorithm: See panels 49-56 in the Section The idea is ... pick a node, see who's attached ... put unvisited nodes into the PQ based on cost ... visit those nodes The (min) PQ automatically puts the min "element" (node and the cumulative edge cost) first. So, when you do a "get" on the PQ, you're getting the "shortest" path so far. There are number of confusing things... when you pick off a vertex from the PQ, you tag it so that you don't backtrack ("while (PQ still has elements)...". The edges leading away from that element you just got are added to the PQ. The PQ is sorted based the costs so far for each. So... when the outer while loop comes along again, the node(s) you visited are out of the PQ, but all the nodes that were connected to the visited nodes are still inside. Then PQ will give you the next thing to pick, which starts the whole thing over again. The inner loop is the gathering of all "end nodes" for the current node you've visited. One problem I have is that I find this reasoning easier than nearly everyone else... no surprise then that the book I want follows this approach :-) So... you might want to get a different opinion (Weiss). My panel 55 tries to show it. Node also that none of this conversation involves springs or strings or whatnot. But it's the same idea.