0% found this document useful (0 votes)
74 views2 pages

Dijkstra

Dijkstra's algorithm finds the shortest paths from a source vertex to all other vertices in a graph with non-negative edge weights. It maintains a set S of vertices known to be closest to the source. Each iteration adds one more vertex to S. The document proves this choice of vertex is correct by showing the estimated distance to outside vertices lower bounds their true shortest path distance.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views2 pages

Dijkstra

Dijkstra's algorithm finds the shortest paths from a source vertex to all other vertices in a graph with non-negative edge weights. It maintains a set S of vertices known to be closest to the source. Each iteration adds one more vertex to S. The document proves this choice of vertex is correct by showing the estimated distance to outside vertices lower bounds their true shortest path distance.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Proof for Dijkstra’s Algorithm

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.

We define the distance di to be the length of the shortest path from s


to vertex vi . Dijkstra’s algorithm maintains a set of vertices S, with two
properties. First, S is a set of vertices in the graph nearest to s; that is:

∀vi ∈ S, ∀vj ∈ V − S, di ≤ dj

And second, for all vertices vj ∈ S, there is a shortest path from s to vj


using only vertices of S as intermediates. There might be several different
choices for S; Dijkstra’s algorithm chooses one arbitrarily.

For each “outside” vertex dj ∈ V − Sk , we define an estimated distance:

dest
j = min di + w(ei,j )
vi ∈S

Since the estimated distance is the length of some path to dj , it is an upper


bound on the length of the true shortest path from 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.

Proof: Any path from s to dj , using only vertices of S as intermediates,


consists of a shortest path from from s to some vi ∈ S, and then one more
edge from vi to vj . We defined the estimated distance to vj to be the short-
est path of this form.

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.

Let vx be the first vertex from V − S along P , as we go from s to vj , so that


the predecessor of vx along the path belongs to S. Since vx comes before
vj , dest
x ≤ dj < dest
m . But vm was defined to be a vertex of V − S such that
est
dm is minimum. This is a contradiction. So our assumption that there is
some vj such that dj < destm has to be wrong.

Now we use the essential Lemma to prove that our new set S 0 has the two
properties of S.

Theorem 3 S 0 is a set of vertices nearest to s, that is,

∀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 .

Finally, we need to prove that for all vertices vi ∈ S 0 , there is a shortest


path from s to vi using only vertices of S 0 as intermediates. This is your
question to think about.

You might also like