A Bit About Dijkstra’s

Correctness of Dijkstra’s Algorithm

Statement:

Dijkstraโ€™s algorithm, run on a weighted, directed graph G = (V, E) with nonnegative weight function w and source s, terminates with u.d = ๐›ฟ(s,u) for all vertices u โˆˆ V.

Analyzing the Statement:

Given: 1. G = (V, E) is a directed graph
2. G has nonnegative weight function w
3. Dijkstra’s algorithm runs on G with the source s.

To prove: Dijkstra’s algorithm terminates with u.d = ๐›ฟ(s,u) for all vertices u โˆˆ V.

Proof

We use the following loop invariant:

At the start of each iteration of the while loop of lines 4โ€“8, v.d = ๐›ฟ(s,v) for each vertex v โˆˆ S

Initialization

Initially, S is empty and hence loop invariant trivially holds.


Maintenance

To prove: u.d = ๐›ฟ(s,u) when each vertex u is being added to the set S.

Note: Text given in gray like this is not a part of the proof, but given for your understanding alone – giving subtitle to each section of proof.

1. Assumption for Contradiction

(Proof by contradiction) Assume that there are vertices which for which u.d โ‰  ๐›ฟ(s,u) when it is being added to the set S.

W.l.o.g, let us assume that u is the first vertex with u.d โ‰  ๐›ฟ(s,u) added to S.

2. Splitting Cases

Case 1: There is no path from ‘s’ to ‘u’

If there is no path from s to u, then by no path property, u.d = ๐›ฟ(s,u) = โˆž, which is a contradiction to our assumption that u.d โ‰  ๐›ฟ(s,u).


Case 2: There is at least one path from ‘s’ to ‘u’

3. First Claim

Claim: uโ‰  s.

Proof of the claim: ‘s’ is the first vertex, and we already know that s.d = ๐›ฟ(s, s) = 0. Hence the claim.

4. Decomposing shortest path

Since there is at least one path from ‘s’ to ‘u’, there is a shortest-path, say ‘p’ from ‘s’ to ‘u’. Note all vertices in path ‘p’ need not lie in the set S.

Let ‘y’ be the first vertex in path ‘p’ that is not in set S. Then the predecessor of ‘y’ in ‘p’ will be in S (since ‘y’ is the first vertex in path p not is S), we will, for convenience refer to it as ‘x’.

Then we can decompose the path as

Where p1 is the path from s to x and p2 is the path from y to u,

Note that p1 or p2 may or may not have edges.

5. Second claim

Claim 2: When u is being added to ‘s’, y.d = ๐›ฟ(s, y)

Proof of claim: Observe that since

  1. x โˆˆ S
  2. u is the first vertex with u.d โ‰  ๐›ฟ(s,u) added to S

we had x.d = ๐›ฟ(s, x) and while examining G.Adj[x], the edge (x, y) was relaxed at that time and hence the claim, i.e., y.d = ๐›ฟ(s, y).

6. Third Claim

Claim 3: u.d โ‰ค y.d

Since u was selected to be included in S before y it follows that u.d โ‰ค y.d.

7. Fourth Claim

Claim 4: y.d โ‰ค u.d

y.d = ๐›ฟ(s, y) (By Claim 2)
โ‰ค ๐›ฟ(s, u) (Since u comes after y in the shortest path)
โ‰ค u.d (By the upper-bound property)

8. The contradiction

Combining claims 3 and 4, we have u.d โ‰ค y.d โ‰ค ๐›ฟ(s, y) โ‰ค ๐›ฟ(s, u) โ‰ค u.d.

Thus, we can conclude that y.d = ๐›ฟ(s, y) = ๐›ฟ(s, u) = u.d.

And that contradicts our choice of u. Hence we conclude that u.d = ๐›ฟ(s, u) when ‘u’ is added and the loop invariant is maintained at all times.

Termination

At termination, Q = V – S = { }. That is, V = S. Hence, we can conclude that u.d = ๐›ฟ(s, u) for every vertex u in V.

Hence the proof.

Pages: Contents<< Previous 8 Next Page>>

Advertisement

One Comment Add yours

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.