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 has a distinct number . The key of a walk is with over the edges of with repetition, compared in lexicographic order. Keys add up when walks are joined, and each edge adds a positive amount to .
Lemma 1. If some walk goes from to , there is a unique walk 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 and . So a least walk, if one exists, is a simple path. There are finitely many simple paths, and two different simple paths from to have different edge sets, so different values of . So the least one is unique. If a subpath were not least, replacing it by a lighter walk would give a lighter walk from to .
We call the shortest path, and the key order on paths "lighter". For a stored path with at least one edge, and 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 to in the current graph, with its key computed from current weights.
- (I2) For a stored path with at least two edges, and are stored, and .
- (I3) For each edge of the graph, its edge path is stored.
- (I4) No two stored paths have the same vertex sequence.
- (I5) for each pair with a path from to , and is empty otherwise. The paths in the lists and are exactly the values of , each in and .
- (I6) For any two values of with and , the path with and 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 , and (I2), (I4), (I6) hold, with cleared for each pair whose shortest path passed through and unchanged for the other pairs.
Proof. A stored path with at least two edges is the union of and , so by induction on its length, each edge of lies in or in . A stored path through contains an edge at . By (I2), following and from the edge path of that edge reaches by induction on length, so line L8 puts into . Conversely, each path that enters is an edge path at or extends a path through , so it passes through . Line L7 clears exactly the removed values of and their list entries. (I2) holds because a path whose or was removed was itself removed. (I4) holds for a subset. For (I6): if and remain values of , they avoid , so their combination avoids , was stored, and was not removed.
Line L2 changes only edges at , and no remaining stored path uses such an edge. So (I1) holds for the new graph , and (I3) holds for every edge of that does not touch . Line L9 stores the edge paths of the edges at , so (I3) holds for , and (I4) still holds, since no edge path at remained. Each path that COMBINE creates satisfies (I1): its parts are values of , so by induction they are simple paths of , 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 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 parts with the same sequence and parts with the same sequence, so by induction the same and , and line L20 prevents a second copy.
Lemma 3 (FIXUP). FIXUP settles the pairs that are connected in in increasing order of the key of their shortest path, and it settles each such pair with .
Proof. The keys that leave do not decrease, because each path inserted at line L23 is heavier than the path of the current step: it contains and one more edge. Every path in is stored, so by (I1) it is a path of 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 is in before any path of key larger than leaves . Then the first path of the pair that leaves is , since is strictly lighter than every other path of the pair.
If is one edge, its edge path is stored by (I3). As the lightest stored path of its pair, it is put into at line L10.
Let have at least two edges. By Lemma 1, and are shortest paths, and both are lighter than . By induction, their pairs are settled before any path of key or more leaves , and after their settling steps, holds them. The paths and 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 is set during FIXUP or confirmed at line L15, it does not change again.
- If both and were values of before FIXUP and stay so, then by (I6) the path with and , which is , was stored before FIXUP. It is the lightest stored path of its pair, so line L10 put it into .
- Otherwise consider the step that executes line L17 for the later of and to become a value of . At that step the other one is a value of : 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 , then , so line L18 calls COMBINE. If the new value is , then , so line L19 calls COMBINE. The ends of differ, so the test passes. COMBINE either inserts into at line L23, or finds it stored. A path that is stored and not yet in was stored before FIXUP, as paths created in FIXUP enter when they are created; then it is the lightest stored path of its pair and line L10 put it into .
In both cases enters at a step that settles a path lighter than , so before any path of key or more leaves .
Theorem. After each update, (I1) to (I6) hold, so returns and returns a shortest path.
Proof. (I1) to (I4) hold by Lemma 2 and the remarks after it. By Lemma 3, each connected pair has after FIXUP. If is not connected in , no stored path joins them by (I1), so the pair is never settled; its old value of would be a stored path from to , so it was cleared by CLEANUP. Lines L16 and L17 keep the lists and equal to the values of , which gives (I5). For (I6), take values and of after FIXUP with and . 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 or and called COMBINE on them. A path is removed only by CLEANUP, so the combination is still stored.