Short answer: The Bron-Kerbosch algorithm lists every maximal clique of an undirected graph. It keeps a current clique R, a set P of candidates that can still extend R, and a set X of vertices already excluded. A pivot taken from P ∪ X limits the branches to candidates outside the pivot’s neighborhood. With the pivot that minimizes that branch set, the running time is O(3^{n/3}), matching the maximum number of maximal cliques. The algorithm lists maximal cliques. It does not stop at the single largest one.
What the problem actually asks
A clique is a set of vertices with every pairwise edge present. A maximal clique cannot add another vertex and stay a clique. A graph can contain exponentially many of them, up to 3^{n/3} in the Moon-Moser bound, so any listing algorithm has an exponential worst case. The search has to avoid reporting a clique that is contained in a larger one, and it has to avoid exploring an extension that was already explored with a different vertex order.
The set X is the memory of that order. A vertex moved from P to X is finished as a sibling at this level. If the search ever reaches an empty P while X is still nonempty, every way to extend R uses a vertex that was already considered, so R is not maximal and nothing is reported.
What the algorithm guarantees
The algorithm reports each maximal clique once. With a pivot u chosen from P ∪ X to maximize the number of candidates adjacent to u, only candidates outside N(u) are branched on, and the time is O(3^{n/3}) for an n-vertex graph. Extra memory is the recursion stack and the three sets, polynomial per level and O(n) levels deep. On a sparse graph, degeneracy ordering of the outer vertices improves the bound to a function of the degeneracy rather than of n alone.
Listing every maximal clique is not the same as returning a maximum clique. The maximum-clique decision problem is NP-complete, and reading the longest list this algorithm emits would still cost time proportional to the number of maximal cliques, which can be exponential even when a single maximum clique is the only object a caller wanted.
The working steps
- Start with R and X empty and P equal to the vertex set.
- If P and X are both empty, report R. It is a maximal clique.
- Choose a pivot u in P ∪ X that maximizes the number of neighbors in P. Branch only on vertices v in P that are not neighbors of u.
- For each such v, recurse with R ∪ {v}, P ∩ N(v), and X ∩ N(v). Then move v from P to X.
- Pass adjacency tests against the graph. A missing edge means the vertex is not in N(v) and must not stay in the child candidate set.
The exponential bound is a listing bound. A single maximum clique is a different question and stays hard. Degeneracy ordering is an outer schedule around the same recursion. Bron-Kerbosch is the R, P, X search.
Approaches that look simpler and fail
| Approach | Why it fails when a clique is reported as soon as P is empty |
|---|---|
| Report R whenever P is empty | If X is nonempty, R is contained in a clique that was already branched on. Both sets have to be empty. |
| Branch on every vertex in P and skip the pivot | The cliques are still found. The 3^{n/3} time bound is the pivoted algorithm. The unpivoted search does more work. |
| Forget to move v into X after its recursion | A later sibling can rebuild the same clique through a different order, and the maximality test loses the vertices already used. |
| Intersect the child sets with the non-neighbors | The child clique can then include a missing edge. The intersection is with N(v), the neighbors. |
A maximum matching is a different exhaustive search. Bron-Kerbosch is the backtracking enumeration of maximal cliques.
A working example
This Python fragment lists every maximal clique with the sets R, P, and X. A pivot limits the branches to candidates outside the pivot’s neighborhood. On a triangle plus a pendant edge the maximal cliques are the triangle and the single extra edge. It prints 2.
adj = {0: {1, 2}, 1: {0, 2}, 2: {0, 1, 3}, 3: {2}}
def bron(r, p, x, out):
if not p and not x:
out.append(set(r))
return
union = p | x
u = max(union, key=lambda v: len(p & adj[v])) if union else None
for v in list(p - (adj[u] if u is not None else set())):
bron(r | {v}, p & adj[v], x & adj[v], out)
p.remove(v)
x.add(v)
found = []
bron(set(), set(adj), set(), found)
assert len(found) == 2 and {0, 1, 2} in found
print(len(found))
Where it is used
Bron-Kerbosch lists maximal cliques in a social graph, a protein-interaction graph, or a conflict graph. NetworkX ships the algorithm. A maximum clique, one largest set, is the harder problem this enumeration does not pretend to solve in polynomial time.
When you can drop this algorithm
Drop a full listing when the graph is large and only one large clique is needed. Use a heuristic or an integer program aimed at that single set, and accept that it may miss other maximal cliques. Keep Bron-Kerbosch when every maximal clique has to appear exactly once.
Why this stays published
We publish this so a search for Bron-Kerbosch returns the sets R, P, and X, the pivot, and the O(3^{n/3}) bound. Bron-Kerbosch lists each maximal clique once by extending R with candidates in P, excluding vertices in X, and pivoting to reach an O(3^{n/3}) bound.
本文由 HoHo 與 AI 協作整理,最後更新於 2026 年 11 月 13 日。
