Let be a directed graph, where is a set of nodes, is a set of edges, and is the non-negative length of edge .
Let be a set of adjacent nodes of node . The following algorithm computes the shortest distance from a node to each of the other nodes.
(1) Table 1 shows the value of for each in the process of execution of , where the input graph is and the starting node is . Complete Table 1.
(2) Prove that for each stores the shortest distance from to when terminates.
(3) Prove that may not find the shortest distance if some of the edges take negative length.
Let denote the length of a shortest path from to .
Suppose that is the first vertex extracted from for which .
Let be a shortest path from to , where satifies but does not.
When is extracted from , since is adjacent to , will be updated
Now both and are in when is chosen.
Note that by assumption is the first vertex extracted from for which , hence either or is chosen after , which means that .
But by assumption we have , hence we have