Proof of Dijkstra
In this article, the Dijkstra will be proved by mathematical induction. Suppose we have following variables:
- is the input graph
- is the set of all vertices
- is the set containing all visited vertices
- is source vertex
- is the length of an edge from to
- is shortest path distance found by Dijkstra algorithm.
Dijkstra algorithm
Proof by mathematical induction
Proof: For each is the shortest path from to .
- Basis: when , the , the assumption is correct.
- Inductive hypothesis:
- Suppose the condition is hold when .
- Let be the latest vertex(the th vertex) added to .
- Inductive step:
- Let is the next vertex(the th vertex) that will be added to (Currently, ).
- Let be the chosen edge, where . The path from to plus denotes , and .
- Consider another path from to via , where . We will show .
- Let is the first edge in that leaves . That is, but . is one path from to to to .
- Let be one subpath of from to , so
- . ( when . In this case, is not chosen, so ).
- From above:
- For all vertices including , the minimal happens when , so . (That's why is chosen instead of .)
- Thus, .