### Correctness proof of Dijkstra's Algorithm

• Proof of correctness: Dijkstra's Algorithm

• Notations:

 D(S,u) = the minimum distance computed by Dijkstra's algorithm between nodes S and u d(S,u) = the actual minimum distance between nodes S and u

• Proposition 13.23 (Goodrich)

• In Dijkstra's Algorithm, when (at the moment that) a vertex u is included into the ReachedSet, we have that:

 D(S,u) = d(S,u)

• Suppose the statement is false

• Then there are some vertices where when (at the moment that) a vertex u is included into the ReachedSet:

 D(S,u) > d(S,u)

• Let x = the first of these vertices that was included into the ReachSet

In other words:

• x = the first vertex such that when (at the moment that) vertex x is included into the ReachedSet:

 D(S,x) > d(S,x)

• This implies that all previous vertices z that were included into the ReachedSet, that:

 D(S,z) = d(S,z)

• Let's look at the moment when this node x is included into the ReachedSet

Denote:

 The P be the (real) shortest path from S to x Let z = the first vertex that is not in the "ReachSet" and is on the shortest path Let y = the predecessor vertex of z on the shortest path P

Graphical depiction of the situation:

• We can conclude the following:

 D(S,y) = d(s,y)                                     ....... (1) (The min. distance S ⇒ y computed by the algorithm = actual min. distance S ⇒ y because y in included before x) D(S,z) = D(S,y) + linkcost(y,z)            = d(s,y) + linkcost(y,z)               ....... (2) D(S,x) ≤ D(S,z)                                        ....... (3) (Because the next vertex included by the algorithm is vertex x)

• Improtant fact:

• A sub path of a shortest path is itself a shortest path

I.e.:

shortest path "S → x" = shortest path "S → z"     shortest path "z → x"

• Therefore:

 d(S,x)   =   d(S,z) + d(z,x)

• We can now conclude that:

 ``` D(S,x) ≤ D(S,z) ............. (3) = d(s,y) + linkcost(y,z) (Equation (2)) ≤ d(S,y) + linkcost(y,z) + d(z,x) = d(S,x) ```

• Ths result is a contradiction to the assumption:

 D(S,x) > d(S,x)

Therefore, the assumption that "the statement false" is false

The statement must be true