Proofs: Read-Tarjan path enumeration
These are the human proofs of Read-Tarjan path enumeration, at full length.
Read-Tarjan lists every simple s-t path exactly once, with one branch per path full
This proof shows: correctness, termination.
Let be a finite directed graph on with out-lists ; an undirected graph is the directed graph with both arcs of every edge, and loops and parallel edges are removed, which does not change the set of simple paths as vertex sequences. Fix and . For a simple path from to , let be the set of simple - paths that start with . Call a branch if .
Lemma 1. For a simple path from to with , if and only if is reachable from in , where is the set of vertices of other than .
Proof. A path in continues from to through vertices not in , which is a path from to in . Conversely, a path from to in can be taken simple, it meets only at , and appending it to gives a path in .
Lemma 2 (the set ). In the loop of lines L11 to L14, at the test of line L13 for index , the blocked set is , and is the set of vertices from which is reachable in .
Proof. For , line L10 sets the blocked set to and computes by a reverse search from over unblocked vertices, which is correct because ( and does not contain ). For , line L12 unblocks , so the blocked set becomes . Every vertex of is in , since is a subgraph of . A vertex has a path to in , and each such path passes through ; so , and reaches through vertices not in . Moreover if and only if it has an arc into : a shortest path from to in does not return to , so after its first arc it lies in . Line L12 tests exactly this, adds , and the reverse search from it over unblocked vertices not yet in adds every vertex that reaches in . A vertex added this way reaches through , so it is in . Hence .
Lemma 3 (partition). Let be a branch ending at , let be the path found at line L8, and for and with let . Then is the disjoint union of and the sets over all such . Moreover if and only if .
Proof. By Lemma 1, exists, and since avoids . Let with . Let be the largest index with a prefix of . Then , since otherwise starts with , which ends at , so . The path does not end at , because for , so its next vertex is in , and by the choice of . So . The pair is determined by , so the sets are disjoint, and none contains . If lies in or in , the sequence is not simple and , and also , so . Otherwise is a simple path from to ; if , and ; if , Lemma 1 with the blocked set shows that if and only if .
Lemma 4. When a branch is popped at line L5, the algorithm outputs, at that time and later through the branches pushed for it and their descendants, exactly the paths of , each once.
Proof. By induction on , where is the number of vertices of . If , , since a simple path that contains ends there, and line L6 outputs and pushes nothing. Otherwise line L9 outputs , and by Lemmas 2 and 3, lines L13 and L14 push exactly the pairs with , each a branch with more vertices than . Every pushed branch is popped later, because the loop runs until the stack is empty, and by induction it outputs exactly . By Lemma 3 these sets and are disjoint and their union is .
Theorem. READ-TARJAN terminates and outputs every simple - path exactly once. It pops exactly branches when paths exist.
Proof. If , the only simple - path is , and line L1 outputs it. If is not reachable from , there is no path and line L2 stops. Otherwise is a branch by Lemma 1, and by Lemma 4 the paths output are exactly , the set of all simple - paths, each once. Every popped branch outputs one path at line L6 or L9, and different branches output different paths by Lemma 4, so at most branches are popped, which proves termination; each branch does finite work because the searches and loops run over finite lists. Each path is output by the branch that pops it or by an ancestor's line L9, and the counting above shows that there are exactly branches.