Interactive Graph Theory Learning
Interactive Graph Theory Learning
Guest User
Using app without sign in
Chordal graph checker
Determines if graph is chordal (every cycle ≥4 has chord)
Select an algorithm and generate steps to begin visualization
A graph is chordal when every cycle of four or more vertices has a chord, an edge connecting two non-consecutive vertices of the cycle. Chordal graphs are a well-behaved class where many NP-hard problems, including coloring and maximum clique, become solvable in polynomial time.
Chordality is tested with Lexicographic BFS (Lex-BFS), which orders the vertices in O(V + E) time. A graph is chordal exactly when the reverse of this order is a perfect elimination ordering, meaning each vertex together with its later neighbors forms a clique, a condition checked in linear time. The same ordering then yields optimal coloring and maximum cliques greedily.
Chordal graphs enable efficient Gaussian elimination with minimal fill-in for sparse matrices, exact inference in probabilistic graphical models through junction trees, perfect phylogeny in computational biology, and register allocation for structured programs. They are a gateway topic into perfect graph theory.
Testing chordality directly, by hunting for a long chordless cycle, is expensive. The standard route is indirect: find a candidate perfect elimination ordering, then verify it.
// Step 1: maximum cardinality search
weight[v] = 0 for all v; order = []
repeat V times:
pick unnumbered v with the largest weight
order.prepend(v)
for each unnumbered neighbor n of v: weight[n]++
// Step 2: verify it is a perfect elimination ordering
for each v in order, at position i:
later = neighbors of v appearing after i
if later is empty: continue
w = the earliest vertex in later
if any u in later is not adjacent to w:
return NOT chordal
return chordalA perfect elimination ordering is one where each vertex, together with its later neighbours, forms a clique. A graph is chordal exactly when such an ordering exists. Maximum cardinality search always produces one if the graph is chordal, so the verification step is what turns a heuristic ordering into a proof, and it is also what detects the failure when no such ordering exists.
Test a four-cycle for chordality, then add one chord and test again.
Example graph: First the 4-cycle A-B, B-C, C-D, D-A. Then the same graph with the chord A-C added.
The plain 4-cycle is not chordal; adding the single chord A-C makes it chordal. This is the definition made concrete: a graph is chordal when every cycle of four or more vertices has an edge joining two non-consecutive vertices of that cycle. The 4-cycle is the smallest possible counterexample, which is why it is the standard test case.
Time: O(V + E) · Space: O(V + E)
Maximum cardinality search runs in O(V + E) when implemented with buckets of vertices by weight, so that selecting the maximum and incrementing neighbours are both amortised constant. The verification pass examines each vertex once and each of its later neighbours once, which totals O(V + E) provided adjacency queries are constant time via a hash set. So the whole test is linear, which is a genuinely surprising result: the naive approach of enumerating cycles and checking each for a chord is exponential, and even a smarter cycle-based method would be far worse. Lexicographic BFS is an alternative to MCS with the same bound.
Chordality is usually a gateway: once a graph is known to be chordal, several NP-hard problems become linear on it.
| Alternative | Prefer it when | Cost |
|---|---|---|
| Maximum clique on a chordal graph | The graph is chordal. NP-hard in general, but linear here via the elimination ordering. | O(V + E) |
| Graph colouring on a chordal graph | Chordal graphs are perfect, so greedy colouring in reverse elimination order is exactly optimal. | O(V + E) |
| Tree decomposition | You want to exploit low treewidth. Chordal graphs are exactly those of treewidth equal to max clique minus 1. | O(V + E) when chordal |
| Lexicographic BFS | An alternative to MCS for producing the candidate ordering. Same complexity, different constant factors. | O(V + E) |
Read the full article: Graph Algorithms and Their Complexity
Related algorithms: Graph Coloring, Maximal Clique, Breadth-First Search