Algorithm Search⌘K

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 G=(V,E)G = (V, E) be a simple undirected graph with nn vertices. Write x<σyx <_\sigma y if xx is visited before yy. For a moment before step ii, the label of an unvisited xx is ℓ(x)=N(x)∩{v1,…,vi−1}\ell(x) = N(x) \cap \{v_1, \ldots, v_{i-1}\}, and A≻BA \succ B means that the first visited vertex of A△BA \triangle B is in AA. 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 ii (before line L3), the classes of LL partition the unvisited vertices; two unvisited vertices are in the same class if and only if they have the same label; and if class XX is before class YY in LL, the labels in XX are ≻\succ the labels in YY.

Initialization. Before step 1, no vertex is visited, every label is empty, and LL has one class holding VV.

Maintenance. Step ii removes v=viv = v_i from the first class. For an unvisited ww, the new label is ℓ(w)∪{v}\ell(w) \cup \{v\} if w∈N(v)w \in N(v), and ℓ(w)\ell(w) otherwise. Take two unvisited vertices xx and yy.

  • If they were in the same class DD, their old labels were equal, AA say. If both or neither are adjacent to vv, the new labels are equal, and lines L5 to L8 leave them in one class: both in D′D', or both in DD. If only xx is adjacent to vv, then the new labels are A∪{v}A \cup \{v\} and AA, with symmetric difference {v}\{v\}, so xx's label is larger. Line L8 moves xx to D′D', which is just before DD, where yy stays.
  • If they were in classes XX before YY, the old labels have ℓ(x)≻ℓ(y)\ell(x) \succ \ell(y), and the first vertex uu of ℓ(x)△ℓ(y)\ell(x) \triangle \ell(y) is in ℓ(x)\ell(x). The vertex vv is visited after uu, so adding vv to one or both labels does not change the first vertex of the symmetric difference, and the new labels still differ, with xx's larger. The class of xx after the step is XX or the new class just before XX, and that of yy is YY or the new class just before YY. Both of these are still before YY's classes, because the new class of YY is inserted directly before YY and after XX (if XX is directly before YY, the new class of YY 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 i+1i + 1.

Lemma 1. The order σ\sigma returned by LEXBFS obeys the LexBFS rule, and its first vertex is ss.

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 ss is first. □\square

Termination. Each step visits one vertex, the loop of line L2 runs nn times, and each step scans one finite list.

Part 2: the four-point property

Lemma 2. Let σ\sigma be any order that obeys the LexBFS rule. If a<σb<σca <_\sigma b <_\sigma c, ac∈Eac \in E and ab∉Eab \notin E, then there is a vertex d<σad <_\sigma a with db∈Edb \in E and dc∉Edc \notin E.

Proof. Consider the step at which bb is chosen. Then aa is visited and cc is not, and bb has a largest label, so ℓ(b)⪰ℓ(c)\ell(b) \succeq \ell(c). Now a∈ℓ(c)a \in \ell(c) and a∉ℓ(b)a \notin \ell(b), so the labels differ, and ℓ(b)≻ℓ(c)\ell(b) \succ \ell(c). Let dd be the first visited vertex of ℓ(b)△ℓ(c)\ell(b) \triangle \ell(c). Then d∈ℓ(b)d \in \ell(b) and d∉ℓ(c)d \notin \ell(c). Since aa is in the symmetric difference, d≤σad \le_\sigma a, and d≠ad \ne a because a∉ℓ(b)a \notin \ell(b). So d<σad <_\sigma a, db∈Edb \in E and dc∉Edc \notin E. □\square

Part 3: chordal graphs

For a vertex xx, let E(x)E(x) be the set of its neighbours y<σxy <_\sigma x. The reverse of σ\sigma is a perfect elimination ordering exactly when E(x)E(x) is a clique for every xx, because the neighbours of xx that come after xx in the reverse order are those that come before xx in σ\sigma.

Lemma 3. Let σ\sigma obey the LexBFS rule on a chordal graph GG. Then there are no two non-adjacent vertices u<σwu <_\sigma w joined by a path whose internal vertices are all visited after ww.

Proof. Assume such pairs exist, and choose one, (u,w)(u, w), with uu as early in σ\sigma as possible. Among the paths for this pair, choose a shortest one, P=u,z,…,wP = u, z, \ldots, w. It has at least one internal vertex, since uw∉Euw \notin E. It is chordless: a chord would give a shorter path between uu and ww whose internal vertices are a subset of those of PP.

Apply Lemma 2 to u<σw<σzu <_\sigma w <_\sigma z: uz∈Euz \in E and uw∉Euw \notin E. It gives d<σud <_\sigma u with dw∈Edw \in E and dz∉Edz \notin E.

The walk d,w,…,z,ud, w, \ldots, z, u, which is dd followed by PP backwards, is a path from dd to uu, because dd is not on PP: every vertex of PP is uu or after it. Its internal vertices are ww and the internal vertices of PP, and they are all visited after uu, and d<σud <_\sigma u. If du∉Edu \notin E, then (d,u)(d, u) is a pair of the forbidden kind with d<σud <_\sigma u, which contradicts the choice of uu. So du∈Edu \in E.

Now dd is adjacent to uu and to ww, but not to zz. Walk along PP from uu, and let yy be the first vertex after uu that is adjacent to dd. It exists, because ww is adjacent to dd, and y≠zy \ne z. The cycle d,u,z,…,y,dd, u, z, \ldots, y, d has at least 4 vertices, because the part of PP from uu to yy has at least 3. It has no chord: the part of PP is chordless, uu and yy are not adjacent because PP is chordless and y≠zy \ne z, and dd is adjacent to no vertex strictly between uu and yy by the choice of yy. A chordless cycle of length at least 4 contradicts that GG is chordal. □\square

Theorem 1 (Rose, Tarjan and Lueker). Let σ\sigma be an order that obeys the LexBFS rule, in particular the output of LEXBFS. Then GG is chordal if and only if the reverse of σ\sigma is a perfect elimination ordering.

Proof. Let GG be chordal, and assume that some E(c)E(c) contains two non-adjacent vertices a<σba <_\sigma b. Then a,c,ba, c, b is a path between the non-adjacent vertices a<σba <_\sigma b whose only internal vertex cc is visited after bb. Lemma 3 forbids this. So every E(x)E(x) is a clique.

Conversely, let every E(x)E(x) be a clique, and let CC be a cycle of length at least 4. Let xx be the vertex of CC visited last. Its two neighbours on CC are in E(x)E(x), so they are adjacent. They are not consecutive on CC, because CC has length at least 4, so this edge is a chord. So GG is chordal. ■\blacksquare

Lemma 4 (the linear-time test). For each xx with E(x)≠∅E(x) \ne \emptyset, let p(x)p(x) be the vertex of E(x)E(x) visited last. Then every E(x)E(x) is a clique if and only if, for every xx, each vertex of E(x)∖{p(x)}E(x) \setminus \{p(x)\} is adjacent to p(x)p(x).

Proof. If every E(x)E(x) is a clique, the test holds. Conversely, assume the test holds, and show that E(x)E(x) is a clique by induction on the position of xx in σ\sigma. Take y≠zy \ne z in E(x)E(x). If one of them is p(x)p(x), they are adjacent by the test. If not, both are adjacent to p(x)p(x) by the test and are visited before p(x)p(x), so both are in E(p(x))E(p(x)), which is a clique by the induction hypothesis, since p(x)<σxp(x) <_\sigma x. □\square

Corollary. LEXBFS followed by the test of Lemma 4 decides in O(n+m)O(n + m) time whether GG is chordal, and if it is, the reverse of σ\sigma is a perfect elimination ordering. This follows from Lemma 1, Theorem 1 and Lemma 4. ■\blacksquare

Back to Lexicographic breadth-first search