Solution

ID: past-exam-of-the-mathematics-course-of-the-university-of-cambridge/2001/iii/paper-31/4/solution

The all-to-one shortest path problem asks for the minimum length of a directed path from every vertex to the root , with and if no such directed path exists. Positive directed edge lengths allow directed cycles to be deleted, so a shortest directed path, when one exists, uses at most directed edges. Its optimality equations are
A Bellman-Ford algorithm initializes and other labels to infinity, then repeats
keeping the root label zero. Induction on proves that is the least length among directed paths using at most directed edges: either the old best directed path remains, or the first directed edge is followed by a directed path with at most directed edges. Thus rounds give the exact distances. An in-place variant repeatedly relaxes ; each decreased label triggers further incoming-arc relaxations. It terminates when no finite label can improve. The Bellman inequalities then telescope along each directed path to show the labels are lower bounds on all directed path lengths, while every finite label represents a discovered directed path and is an upper bound on the optimum. This proves correctness. The method is a label-correcting shortest-path algorithm: a processed label can be revised many times. Full scans cost .
Let and choose attaining it. Every directed path from a nonroot vertex to has a final directed edge costing at least , and all preceding directed edges have positive lengths. Therefore every . The direct directed edge from to has length , so
If no incoming root directed edge exists, all these distances are infinite and there is no finite next vertex to settle.
The all-to-one Dijkstra algorithm sets the root's label to zero and all others to infinity. Repeatedly choose an unsettled vertex with least finite label, make that label permanent, and relax every incoming directed edge of an unsettled vertex:
Store the corresponding successor whenever the label improves. Stop when all vertices are settled or every remaining label is infinite. This applies the usual source version to the reversed graph; relaxing outgoing original directed edges would solve the wrong direction of the problem.
For its correctness, inductively assume every settled distance is exact. Any directed path from an unsettled vertex to the root must first enter the settled set at some vertex , through an directed edge . That directed edge has already been relaxed, so . The newly selected label is no greater than . The directed path's preceding nonnegative lengths therefore make its total length at least . On the other hand, itself is the length of a discovered directed path. Hence , and it can never need correction. This is a label-setting shortest-path algorithm. Straight array selection costs .
For four vertices and root 4, the full symbolic execution is as follows. After settling 4, the tentative labels are . Select
set , and update the two other labels to . Select the smaller of those labels at vertex , set , then for the last vertex set
The stored successors give the corresponding shortest routes; infinity conventions handle missing directed edges and disconnected vertices.
The supplied PDF contains no visible network diagram or directed edge lengths in the space for this example, and the converted TeX omits the diagram as well. Numerical distances and route choices cannot be determined from the supplied data. The symbolic run above gives the exact four-node calculation once those lengths are available; no network has been guessed.

New to topics? Read the docs here!