Proofs: Frederickson's planar shortest-path algorithm
These are the human proofs of Frederickson's planar shortest-path algorithm, at full length.
Correctness of Frederickson's planar shortest-path algorithm full
This proof shows: correctness, termination.
Line numbers refer to the pseudocode on the main page. All lengths are nonnegative. For a set of arcs and vertices , is the least length of a directed path from to with all arcs in , or . A division of a set of arcs is a set of pieces whose arc sets partition ; each piece contains the ends of its arcs, and is the set of vertices of that are in another piece or are terminals. Planarity is not used anywhere below: it only bounds the sizes, and so the time.
Paths and pieces
Lemma 1. Let be a division of , and let be a path with all arcs in . Cut at every inner vertex () that is a boundary vertex of some piece. Then each part has all its arcs in one piece.
Proof. Take two consecutive arcs and in the same part, so is not a boundary vertex of any piece. Then is in exactly one piece: it is in the piece of each arc at it, and if it were in two pieces it would be a boundary vertex of both. So both arcs are in that piece. By induction along the part, all its arcs are in one piece.
The dense distance graph. Given and tables with for all , let be the graph whose vertices are all boundary vertices and which has, for each piece and each pair in with , an arc of length .
Lemma 2. For boundary vertices , .
Proof. Each arc of stands for a path in of the same length, so . Conversely, take a shortest path from to in and cut it as in Lemma 1. Every cut vertex is a boundary vertex, and so are and . Each part goes from a boundary vertex to a boundary vertex inside one piece , and are in , so they are in ; its length is at least , which is an arc of (or and the part can be dropped). So .
The boundary search
Lemma 3. Assume the tables are correct for , and that every start vertex is a boundary vertex. Then BOUNDARY-SEARCH returns, for every boundary vertex , , the minimum over the start vertices .
Proof. By Lemma 2 it suffices to show that the procedure is Dijkstra's algorithm on with several sources: it settles the vertices in order of their final labels, and when it settles it relaxes every arc of out of . The second part is lines L18 and L19, which go over every piece with and every ; relaxing only into vertices not settled changes nothing, since a settled vertex has its final, smaller or equal label.
For the first part, we use this invariant, which holds after line L14 and after every round of the loop:
(K) Every boundary vertex that is not settled and has lies in some piece such that holds an entry of with key equal to and .
After line L14, the start vertices are the only vertices with finite labels, and each is in a piece inserted with the minimum over its boundary. In a round, a label can drop only in line L19, for a piece with , and line L20 then sets to the minimum over the vertices of not settled, which is at most , and inserts with it. A key changes only in lines L16 and L20, and both set it to the current minimum of the piece, which is at most the label of every vertex of the piece not settled. So (K) holds again.
Also, each key is at least the true minimum of its piece at the moment it is set, and labels only go down. So the key of an entry is either equal to the current minimum of its piece, or larger than a label that has since dropped (too high), or smaller because the vertex that gave it has since been settled (too low). Line L16 skips entries whose key is not , and rescans the piece: if the true minimum differs from the key, the key was too low, is reinserted with , and nothing is settled.
Now suppose line L17 settles from piece with , where is the least key in and the rescan confirmed . Let be any vertex not settled with finite label. By (K), some entry in has key at most , so . Hence has the least label among all vertices not settled, which is the rule of Dijkstra's algorithm. With nonnegative lengths this rule settles every vertex at its distance from the sources, by the usual proof of Dijkstra's algorithm. Every vertex reachable from a source gets a finite label, and by (K) the loop does not end while such a vertex is not settled.
The tables
Lemma 4. After line L6, for every small piece and . After line L8, for every piece of and .
Proof. The first claim is the correctness of Dijkstra's algorithm run on the arcs of . For the second, is a division of the arcs of , and line L4 makes every vertex of a boundary vertex of the small pieces that contain it. So in line L8 the start vertex and every target are boundary vertices of , the tables of are correct by the first claim, and Lemma 3, applied to with , gives .
The final labels
Theorem. FREDERICKSON-SSSP returns for every vertex .
Proof. By line L2, is a boundary vertex of . By Lemma 4 the tables of are correct, so by Lemma 3 line L9 gives for every boundary vertex of .
Now let be a vertex that is not a boundary vertex; then , and lies in exactly one piece . If is not reachable, every label stays , since all labels are lengths of real paths. Otherwise take a shortest path from to , and let be the last vertex of that is a boundary vertex of some piece; it exists, since is one. Every vertex after on is not a boundary vertex, so by the argument of Lemma 1 all arcs after are in one piece, the piece of the last arc, which contains and so is . Then is in , hence . Line L11 starts Dijkstra in with the label , so it finds a label for at most . Every label it finds is the length of a path from , so it is at least . Line L11 changes no label of a boundary vertex below its distance, by the same remark.
Termination
Each Dijkstra run settles each vertex of its piece once. In BOUNDARY-SEARCH, each round of the loop either removes an entry from without inserting one (an outdated entry), or reinserts one piece after a rescan that found a larger key (this happens at most once per inserted entry, since the reinserted entry has the correct key until a vertex is settled), or settles a new vertex. Each settled vertex inserts at most one entry per piece that contains it. So the number of entries, and of rounds, is finite, and every loop ends.