Interactive Graph Theory Learning
Interactive Graph Theory Learning
Guest User
Using app without sign in
Maximal clique finder
Finds largest complete subgraph (all vertices connected)
Select an algorithm and generate steps to begin visualization
A clique is a set of vertices that are all pairwise connected. A maximal clique cannot be extended by adding another vertex, and finding all maximal cliques, or the single largest one, is a fundamental NP-hard problem in network analysis.
The Bron-Kerbosch algorithm enumerates all maximal cliques by recursive backtracking over three sets: the current clique R, candidates P that connect to all of R, and excluded vertices X already covered. Choosing a good pivot dramatically prunes the recursion, and processing vertices in degeneracy order gives the best known enumeration bound of O(3 to the power n/3), matching the maximum possible number of maximal cliques.
Clique detection finds tightly knit communities in social networks, protein interaction complexes in biology, correlated assets in finance, and co-purchased product groups in recommender systems. Clique problems are also the standard vehicle for teaching NP-completeness reductions.
Bron-Kerbosch explores with three sets: R is the clique built so far, P holds candidates that could still extend it, and X holds vertices already tried. A clique is maximal exactly when P and X are both empty.
BronKerbosch(R, P, X):
if P and X are both empty:
report R as a maximal clique
return
for each vertex v in P:
BronKerbosch(R + {v},
P intersect neighbors(v),
X intersect neighbors(v))
P = P - {v}
X = X + {v}
// With pivoting: choose a pivot u from P union X and
// only branch on v in P that are NOT neighbors of uX is the part people leave out, and without it the algorithm reports non-maximal cliques. When a vertex has already been explored at this level it moves into X, so any clique that could have included it is rejected as not maximal. The pivot refinement then cuts the branching factor sharply: every maximal clique must contain the pivot or one of its non-neighbours, so branching on the rest is wasted work.
Enumerate all maximal cliques of a six-edge graph that contains two overlapping triangles and a pendant edge.
Example graph: Undirected edges A-B, A-C, B-C, B-D, C-D and D-E.
The maximal cliques are {A, B, C}, {B, C, D} and {D, E}. The maximum clique, meaning the largest one, has size 3 and there are two of them. Note that maximal and maximum are different: {D, E} is maximal because nothing can extend it, but it is far from maximum. Note too that B and C appear in two maximal cliques each, which is normal and is why the count of maximal cliques can be much larger than the vertex count.
Time: O(3^(V/3)) · Space: O(V^2)
The bound comes from the Moon-Moser theorem: a graph on V vertices can have at most 3 to the power V/3 maximal cliques, and that bound is tight, achieved by a complete multipartite graph of V/3 triangles. Since the algorithm must at minimum print every one of them, no enumeration algorithm can beat that in the worst case, and Bron-Kerbosch with pivoting matches it. This is worth internalising: the algorithm is optimal, but the problem itself is exponential. Finding just the single largest clique is NP-hard, and even approximating it within any reasonable factor is hard. In practice, pivoting and a degeneracy vertex ordering make sparse real-world graphs with tens of thousands of vertices tractable, because sparse graphs have far fewer maximal cliques than the worst case.
Decide first whether you want every maximal clique or just the biggest one, because they are different problems with different tools.
| Alternative | Prefer it when | Cost |
|---|---|---|
| Bron-Kerbosch with pivoting | You want all maximal cliques. The standard choice, and worst-case optimal. | O(3^(V/3)) |
| Degeneracy ordering variant | Sparse real-world graphs. Ordering by degeneracy d gives a much better practical bound. | O(d·V·3^(d/3)) |
| Max-clique branch and bound | You only need the single largest clique, not the full enumeration. Colouring bounds prune hard. | exponential, but far faster in practice |
| Complement plus independent set | Your problem is naturally about mutually non-adjacent vertices. A clique in G is an independent set in the complement of G. | equivalent |
| Triangle enumeration | You only care about cliques of size 3, which is a much easier special case. | O(E^1.5) |
Read the full article: Applications of Graph Theory in the Real World
Related algorithms: Graph Coloring, Chordality Check, Bipartite Check