The only paths starting with a are a,b and a,d with lengths 4 and 2, respectively; d is the closest
vertex to a.
To find the next closest vertex to a, we look at all the paths going through a or d.
One
path a,d,e has a length of 5; another a,b (which goes through a) has a length of 4.
So, d is the closest
vertex to a, and b is the next closest, and then e.
To find the third closest vertex to a, we have to
examine the paths that go through a, b, d, or e.
There is a path of length 7 to c; another path of
length 7 to e, and a path of length 6 to z.
Consequently, z is the next closest vertex to a along the
path a, d, e, z.
We have found the length of the shortest path.
Now, we need to formalize this strategy into an algorithm. Assume the following: we have a
weighted, connected simple graph, with all the weights positive (you will see that this is a necessity
because the algorithm assumes a building up of path lengths as we proceed).
This graph G has
vertex set {v
0
, v
1
, v
2
...} where v
0
= a, the starting vertex for the path, and v
n
= z, the terminating
vertex for the path.
Weights are stored in a 2-dim array where w(v
i
, v
j
) = an integer if there is an
edge between v
i
and v
j
, and ∞ otherwise.
An array L[1.
..n] (an entry for each vertex) will keep
track of the path lengths as we process.
This array is initialized to ∞ for all entries except the