Proofs: Tarjan's subtree disassembly
These are the human proofs of Tarjan's subtree disassembly, at full length.
Subtree disassembly returns the distances or a reachable negative cycle full
This proof shows: correctness, termination.
Let have vertices, real weights and source . Line numbers refer to SUBTREE-DISASSEMBLY on the main page. A label change is one execution of line L9. A vertex is active if it is in the tree , and inactive if it has a finite label but is not in .
Invariant 1 (structure). At the test of line L2: (a) is a tree rooted at whose arcs are arcs of , given by ; (b) every tree arc is tight, ; (c) and is in ; (d) every vertex in is in .
Proof. At the start and all four parts hold. Consider a label change of through the arc during the scan of . The scan runs only for , and stays in during its own scan: it could leave only at line L8 as a proper descendant of some , but then line L6 would have returned. Line L6 has failed, so and is not an ancestor of . Line L8 removes the proper descendants of from and from ; the rest of is still a tree, and all its arcs are unchanged and tight. Line L9 then lowers and makes a child of . The vertex is not in the subtree of , so no cycle is created and stays a tree. The only arcs with head or tail in are now , which is tight by line L9, since has no children after line L8. So (a) and (b) hold. For (c): would need to be an ancestor-or-equal of , which is always the case, so line L6 returns before changes. Part (d) holds because line L8 removes from every vertex it removes from , and line L10 adds , which is in .
Fact 2 (labels are path weights). At all times, every finite label is the weight of a simple path from to .
Proof. For , by Invariant 1 (b) and (c), summing the tight arcs along the tree path gives , which is a simple path. An inactive vertex keeps the label it had when it was last in , which was such a weight then.
Lemma 3 (returned cycles). If line L7 returns, the returned cycle is a negative cycle reachable from .
Proof. If , the cycle is the self-loop with . Otherwise is a proper ancestor of in , and the tree path from to has weight by tightness. With the arc , it closes a cycle of distinct vertices (a tree path is simple) of weight by the test of line L5. Its vertices are in , so they are reachable from .
Lemma 4 (termination). The algorithm terminates.
Proof. By Fact 2 every finite label is the weight of one of the finitely many simple paths from . Each label change makes a label strictly smaller, so each vertex has finitely many label changes, and line L10 adds finitely many entries to . Each iteration of line L2 removes one entry.
Invariant 5 (violated arcs). At the test of line L2, every arc with and has or inactive.
Proof. At the start only is finite and . When is scanned, each arc out of is relaxed and becomes non-violated; a later label change in the same scan lowers only the label of some head (the case returns), which cannot violate an arc out of . When goes down at line L9, the arcs out of may become violated, and line L10 puts in . A vertex removed at line L8 leaves but becomes inactive. Lowering never violates an arc into .
Lemma 6 (no inactive vertex at the end). If the loop of line L2 ends because is empty, no vertex is inactive.
Proof. For an inactive vertex , look at the last time it was removed at line L8, during the label change of some vertex , and let be its parent just before that removal, so that is or a vertex removed at the same time, and the arc was tight with the labels just before time . Let be the depth of below at that moment. Since is inactive, has not changed since .
Suppose is empty at the end and , the set of inactive vertices, is not empty. Take and . Two cases.
- is now smaller than just before . This holds if , whose label went down at time , or if had a label change after . Then , the arc is violated, and by Invariant 5 with empty, . In this case the last removal of came after time : for , was active right after ; for , was put back in by a label change after . So .
- is unchanged since just before . Then , was removed at time and has not been put back in , so with and .
In both cases and the pair is lexicographically larger than . Starting from any and applying again and again gives an infinite sequence in the finite set with strictly increasing pairs, which is impossible.
Theorem. The algorithm terminates. If it returns a cycle, that cycle is a negative cycle reachable from . If it returns and , then no negative cycle is reachable from , for all , with exactly for the unreachable vertices, and is a shortest-path tree. So it returns a cycle if and only if a negative cycle is reachable from .
Proof. Termination is Lemma 4, and the claim on returned cycles is Lemma 3. Suppose it returns at line L11, with empty. By Lemma 6 there is no inactive vertex, so by Invariant 5 no arc with a finite tail is violated. As in the proof for SPFA, a reachable vertex with label would give a violated arc on a path from , so exactly the reachable vertices have finite labels. Summing the inequalities around any cycle through reachable vertices gives a nonnegative weight, so no negative cycle is reachable from . By Invariant 1 (c) , by Fact 2 each finite label is the weight of a path from , and the triangle inequality holds on every arc with a reachable tail; Theorem B of the optimality conditions gives . All reachable vertices are in , which is a tree of tight arcs by Invariant 1, so each tree path has weight , and is a shortest-path tree. Finally, if a negative cycle is reachable from , the run cannot return at line L11, so it returns a cycle.