Algorithm Search⌘K

Proofs: Maximum cardinality search

These are the human proofs of Maximum cardinality search, at full length.

MCS computes a maximum cardinality search 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. Before step ii, the weight of an unvisited xx is w(x)=∣N(x)∩{v1,…,vi−1}∣w(x) = |N(x) \cap \{v_1, \ldots, v_{i-1}\}|, and ℓ(x)=N(x)∩{v1,…,vi−1}\ell(x) = N(x) \cap \{v_1, \ldots, v_{i-1}\} is the set that it counts.

Part 1: the algorithm follows the MCS rule

Invariant. At the start of step ii (before line L3): for each unvisited xx, size[x]=w(x)\mathrm{size}[x] = w(x) and x∈B[w(x)]x \in B[w(x)]; the buckets hold no visited vertex; and, if some vertex is unvisited, jj is the largest index of a non-empty bucket.

Initialization. Before step 1, no vertex is visited, every weight is 0, line L1 puts all of VV in B[0]B[0] with size=0\mathrm{size} = 0, and j=0j = 0.

Maintenance. Step ii takes vv from B[j]B[j] at line L3 and marks it at line L4, so it leaves the buckets. For an unvisited xx, the new weight is w(x)+1w(x) + 1 if x∈N(v)x \in N(v) and w(x)w(x) otherwise. Lines L5 and L6 run exactly for the unvisited neighbours of vv, each one time, because the graph is simple. Each such xx moves one bucket up and its size grows by 1, so the first two parts hold after the step. Before the step, every weight was at most jj. After it, every weight is at most j+1j + 1. So after line L7, no bucket above jj is non-empty, and line L8 lowers jj to the largest non-empty bucket, or to −1-1 if all buckets are empty, which happens only when all vertices are visited.

Lemma 1. The order σ\sigma returned by MCS obeys the MCS rule.

Proof. By the invariant, at step ii the bucket B[j]B[j] holds the unvisited vertices of largest weight, and it is not empty because some vertex is unvisited. Line L3 takes one of them. □\square

Termination. Each step visits one vertex, and line L2 runs nn times. Each step scans one finite list. The loop of line L8 lowers jj each time and stops at −1-1 at the latest.

Part 2: the weak four-point property

Lemma 2. Let σ\sigma be any order that obeys the MCS rule. If a<σb<σca <_\sigma b <_\sigma c, ac∈Eac \in E and ab∉Eab \notin E, then there is a vertex d<σbd <_\sigma b 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 the largest weight, so ∣ℓ(b)∣≥∣ℓ(c)∣|\ell(b)| \ge |\ell(c)|. Now a∈ℓ(c)∖ℓ(b)a \in \ell(c) \setminus \ell(b), so ∣ℓ(c)∖ℓ(b)∣≥1|\ell(c) \setminus \ell(b)| \ge 1. Because

∣ℓ(b)∖ℓ(c)∣=∣ℓ(b)∣−∣ℓ(b)∩ℓ(c)∣≥∣ℓ(c)∣−∣ℓ(b)∩ℓ(c)∣=∣ℓ(c)∖ℓ(b)∣≥1,|\ell(b) \setminus \ell(c)| = |\ell(b)| - |\ell(b) \cap \ell(c)| \ge |\ell(c)| - |\ell(b) \cap \ell(c)| = |\ell(c) \setminus \ell(b)| \ge 1,

there is a vertex d∈ℓ(b)∖ℓ(c)d \in \ell(b) \setminus \ell(c). It is visited before bb, it is a neighbour of bb, and it is not a neighbour of cc. □\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 MCS 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. Call such a pair (u,w)(u, w) bad. Assume bad pairs exist, and choose one in which the later vertex ww is 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, so zz is internal and w<σzw <_\sigma z. The path 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, with uz∈Euz \in E and uw∉Euw \notin E. It gives d<σwd <_\sigma w with dw∈Edw \in E and dz∉Edz \notin E. Then d≠ud \ne u, because uz∈Euz \in E. Also dd is not on PP: every vertex of PP other than uu is ww or after ww.

The walk d,w,…,z,ud, w, \ldots, z, u, which is dd followed by PP backwards, is a path from dd to uu. Its internal vertices are ww and the internal vertices of PP, and they are all visited after ww, so after both dd and uu. If du∉Edu \notin E, then the pair of dd and uu, in the order of σ\sigma, is bad, and its later vertex is before ww. This contradicts the choice of ww. 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 yy is not the next vertex zz after uu, 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 (Tarjan and Yannakakis). Let σ\sigma be an order that obeys the MCS rule, in particular the output of MCS. 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. MCS 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 Maximum cardinality search