A clique is a set of pairwise adjacent vertices; an independent set is a set of pairwise non-adjacent vertices. They are the same problem on complementary graphs:
And minimum vertex cover is the complement of a maximum independent set:
All three are NP-hard in general.
The tractable cases
| Graph class | Complexity |
|---|---|
| Bipartite | P — König: MVC = max matching, MIS = − max matching |
| Tree | P — linear tree DP |
| Interval graph | P — greedy by right endpoint |
| Chordal graph | P — perfect elimination ordering |
| Perfect graph | P (via SDP; impractical but polynomial) |
| Planar | still NP-hard, but has a PTAS |
| Bounded treewidth | P — DP over a tree decomposition |
| General | NP-hard, inapproximable within |
Check for bipartiteness first. A great many “select a maximum set with no two conflicting” problems are secretly bipartite matching.
Tree DP for maximum weight independent set
void dfs(int u, int p) {
dp[u][0] = 0; dp[u][1] = w[u];
for (int v : adj[u]) {
if (v == p) continue;
dfs(v, u);
dp[u][0] += max(dp[v][0], dp[v][1]);
dp[u][1] += dp[v][0]; // v cannot be chosen
}
}
// answer: max(dp[root][0], dp[root][1]). See Tree DP.
Exact algorithms for general graphs
| Method | Time | Feasible |
|---|---|---|
| Brute force over subsets | 20 | |
| Bron-Kerbosch with pivoting | 40-60 | |
| Bron-Kerbosch with bitsets | , tiny constant | 100-150 |
| Branch and bound with a colouring bound | exponential, strong pruning | 100-1000 (sparse) |
| Meet in the middle | 40-50 | |
| Degeneracy-ordered Bron-Kerbosch | large sparse graphs |
is the maximum possible number of maximal cliques (Moon-Moser), so Bron-Kerbosch is worst-case optimal for enumeration.
Meet in the middle for max independent set
Split the vertices into halves and ( each):
- Enumerate all independent subsets of .
- For each subset , compute the set of -vertices compatible with it (a bitmask AND).
- Precompute, for every subset of , the maximum-weight independent subset within it — an SOS-style DP over supersets.
- Combine.
— handles . See Meet in the Middle.
The colouring bound
The key pruning for branch and bound: greedily colour the candidate set; a clique within it cannot exceed the number of colours used.
// order candidates by greedy colouring; prune when
// current_clique_size + colours_remaining <= bestCheap to compute, and far tighter than “candidate count”. It is what makes modern max-clique solvers handle graphs with hundreds of vertices.
Bitset representation
For , store each vertex’s neighbourhood as a bitset. Then is one AND, and iterating the candidates uses _Find_next:
bitset<128> adj[128];
bitset<128> newP = P & adj[v]; // O(n/64)This is a 64× speedup and is what turns Bron-Kerbosch from "" into "". See Bitset Optimization.
Approximation and hardness
| Problem | Best known | Hardness |
|---|---|---|
| Max clique | inapproximable | |
| Max independent set | same | same |
| Min vertex cover | 2 | no better than 1.36 (2 under UGC) |
| MIS on bounded-degree |
Independent set is one of the hardest problems to approximate; vertex cover, its complement, is one of the easiest. The asymmetry comes from the objective: a 2-approximation for a small cover corresponds to a terrible approximation for the large complementary set.
Parameterized results
Vertex cover is FPT: for a cover of size , via branching on an uncovered edge plus kernelisation to vertices. Independent set (parameterized by solution size) is W[1]-hard — no FPT algorithm expected. See Parameterized Complexity.
See also: Bron-Kerbosch · Bipartite Matching · Parameterized Complexity