A chordal graph is a special kind of graph. Many NP-hard problems on general graphs have efficient linear-time algorithms on chordal graphs.
Definitions and properties
Subgraph: A graph whose vertex set and edge set are subsets of those of the original graph.
Induced subgraph: A graph whose vertex set is a subset of the original vertex set, and whose edge set contains every edge whose two endpoints both belong to the selected vertex set.
Clique: A complete subgraph.
Maximal clique: A clique that is not a subgraph of any other clique.
Maximum clique: A clique with the largest number of vertices.
Clique number: The number of vertices in a maximum clique, denoted by .
Minimum coloring: Coloring vertices with as few colors as possible so that the endpoints of every edge have different colors.
Chromatic number: The number of colors in a minimum coloring, denoted by .
Maximum independent set: The largest vertex set in which no two vertices are directly connected by an edge. Its size is denoted by .
Minimum clique cover: Covering all vertices with as few cliques as possible. The number of cliques used is denoted by .
Chord: An edge connecting two nonadjacent vertices on a cycle.
Chordal graph: A graph in which every cycle of length greater than has a chord.
Lemma 1: Clique number chromatic number.
Proof: Consider coloring the induced subgraph of a maximum clique alone. At least colors are required.
Lemma 2: Maximum independent-set size minimum clique-cover size.
Proof: At most one vertex can be selected from each clique.
Lemma 3: Every induced subgraph of a chordal graph is chordal.
Proof: If a chordal graph had an induced subgraph that was not chordal, that induced subgraph would contain a chordless cycle of length greater than . No matter how edges are added to the original graph, this would not make the original graph chordal, a contradiction.
Lemma 4: No induced subgraph of a chordal graph can be a cycle with more than vertices.
Proof: A cycle with more than vertices is not chordal, so the result follows from the preceding lemma.
Recognizing chordal graphs
Problem statement
Given an undirected graph, determine whether it is chordal.
Vertex separators
In a graph , for two vertices , define a vertex separator between them as a set whose deletion leaves disconnected. If no proper subset of a vertex separator between is also a vertex separator, call it a minimal vertex separator.
Lemma 5: A minimal vertex separator for divides the original graph into several connected components. Let be the component containing and the component containing . For every vertex in the minimal vertex separator, contains vertices from both and .
Proof: If contained vertices from at most one of and , deleting from the vertex separator would still leave the two vertices disconnected, so the original separator would not be minimal.
Lemma 6: In a chordal graph, the induced subgraph of every minimal vertex separator between two vertices is a clique.
Proof: If the minimal vertex separator has size , its induced subgraph is clearly a clique.
Otherwise, let two vertices in the minimal vertex separator be . By Lemma 5, contains vertices from , say ; likewise, let them be . Note that it is possible that .
Since are connected components, there are shortest paths between and between . Let be the two separator vertices, and let the shortest paths through the interiors of be . Then the graph contains the cycle , whose length is . By the definition of a chordal graph, this cycle has a chord.
If the chord connects the two components , the vertex set is not a vertex separator. If it connects two vertices inside one component, or a vertex inside one component with a vertex in the vertex separator, it contradicts the shortest-path property. Therefore the chord can only connect .
Thus, every two vertices in a minimal vertex separator of a chordal graph are directly connected by an edge, proving the lemma.
Simplicial vertices
Let denote the set of vertices adjacent to . If the induced subgraph on is a clique, then is called a simplicial vertex.
Lemma 7: Every chordal graph has at least one simplicial vertex; a chordal graph that is not complete has at least two nonadjacent simplicial vertices.
Proof: By mathematical induction. Consider each connected component separately.
Induction base: If the graph is isomorphic to a complete graph, every vertex is simplicial. If the graph has at most vertices, the lemma holds.
If the graph has vertices and is not complete, there must be with . Let be a minimal vertex separator between . Let be the connected components containing in the induced subgraph obtained after deleting . By symmetry, consider only the side containing , and let . If is complete, then is simplicial. Otherwise, since is an induced subgraph of the original graph, it is chordal, so it has two nonadjacent simplicial vertices. Since is a clique, its vertices are pairwise adjacent, so at least one of those simplicial vertices lies in . That simplicial vertex remains simplicial when extended to the whole graph.
Since each step divides the whole graph into connected components of strictly smaller size, all of which satisfy the property, the induction is complete.
Perfect elimination ordering
Let . A perfect elimination ordering is a permutation of such that is simplicial in the induced subgraph on .
Lemma 8: An undirected graph is chordal if and only if it has a perfect elimination ordering.
Sufficiency: A chordal graph with vertex has a perfect elimination ordering. By Lemma 3 and Lemma 7, a perfect elimination ordering of a chordal graph with vertices can be obtained by taking a perfect elimination ordering of a chordal graph with vertices and appending a simplicial vertex.
Necessity: Suppose an undirected graph has a cycle with vertices and has a perfect elimination ordering. Let be the first vertex of the cycle to appear in the ordering, and suppose the first vertex is and its two neighbors on the cycle are . The definition of a simplicial vertex and the property of a perfect elimination ordering imply that are directly connected, a contradiction.
Naive algorithm
Each time, find a simplicial vertex and add it to the perfect elimination ordering.
Delete vertex and all edges incident to it from the graph.
Repeat the process. If every vertex is deleted, the original graph is chordal and a perfect elimination ordering has been found; if the graph has no simplicial vertex, the original graph is not chordal.
The time complexity is .
MCS algorithm
Maximum Cardinality Search is an algorithm that finds a perfect elimination ordering of an undirected graph in time.
Number the vertices in reverse order, that is, from down to .
Let denote the number of already numbered vertices adjacent to vertex . At each step, number the unnumbered vertex with the largest .
Use linked lists to maintain, for each , the vertices satisfying .
Since every edge contributes at most to , the time complexity is .
Correctness proof:
Let be the position of in this ordering. We need to prove that, for every chordal graph, the ordering produced by the algorithm is a perfect elimination ordering; that is, all vertices after a given vertex in the ordering and adjacent to it are pairwise adjacent.
Lemma 9: Consider three vertices satisfying . If is an edge but is not, then contributes to the of but not to that of . For to be added to the ordering before , there must be an with such that is an edge but is not; that is, contributes to but not to .
Lemma 10: A chordal graph cannot contain a sequence satisfying all of the following:
- is an edge if and only if .
- .
- There exists such that and .
Proof:
Since , is an edge, and is not, property 1 implies that there is an with such that is an edge but is not.
Let be the smallest index for which is an edge. We can conclude that is not an edge; otherwise would form a chordless cycle of length .
If , then is another sequence satisfying the properties. If , then is such a sequence.
In this derivation, we increased . Continuing in this way must eventually produce a contradiction.
Theorem 1: For every chordal graph, the ordering produced by Maximum Cardinality Search is a perfect elimination ordering.
Proof: Consider any three vertices with . We need to prove that if and are edges, then is also an edge.
Suppose otherwise. Then form a sequence satisfying the properties in Lemma 10, but we have proved that no such sequence exists, a contradiction. Therefore is an edge.
Reference code:
while (cur) {
p[cur] = h[nww];
rnk[p[cur]] = cur;
h[nww] = nxt[h[nww]];
lst[h[nww]] = 0;
lst[p[cur]] = nxt[p[cur]] = 0;
tf[p[cur]] = true;
for (vector<int>::iterator it = G[p[cur]].begin(); it != G[p[cur]].end();
it++)
if (!tf[*it]) {
if (h[deg[*it]] == *it) h[deg[*it]] = nxt[*it];
nxt[lst[*it]] = nxt[*it];
lst[nxt[*it]] = lst[*it];
lst[*it] = nxt[*it] = 0;
deg[*it]++;
nxt[*it] = h[deg[*it]];
lst[h[deg[*it]]] = *it;
h[deg[*it]] = *it;
}
cur--;
if (h[nww + 1]) nww++;
while (nww && !h[nww]) nww--;
}
If the original graph is chordal, the result at this point is a perfect elimination ordering. However, since the original graph may not be chordal, the result is then certainly not a perfect elimination ordering. The problem is therefore reduced to checking whether the computed ordering is a perfect elimination ordering of the original graph.
Checking whether an ordering is a perfect elimination ordering
Naive algorithm
By definition, in the perfect elimination ordering , check whether the vertices in adjacent to form a clique. The time complexity is .
Optimized algorithm
By the definition of a perfect elimination ordering, let the vertices adjacent to in , in increasing order, be . It is enough to check whether is directly connected to every other vertex. The time complexity is .
jud = true;
for (int i = 1; i <= n; i++) {
cur = 0;
for (vector<int>::iterator it = G[p[i]].begin(); it != G[p[i]].end(); it++)
if (rnk[p[i]] < rnk[*it]) {
s[++cur] = *it;
if (rnk[s[cur]] < rnk[s[1]]) swap(s[1], s[cur]);
}
for (int j = 2; j <= cur; j++)
if (!st[s[1]].count(s[j])) {
jud = false;
break;
}
}
if (!jud)
printf("Imperfect\n");
else
printf("Perfect\n");
Thus, the chordal graph recognition problem can be solved in time.
Maximal cliques of chordal graphs
Let be the sequence of vertices directly adjacent to that occur after in the perfect elimination ordering. Every maximal clique of a chordal graph is of the form .
Proof: Consider a maximal clique of a chordal graph, and let be the first vertex in the clique to appear in the perfect elimination ordering. Then . Since is maximal, .
A chordal graph has at most maximal cliques. To find all maximal cliques, we can determine whether each is maximal.
Let . If , then is not maximal. In this case, clearly appears before in the perfect elimination ordering.
Let be the earliest vertex in in the perfect elimination ordering, and let be the latest among all satisfying . Then necessarily ; otherwise replacing it by would still satisfy the condition, so the chosen would not be the latest.
if and only if .
The problem is reduced to checking whether there exists a satisfying and . The time complexity is .
for (int i = 1; i <= n; i++) {
cur = 0;
for (vector<int>::iterator it = G[p[i]].begin(); it != G[p[i]].end(); it++)
if (rnk[p[i]] < rnk[*it]) {
s[++cur] = *it;
if (rnk[s[cur]] < rnk[s[1]]) swap(s[1], s[cur]);
}
fst[p[i]] = s[1];
N[p[i]] = cur;
}
for (int i = 1; i <= n; i++) {
if (!vis[p[i]]) ans++;
if (N[p[i]] >= N[fst[p[i]]] + 1) vis[fst[p[i]]] = true;
}
Chromatic and clique numbers of chordal graphs
One construction method is to color the vertices one by one in reverse perfect elimination order, assigning each vertex the smallest available color. The time complexity is .
Correctness proof: If this method uses colors, then . Every vertex in a clique has a different color, so . By Lemma 1, . Therefore .
If only the chromatic/clique number is needed, without constructing a coloring, take the maximum of .
for (int i = 1; i <= n; i++) ans = max(ans, deg[i] + 1);
Maximum independent set and minimum clique cover of chordal graphs
Maximum independent set: Traverse the perfect elimination ordering from beginning to end, selecting every vertex that has no edge to any previously selected vertex.
Minimum clique cover: Let the maximum independent set be . Then the collection of cliques is a minimum clique cover of the graph. Both procedures have time complexity .
Correctness proof: Let the independent-set size and clique-cover size produced above be . By definition, . By Lemma 2, , so .
for (int i = 1; i <= n; i++)
if (!vis[p[i]]) {
ans++;
for (vector<int>::iterator it = G[p[i]].begin(); it != G[p[i]].end(); it++)
vis[*it] = true;
}
Exercises
P3196 [HNOI2008] The Magical Land