Algorithm Search⌘K

Proofs: Demetrescu-Italiano dynamic APSP algorithm

These are the human proofs of Demetrescu-Italiano dynamic APSP algorithm, at full length.

The cleanup and fixup procedures keep all shortest paths full

This proof shows: correctness.

This proof is for the version on the page: CLEANUP and FIXUP over a store of paths, without smoothing. Edge weights are nonnegative.

Order on walks. Each edge ee has a distinct number id(e)\mathrm{id}(e). The key of a walk π\pi is k(π)=(w(π),μ(π))k(\pi) = \big(w(\pi), \mu(\pi)\big) with μ(π)=∑2id(e)\mu(\pi) = \sum 2^{\mathrm{id}(e)} over the edges of π\pi with repetition, compared in lexicographic order. Keys add up when walks are joined, and each edge adds a positive amount to μ\mu.

Lemma 1. If some walk goes from xx to y≠xy \ne x, there is a unique walk πxy∗\pi^*_{xy} of least key. It is a simple path, and each of its subpaths with at least one edge is the least walk between its ends.

Proof. A walk that repeats a vertex contains a closed subwalk with at least one edge; removing it gives a walk with a smaller key, because the closed subwalk has w≥0w \ge 0 and μ>0\mu > 0. So a least walk, if one exists, is a simple path. There are finitely many simple paths, and two different simple paths from xx to yy have different edge sets, so different values of μ\mu. So the least one is unique. If a subpath were not least, replacing it by a lighter walk would give a lighter walk from xx to yy. □\square

We call πxy∗\pi^*_{xy} the shortest path, and the key order on paths "lighter". For a stored path PP with at least one edge, l(P)l(P) and r(P)r(P) are as on the page; for an edge, they are the one-vertex paths, which are fixed objects.

Invariants. Between updates:

  • (I1) Each stored path is a simple path from xx to y≠xy \ne x in the current graph, with its key computed from current weights.
  • (I2) For a stored path PP with at least two edges, l(P)l(P) and r(P)r(P) are stored, P∈Lext(l(P))P \in L_{ext}(l(P)) and P∈Rext(r(P))P \in R_{ext}(r(P)).
  • (I3) For each edge of the graph, its edge path is stored.
  • (I4) No two stored paths have the same vertex sequence.
  • (I5) SP[x,y]=πxy∗\mathrm{SP}[x, y] = \pi^*_{xy} for each pair with a path from xx to yy, and SP[x,y]\mathrm{SP}[x, y] is empty otherwise. The paths in the lists L∗L^* and R∗R^* are exactly the values of SP\mathrm{SP}, each in L∗(r(σ))L^*(r(\sigma)) and R∗(l(σ))R^*(l(\sigma)).
  • (I6) For any two values a,ba, b of SP\mathrm{SP} with r(a)=l(b)r(a) = l(b) and x(a)≠y(b)x(a) \ne y(b), the path with l=al = a and r=br = b is stored.

At the start the graph has no edges and the store is empty, so all invariants hold.

Lemma 2 (CLEANUP). After line L1, the stored paths are exactly the old stored paths that do not pass through vv, and (I2), (I4), (I6) hold, with SP\mathrm{SP} cleared for each pair whose shortest path passed through vv and unchanged for the other pairs.

Proof. A stored path with at least two edges is the union of l(P)l(P) and r(P)r(P), so by induction on its length, each edge of PP lies in l(P)l(P) or in r(P)r(P). A stored path through vv contains an edge at vv. By (I2), following LextL_{ext} and RextR_{ext} from the edge path of that edge reaches PP by induction on length, so line L8 puts PP into QQ. Conversely, each path that enters QQ is an edge path at vv or extends a path through vv, so it passes through vv. Line L7 clears exactly the removed values of SP\mathrm{SP} and their list entries. (I2) holds because a path whose ll or rr was removed was itself removed. (I4) holds for a subset. For (I6): if aa and bb remain values of SP\mathrm{SP}, they avoid vv, so their combination avoids vv, was stored, and was not removed. □\square

Line L2 changes only edges at vv, and no remaining stored path uses such an edge. So (I1) holds for the new graph G′G', and (I3) holds for every edge of G′G' that does not touch vv. Line L9 stores the edge paths of the edges at vv, so (I3) holds for G′G', and (I4) still holds, since no edge path at vv remained. Each path that COMBINE creates satisfies (I1): its parts are values of SP\mathrm{SP}, so by induction they are simple paths of G′G', r(a)=l(b)r(a) = l(b) makes them overlap in all but one edge at each end, and line L18 or L19 checks that its two ends differ, so it is a simple path with the key k(a)k(a) plus the key of one edge. COMBINE keeps (I2) by line L22, and (I4): two stored paths with the same vertex sequence of at least two edges would have ll parts with the same sequence and rr parts with the same sequence, so by induction the same ll and rr, and line L20 prevents a second copy.

