Algorithm Search⌘K

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 AA and vertices x,yx, y, distA(x,y)\mathrm{dist}_A(x, y) is the least length of a directed path from xx to yy with all arcs in AA, or ∞\infty. A division DD of a set of arcs AA is a set of pieces whose arc sets partition AA; each piece contains the ends of its arcs, and B(P)B(P) is the set of vertices of PP 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 DD be a division of AA, and let π=(x0,x1,…,xk)\pi = (x_0, x_1, \ldots, x_k) be a path with all arcs in AA. Cut π\pi at every inner vertex xix_i (0<i<k0 < i < k) that is a boundary vertex of some piece. Then each part has all its arcs in one piece.

Proof. Take two consecutive arcs xi−1xix_{i-1} x_i and xixi+1x_i x_{i+1} in the same part, so xix_i is not a boundary vertex of any piece. Then xix_i 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. □\square

The dense distance graph. Given DD and tables TT with TP[b][b′]=distA(P)(b,b′)T_P[b][b'] = \mathrm{dist}_{A(P)}(b, b') for all b,b′∈B(P)b, b' \in B(P), let HH be the graph whose vertices are all boundary vertices and which has, for each piece PP and each pair b≠b′b \ne b' in B(P)B(P) with TP[b][b′]<∞T_P[b][b'] < \infty, an arc b→b′b \to b' of length TP[b][b′]T_P[b][b'].

Lemma 2. For boundary vertices b,b′b, b', distH(b,b′)=distA(b,b′)\mathrm{dist}_H(b, b') = \mathrm{dist}_A(b, b').

Proof. Each arc of HH stands for a path in AA of the same length, so distA≤distH\mathrm{dist}_A \le \mathrm{dist}_H. Conversely, take a shortest path π\pi from bb to b′b' in AA and cut it as in Lemma 1. Every cut vertex is a boundary vertex, and so are bb and b′b'. Each part goes from a boundary vertex cc to a boundary vertex c′c' inside one piece PP, and c,c′c, c' are in PP, so they are in B(P)B(P); its length is at least TP[c][c′]T_P[c][c'], which is an arc of HH (or c=c′c = c' and the part can be dropped). So distH≤distA\mathrm{dist}_H \le \mathrm{dist}_A. □\square

Lemma 3. Assume the tables TT are correct for DD, and that every start vertex is a boundary vertex. Then BOUNDARY-SEARCH(D,T,start)(D, T, \mathit{start}) returns, for every boundary vertex bb, d(b)=min⁡a(start(a)+distA(a,b))d(b) = \min_{a} (\mathit{start}(a) + \mathrm{dist}_A(a, b)), the minimum over the start vertices aa.

Proof. By Lemma 2 it suffices to show that the procedure is Dijkstra's algorithm on HH with several sources: it settles the vertices in order of their final labels, and when it settles bb it relaxes every arc of HH out of bb. The second part is lines L18 and L19, which go over every piece QQ with b∈B(Q)b \in B(Q) and every b′∈B(Q)b' \in B(Q); 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 xx that is not settled and has d(x)<∞d(x) < \infty lies in some piece QQ such that HH holds an entry of QQ with key equal to key(Q)\mathrm{key}(Q) and key(Q)≤d(x)\mathrm{key}(Q) \le d(x).

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 d(x)d(x) can drop only in line L19, for a piece QQ with x∈B(Q)x \in B(Q), and line L20 then sets key(Q)\mathrm{key}(Q) to the minimum over the vertices of B(Q)B(Q) not settled, which is at most d(x)d(x), and inserts QQ 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 key(P)\mathrm{key}(P), and rescans the piece: if the true minimum mm differs from the key, the key was too low, PP is reinserted with mm, and nothing is settled.

Now suppose line L17 settles bb from piece PP with d(b)=k=key(P)d(b) = k = \mathrm{key}(P), where kk is the least key in HH and the rescan confirmed kk. Let xx be any vertex not settled with finite label. By (K), some entry in HH has key at most d(x)d(x), so k≤d(x)k \le d(x). Hence bb 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. □\square

The tables

Lemma 4. After line L6, TQ[b][b′]=distA(Q)(b,b′)T_Q[b][b'] = \mathrm{dist}_{A(Q)}(b, b') for every small piece QQ and b,b′∈B(Q)b, b' \in B(Q). After line L8, TP[b][b′]=distA(P)(b,b′)T_P[b][b'] = \mathrm{dist}_{A(P)}(b, b') for every piece PP of D1D_1 and b,b′∈B(P)b, b' \in B(P).

Proof. The first claim is the correctness of Dijkstra's algorithm run on the arcs of QQ. For the second, D2D_2 is a division of the arcs of PP, and line L4 makes every vertex of B(P)B(P) a boundary vertex of the small pieces that contain it. So in line L8 the start vertex bb and every target b′b' are boundary vertices of D2D_2, the tables of D2D_2 are correct by the first claim, and Lemma 3, applied to D2D_2 with A=A(P)A = A(P), gives δ(b′)=distA(P)(b,b′)\delta(b') = \mathrm{dist}_{A(P)}(b, b'). □\square

The final labels

Theorem. FREDERICKSON-SSSP returns d(x)=dist(s,x)d(x) = \mathrm{dist}(s, x) for every vertex xx.

Proof. By line L2, ss is a boundary vertex of D1D_1. By Lemma 4 the tables of D1D_1 are correct, so by Lemma 3 line L9 gives d(b)=dist(s,b)d(b) = \mathrm{dist}(s, b) for every boundary vertex bb of D1D_1.

Now let xx be a vertex that is not a boundary vertex; then x≠sx \ne s, and xx lies in exactly one piece PP. If xx is not reachable, every label stays ∞\infty, since all labels are lengths of real paths. Otherwise take a shortest path π\pi from ss to xx, and let bb be the last vertex of π\pi that is a boundary vertex of some piece; it exists, since ss is one. Every vertex after bb on π\pi is not a boundary vertex, so by the argument of Lemma 1 all arcs after bb are in one piece, the piece of the last arc, which contains xx and so is PP. Then bb is in PP, hence b∈B(P)b \in B(P). Line L11 starts Dijkstra in PP with the label d(b)=dist(s,b)d(b) = \mathrm{dist}(s, b), so it finds a label for xx at most dist(s,b)+distA(P)(b,x)=dist(s,x)\mathrm{dist}(s, b) + \mathrm{dist}_{A(P)}(b, x) = \mathrm{dist}(s, x). Every label it finds is the length of a path from ss, so it is at least dist(s,x)\mathrm{dist}(s, x). Line L11 changes no label of a boundary vertex below its distance, by the same remark. □\square

Termination

Each Dijkstra run settles each vertex of its piece once. In BOUNDARY-SEARCH, each round of the loop either removes an entry from HH 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. ■\blacksquare

Back to Frederickson's planar shortest-path algorithm