Proofs: Trémaux traversal
These are the human proofs of Trémaux traversal, at full length.
Trémaux's rule walks each edge of the component twice and returns to the start full
This proof shows: correctness, termination.
Let be an undirected multigraph, , and the vertex set of the component of . The walker is at . Call the vertices with $\mathrm{visited} = $ true visited. For each visited , the edge joins to the vertex at which the walker stood when he first entered . Let be the sequence in which ; we show that it exists.
Invariant. At the start of each iteration of the loop of line L2:
- the entry edges of the visited vertices other than form a tree on the visited vertices, and is visited, so is the path in from to ;
- an edge has mark 1 if and only if it is for some ;
- each visited vertex that is not on has no edge with mark 0;
- the walk so far goes from to , an edge with mark 0 has not been walked, and an edge with mark has been walked times.
Initialization. Only is visited, has no edges, , all marks are 0 and the walk is empty. All four parts hold.
A consequence. The edges with mark 1 at are , if , and nothing else. By part 2, an edge with mark 1 is . It is not a loop, because was unvisited and visited when it was set. If it contains , then or , and a vertex is on a path only once, so .
Maintenance. Consider the three cases of one iteration.
- Line L5. The edge has mark 0 and is visited. The walker goes to and back, gets mark 2 and has been walked twice. Nothing else changes, so all parts still hold.
- Line L6. The edge has mark 0 and is not visited. Now is visited with and , so grows by a leaf, and becomes . The edge has mark 1, it has been walked once, and it is the entry edge of the new last vertex of . Part 3 is unchanged because is on .
- Line L8. No edge at has mark 0, and . The walker goes along to , which gives that edge its second walk and mark 2. Now is , which agrees with part 2. The vertex leaves and has no edge with mark 0, so part 3 holds.
Termination. Each iteration that does not stop raises the sum of all marks by 1 or 2, and the sum is at most , because a mark never exceeds 2: lines L4 to L6 act only on an edge with mark 0, and line L8 acts only on , which has mark 1 by part 2. So the loop stops after at most iterations.
Lemma 1 (local rule). At each step, the walker can choose by the local marks alone: an edge at with mark 0 for line L3, and, for line L8, the only edge at with mark 1.
Proof. This is the consequence above.
Lemma 2. When the walker stops, he is at , every vertex of is visited, every edge with an end in has mark 2, and no other edge has a mark.
Proof. Line L9 runs only if , so , , and no edge at has mark 0. By part 2, no edge has mark 1. By part 3, and the test at , no visited vertex has an edge with mark 0. Suppose that a vertex of is not visited. A path from to it has an edge with visited and not. This edge has mark 2, so it has been walked, by part 4, and the walker has stood at . Each arrival at a vertex happens at line L4, L5 or L8, and an arrival at an unvisited vertex makes it visited at line L6. So is visited, a contradiction. So all of is visited, and each edge with an end in has mark 2. The walk stays in , so other edges are never walked and have mark 0.
Lemma 3 (Trémaux tree). At the end, is a spanning tree of , and each edge of the component that is not in joins an ancestor and a descendant in .
Proof. is a tree on the visited vertices, which are , by part 1 and Lemma 2. A non-tree edge gets its first mark at line L4 when the walker stands at one end, say , and line L5 applies, so is visited at that moment. If were not on the path from to at that moment, then by part 3 it would have no edge with mark 0, but has mark 0 then. So is on the tree path from to , which makes it an ancestor of . A loop joins to itself.
Theorem. TREMAUX stops after a closed walk from that visits every vertex of the component of , walks each edge of the component exactly twice, never walks another edge, and needs at each step only the marks at the current vertex. Its entry edges form a spanning tree of the component in which every other edge joins an ancestor and a descendant.
Proof. Termination and Lemma 2 give the walk and its end at . By part 4 and Lemma 2, each edge of the component has been walked exactly twice and every other edge never. Lemma 1 gives the local rule and Lemma 3 the tree.