Lemma 3 (FIXUP). FIXUP settles the pairs that are connected in G′G' in increasing order of the key of their shortest path, and it settles each such pair (x,y)(x, y) with π=πxy∗\pi = \pi^*_{xy}.

Proof. The keys that leave HH do not decrease, because each path inserted at line L23 is heavier than the path π\pi of the current step: it contains π\pi and one more edge. Every path in HH is stored, so by (I1) it is a path of G′G' and at least as heavy as the shortest path of its pair.

We show by induction over the shortest paths in increasing key order that P=πxy∗P = \pi^*_{xy} is in HH before any path of key larger than k(P)k(P) leaves HH. Then the first path of the pair (x,y)(x, y) that leaves HH is PP, since PP is strictly lighter than every other path of the pair.

If PP is one edge, its edge path is stored by (I3). As the lightest stored path of its pair, it is put into HH at line L10.

Let PP have at least two edges. By Lemma 1, A=l(P)A = l(P) and B=r(P)B = r(P) are shortest paths, and both are lighter than PP. By induction, their pairs are settled before any path of key k(P)k(P) or more leaves HH, and after their settling steps, SP\mathrm{SP} holds them. The paths r(A)r(A) and l(B)l(B) have the same vertex sequence and are both stored, or both the same one-vertex path, so by (I4) they are the same object. A pair is settled only once in a FIXUP, so once a pair's SP\mathrm{SP} is set during FIXUP or confirmed at line L15, it does not change again.

  • If both AA and BB were values of SP\mathrm{SP} before FIXUP and stay so, then by (I6) the path with l=Al = A and r=Br = B, which is PP, was stored before FIXUP. It is the lightest stored path of its pair, so line L10 put it into HH.
  • Otherwise consider the step that executes line L17 for the later of AA and BB to become a value of SP\mathrm{SP}. At that step the other one is a value of SP\mathrm{SP}: either it was set earlier in this FIXUP, or it was a value before FIXUP and its pair has not been settled with a different path, because its shortest path is still the same object. If the new value is BB, then A∈L∗(r(A))=L∗(l(B))A \in L^*(r(A)) = L^*(l(B)), so line L18 calls COMBINE(A,B)(A, B). If the new value is AA, then B∈R∗(l(B))=R∗(r(A))B \in R^*(l(B)) = R^*(r(A)), so line L19 calls COMBINE(A,B)(A, B). The ends of PP differ, so the test passes. COMBINE either inserts PP into HH at line L23, or finds it stored. A path that is stored and not yet in HH was stored before FIXUP, as paths created in FIXUP enter HH when they are created; then it is the lightest stored path of its pair and line L10 put it into HH.

In both cases PP enters HH at a step that settles a path lighter than PP, so before any path of key k(P)k(P) or more leaves HH. □\square

Theorem. After each update, (I1) to (I6) hold, so dist(x,y)\mathrm{dist}(x, y) returns d(x,y)d(x, y) and path(x,y)\mathrm{path}(x, y) returns a shortest path.

Proof. (I1) to (I4) hold by Lemma 2 and the remarks after it. By Lemma 3, each connected pair has SP[x,y]=πxy∗\mathrm{SP}[x, y] = \pi^*_{xy} after FIXUP. If (x,y)(x, y) is not connected in G′G', no stored path joins them by (I1), so the pair is never settled; its old value of SP\mathrm{SP} would be a stored path from xx to yy, so it was cleared by CLEANUP. Lines L16 and L17 keep the lists L∗L^* and R∗R^* equal to the values of SP\mathrm{SP}, which gives (I5). For (I6), take values aa and bb of SP\mathrm{SP} after FIXUP with r(a)=l(b)r(a) = l(b) and x(a)≠y(b)x(a) \ne y(b). If both were values before FIXUP, (I6) held before and the combination was not removed. Otherwise, as in the proof of Lemma 3, the later of the two to be set at line L17 found the other in L∗L^* or R∗R^* and called COMBINE on them. A path is removed only by CLEANUP, so the combination is still stored. ■\blacksquare

Back to Demetrescu-Italiano dynamic APSP algorithm