Despite this, the description of the algorithm allows us to construct
a shortest path very simply. Whenever the value of
is changed,
either by being defined for the first time in D3(c),
or by being reduced in D3(d), it happens when
is
adjacent to some node
for which we have just determined the
minimum distance. If, at each stage
is changed, we record the
to which it was adjacent at the time, then when
is finally
brought into
we shall have recorded a final ``previous'' node for
. If we trace these previous nodes back one by one, we shall
finally arrive at
, and this will provide a path of shortest
length. This is not obvious, and the braver of you may like to
construct a proper proof along the lines above.
It may seem as though this procedure gives a unique shortest path. It
does, to the extent that the order in which nodes are brought into
is unique. But this is not generally unique, because if there are
multiple paths of shortest length, at some stage we shall have to make
an arbitrary choice in D1.