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 be a simple undirected graph with vertices. Write if is visited before . Before step , the weight of an unvisited is , and is the set that it counts.
Part 1: the algorithm follows the MCS rule
Invariant. At the start of step (before line L3): for each unvisited , and ; the buckets hold no visited vertex; and, if some vertex is unvisited, 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 in with , and .
Maintenance. Step takes from at line L3 and marks it at line L4, so it leaves the buckets. For an unvisited , the new weight is if and otherwise. Lines L5 and L6 run exactly for the unvisited neighbours of , each one time, because the graph is simple. Each such 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 . After it, every weight is at most . So after line L7, no bucket above is non-empty, and line L8 lowers to the largest non-empty bucket, or to if all buckets are empty, which happens only when all vertices are visited.
Lemma 1. The order returned by MCS obeys the MCS rule.
Proof. By the invariant, at step the bucket holds the unvisited vertices of largest weight, and it is not empty because some vertex is unvisited. Line L3 takes one of them.
Termination. Each step visits one vertex, and line L2 runs times. Each step scans one finite list. The loop of line L8 lowers each time and stops at at the latest.
Part 2: the weak four-point property
Lemma 2. Let be any order that obeys the MCS 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 the largest weight, so . Now , so . Because
there is a vertex . It is visited before , it is a neighbour of , and it is not a neighbour of .
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 MCS 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. Call such a pair bad. Assume bad pairs exist, and choose one in which the later vertex is as early in as possible. Among the paths for this pair, choose a shortest one, . It has at least one internal vertex, since , so is internal and . The path is chordless: a chord would give a shorter path between and whose internal vertices are a subset of those of .
Apply Lemma 2 to , with and . It gives with and . Then , because . Also is not on : every vertex of other than is or after .
The walk , which is followed by backwards, is a path from to . Its internal vertices are and the internal vertices of , and they are all visited after , so after both and . If , then the pair of and , in the order of , is bad, and its later vertex is before . This 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 is not the next vertex after , 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 (Tarjan and Yannakakis). Let be an order that obeys the MCS rule, in particular the output of MCS. 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. MCS 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.