Proofs: Lexicographic breadth-first search
These are the human proofs of Lexicographic breadth-first search, at full length.
LEXBFS computes a LexBFS order, and its reverse is a perfect elimination ordering exactly for chordal graphs full
This proof shows: correctness, termination.
Let be a simple undirected graph with vertices. Write if is visited before . For a moment before step , the label of an unvisited is , and means that the first visited vertex of is in . This is a strict total order on the subsets of the visited vertices.
Part 1: the algorithm follows the LexBFS rule
Invariant. At the start of step (before line L3), the classes of partition the unvisited vertices; two unvisited vertices are in the same class if and only if they have the same label; and if class is before class in , the labels in are the labels in .
Initialization. Before step 1, no vertex is visited, every label is empty, and has one class holding .
Maintenance. Step removes from the first class. For an unvisited , the new label is if , and otherwise. Take two unvisited vertices and .
- If they were in the same class , their old labels were equal, say. If both or neither are adjacent to , the new labels are equal, and lines L5 to L8 leave them in one class: both in , or both in . If only is adjacent to , then the new labels are and , with symmetric difference , so 's label is larger. Line L8 moves to , which is just before , where stays.
- If they were in classes before , the old labels have , and the first vertex of is in . The vertex is visited after , so adding to one or both labels does not change the first vertex of the symmetric difference, and the new labels still differ, with 's larger. The class of after the step is or the new class just before , and that of is or the new class just before . Both of these are still before 's classes, because the new class of is inserted directly before and after (if is directly before , the new class of goes between them).
Empty classes are deleted, which does not change the order of the others. So the invariant holds at the start of step .
Lemma 1. The order returned by LEXBFS obeys the LexBFS rule, and its first vertex is .
Proof. By the invariant, the first class holds exactly the unvisited vertices with the largest label, and line L3 takes one of them. At step 1, all labels are equal and is first.
Termination. Each step visits one vertex, the loop of line L2 runs times, and each step scans one finite list.
Part 2: the four-point property
Lemma 2. Let be any order that obeys the LexBFS rule. If , and , then there is a vertex with and .
Proof. Consider the step at which is chosen. Then is visited and is not, and has a largest label, so . Now and , so the labels differ, and . Let be the first visited vertex of . Then and . Since is in the symmetric difference, , and because . So , and .
Part 3: chordal graphs
For a vertex , let be the set of its neighbours . The reverse of is a perfect elimination ordering exactly when is a clique for every , because the neighbours of that come after in the reverse order are those that come before in .
Lemma 3. Let obey the LexBFS rule on a chordal graph . Then there are no two non-adjacent vertices joined by a path whose internal vertices are all visited after .
Proof. Assume such pairs exist, and choose one, , with as early in as possible. Among the paths for this pair, choose a shortest one, . It has at least one internal vertex, since . It is chordless: a chord would give a shorter path between and whose internal vertices are a subset of those of .
Apply Lemma 2 to : and . It gives with and .
The walk , which is followed by backwards, is a path from to , because is not on : every vertex of is or after it. Its internal vertices are and the internal vertices of , and they are all visited after , and . If , then is a pair of the forbidden kind with , which contradicts the choice of . So .
Now is adjacent to and to , but not to . Walk along from , and let be the first vertex after that is adjacent to . It exists, because is adjacent to , and . The cycle has at least 4 vertices, because the part of from to has at least 3. It has no chord: the part of is chordless, and are not adjacent because is chordless and , and is adjacent to no vertex strictly between and by the choice of . A chordless cycle of length at least 4 contradicts that is chordal.
Theorem 1 (Rose, Tarjan and Lueker). Let be an order that obeys the LexBFS rule, in particular the output of LEXBFS. Then is chordal if and only if the reverse of is a perfect elimination ordering.
Proof. Let be chordal, and assume that some contains two non-adjacent vertices . Then is a path between the non-adjacent vertices whose only internal vertex is visited after . Lemma 3 forbids this. So every is a clique.
Conversely, let every be a clique, and let be a cycle of length at least 4. Let be the vertex of visited last. Its two neighbours on are in , so they are adjacent. They are not consecutive on , because has length at least 4, so this edge is a chord. So is chordal.
Lemma 4 (the linear-time test). For each with , let be the vertex of visited last. Then every is a clique if and only if, for every , each vertex of is adjacent to .
Proof. If every is a clique, the test holds. Conversely, assume the test holds, and show that is a clique by induction on the position of in . Take in . If one of them is , they are adjacent by the test. If not, both are adjacent to by the test and are visited before , so both are in , which is a clique by the induction hypothesis, since .
Corollary. LEXBFS followed by the test of Lemma 4 decides in time whether is chordal, and if it is, the reverse of is a perfect elimination ordering. This follows from Lemma 1, Theorem 1 and Lemma 4.