Dijkstra
Dijkstra
Recall that Dijkstra’s algorithm finds the length of all the shortest paths
in a directed graph with non-negative weights on the edges, from a source
vertex s to every other vertex vi in the graph.
∀vi ∈ S, ∀vj ∈ V − S, di ≤ dj
dest
j = min di + w(ei,j )
vi ∈S
Lemma 1 The estimated distance to dest j is the length of the shortest path
from s to dj , using only vertices of S as intermediates.
The basic step of Dijkstra’s algorithm adds one more vertex to S. It selects
the vertex to add to be one of the vm ∈ V − S such that dest
j is minimum;
est est 0
that is, dm ≤ dj , ∀vj ∈ V − S. The new set S = S + vm .
We want to prove that this is a correct choice, that is, that S 0 will have the
two properties that S had. This is done using the following essential lemma
about S.
1
Lemma 2 Let vm be an outside vertex in V − S such that dest m is minimum.
Then dest
m ≤ d j , for all j ∈ V − S. That is, the estimated distance to vm
is a lower bound on the length of the shortest path from s to any vertex in
V − S.
Proof: Assume for the purpose of contradiction that there is some vertex
vj ∈ V − S, with dj < dest est est est
m . Since dm ≤ dj , we have dj < dj . So any
true shortest path P from s to vj is shorter than the length of a shortest
path using only vertices from S as intermediates. Then P must use at least
one vertex from V − S as an intermediate.
Now we use the essential Lemma to prove that our new set S 0 has the two
properties of S.
∀vi ∈ S 0 , ∀vj ∈ V − S 0 , di ≤ dj
We use the essential lemma in two ways. First, since the lemma is true for
vm as well as any other vertex in V − S, we have dest est
m ≤ dm ≤ dm , that
est
is, dm = dm . So we have computed the length of the shortest path to vm .
And second, since dest
m = dm ≤ dj , for all vj ∈ V − S, then it is also true
that dm ≤ dj for all vj ∈ V − S 0 .