NP membership · Reduction construction · Forward & backward correctness · Polynomiality → See 🔐 NP-Completeness tab
Brute-force + greedy implemented · Side-by-side comparison · Growth-curve visualization → See 🔬 Visualizer & ⚖️ Comparison tabs
Paradigm identified · Design justified · Approximation ratio · Valid counterexample → See ⚙️ Algorithm Design collapsible below
Given an undirected graph G = (V, E) and an integer k, does there exist a subset S ⊆ V with |S| ≥ k such that for every pair u, v ∈ S, the edge (u,v) ∉ E?
S is an independent set if and only if V \ S is a vertex cover. This elegant duality is the key to the NP-completeness reduction.
Assign non-interfering channels in a conflict graph where edges represent interference. A max independent set gives the maximum set of simultaneous transmissions.
Compilers build interference graphs where variables that are "live" simultaneously are connected. A maximum independent set gives variables that can share a register.
Find the largest group of people with no mutual friendship edges — e.g., finding a diverse committee where no two members know each other.
Protein compatibility: vertices are proteins, edges connect incompatible pairs. A max independent set is the largest compatible protein set.
Cormen, Leiserson, Rivest, Stein — Introduction to Algorithms, Chapter 34. Also: Garey & Johnson, Computers and Intractability (1979). Wikipedia: Independent set (graph theory).
A greedy algorithm builds a solution incrementally by making the locally optimal choice at each step and never reconsidering past decisions. For Independent Set the greedy rule is: at each iteration, pick the vertex with the minimum current degree in the remaining induced subgraph, add it to the independent set S, then remove it and all its neighbours from the graph.
When vertex v is added to S, all neighbours N(v) are removed from future consideration. Choosing the vertex with the fewest neighbours eliminates the fewest other vertices, leaving the largest possible residual graph for subsequent iterations. Formally: if deg(v) = d in the current graph, then adding v removes at most d+1 vertices (v itself plus up to d neighbours). Minimising d maximises the expected size of the remaining graph and therefore the expected size of the final independent set.
Each of at most n iterations scans remaining vertex degrees O(n) and removes neighbours O(n). Total: O(n²). Compare with brute-force O(2ⁿ · n²).
Unlike Vertex Cover (which admits a 2-approximation), Maximum Independent Set has no
known constant-factor polynomial-time approximation unless P = NP.
Håstad (1999) proved that no polynomial algorithm can approximate MIS within
n^(1−ε) for any ε > 0, assuming P ≠ NP.
Zuckerman (2007) strengthened this to n / 2^(log n)^(1−ε).
The greedy heuristic has no proven approximation ratio — on adversarial graphs it
can produce an IS of size O(log n) while the optimum is Ω(n).
A second graph where greedy fails, traced by hand to make every decision explicit.
Graph: 6 vertices {0–5}, 7 edges: 0–1, 0–2, 1–5, 2–3, 3–4, 3–5, 4–5.
Initial degrees: 0:2, 1:2, 2:2, 3:3, 4:2, 5:3.
Brute-force verifies α(G) = 3 (optimal IS = {1, 2, 4}).
Remaining: {0, 1, 2, 3, 4, 5}
Degrees: 0:2, 1:2, 2:2, 3:3, 4:2, 5:3
S = ∅
Min degree = 2. Four-way tie: {0, 1, 2, 4}.
Lowest index → pick 0.
Remove 0 and N(0)∩rem = {1, 2}.
Remaining: {3, 4, 5} | S = {0}
Remaining: {3, 4, 5}. Edges 3–4, 3–5, 4–5 all survive.
Degrees: 3:2, 4:2, 5:2. Three-way tie.
Lowest index → pick 3.
Remove 3 and N(3)∩rem = {4, 5}.
Remaining: ∅ | S = {0, 3}
Greedy IS = {0, 3}, size 2.
Optimal IS = {1, 2, 4}, size 3.
Gap = 1. Greedy is suboptimal.
Validity of optimal: 1–2 ∉ E ✓, 1–4 ∉ E ✓, 2–4 ∉ E ✓
Both counterexamples (the 6-vertex "Greedy Fails" preset and this graph) show the
greedy min-degree heuristic can miss the optimal IS by at least 1 vertex on carefully
chosen graphs. More importantly, for large n it can miss by a factor of
O(n / log n) — there is no constant c such that greedy always finds an IS
of size ≥ c · α(G). This is not a weakness of this specific heuristic; it reflects the
fundamental hardness of the problem (Håstad 1999).
The maximum size of an independent set in graph G. Computing α(G) is NP-hard in general, but polynomial for bipartite graphs (via König's theorem) and perfect graphs.
If S is an independent set, then V \ S is a vertex cover (every edge has at least one endpoint in V \ S). This is the key to the reduction.
S is an independent set in G if and only if S is a clique in the complement graph Ḡ. Maximum Independent Set ≡ Maximum Clique on the complement.
Independent Set ∈ NP-complete means no polynomial-time algorithm is known. Approximating it within factor n^(1-ε) is also NP-hard (Håstad 1999; Zuckerman 2007).
"A problem is in NP if, given a proposed solution, you can check it quickly — in polynomial time. For Independent Set, the proposed solution is just a list of vertices S. To verify it I do two things: first, count that |S| ≥ k; second, look at every pair of vertices in S and make sure there is no edge between them. That second check is at most |S|² steps, which is O(n²) — polynomial. So yes, Independent Set is in NP."
"The construction is almost trivially simple, which is what makes it elegant. Given any Vertex Cover instance — a graph G and a number k — I hand the solver the exact same graph G, but ask about an independent set of size |V| − k instead. No new edges, no new vertices, no complex gadgets. The key insight is that a vertex cover and an independent set are complements: if C covers all edges, then the remaining vertices V\C have no edges between them."
"Suppose G has a vertex cover C of size k — meaning every edge has at least one endpoint in C. Now look at S = V \ C, the vertices not in C. Could S contain two vertices u and v with an edge between them? No — because if (u, v) is an edge and both u, v are in S, then neither is in C, which would mean that edge is uncovered. That contradicts C being a vertex cover. So S must be an independent set, and its size is |V| − k exactly."
"Suppose G has an independent set S of size |V| − k. Let C = V \ S be the other vertices. I need to show C covers every edge. Take any edge (u, v) in G. Because S is independent, u and v cannot both be in S — so at least one of them is in C. That's exactly what a vertex cover requires: every edge has at least one endpoint in C. And |C| = |V| − |S| = k. Done."
"The reduction function f just copies the graph G and computes |V| − k. Copying G takes O(|V| + |E|) time — linear in the input size. Computing |V| − k is a single subtraction, O(1). So the entire transformation is O(|V| + |E|), which is polynomial. This matters because a reduction is only valid if you can perform it efficiently — otherwise you might be hiding the hard work inside the reduction itself."
To show a problem is in NP, we must demonstrate a polynomial-time verifier: given a certificate (proposed solution), we can check in polynomial time whether it is valid.
The certificate for Independent Set is a subset S ⊆ V with |S| ≥ k.
This certificate has size O(n) — it is a list of at most n vertex identifiers — so it can be
written down and transmitted in polynomial space.
The verifier receives three things: the graph G, the target size k,
and the proposed answer S (the claimed independent set).
It runs exactly two checks. If both pass, it accepts. If either fails, it rejects immediately.
Count the vertices in S and check that the count is at least k.
This is just a single count — it takes O(n) time
because S has at most n vertices.
|S| < k → REJECT immediately.
If |S| ≥ k → continue to Check 2.
Look at every possible pair of vertices inside S and ask:
is there an edge between them? If you find even one edge inside S,
then S is not independent and must be rejected.
|S|² ≤ n² pairs
→ O(n²) time.
(u, v) both in S:
if edge (u, v) exists in G
→ REJECT.
If no such pair found → ACCEPT.
Total verification time: O(n²) — polynomial in the input size. Therefore Independent Set ∈ NP. ✓ NP Membership Shown
Knowing IS ∈ NP means we can check a proposed solution quickly. It says nothing about how hard it is to find one in the first place. The only known exact algorithm tries every possible subset — here is how that works and why it is so slow:
A graph with n vertices has exactly 2ⁿ possible subsets
(each vertex is either included or not — like a binary switch).
For n = 10 that is 1 024 subsets. For n = 50 that is
1 000 000 000 000 000 subsets — more than a quadrillion.
For each subset, check whether it is a valid independent set (run the same O(n²) pair check from the verifier above). Keep the largest valid one found.
Total work = (number of subsets) × (cost per subset) = 2ⁿ × O(n²) = O(2ⁿ · n²). The 2ⁿ term dominates and grows so fast that even the fastest computers cannot cope:
The key gap: The verifier runs in O(n²) — fast. The best known solver runs in O(2ⁿ · n²) — exponentially slow. NP-completeness is the formal statement that this gap very likely cannot be closed. If someone found a polynomial-time algorithm for IS, it would prove P = NP and solve thousands of open problems simultaneously.
We reduce the known NP-complete problem Vertex Cover to Independent Set. Since Vertex Cover is NP-complete and we show VC ≤ₚ IS, it follows that IS is NP-hard. Combined with Step 1, IS is NP-complete.
A reduction only transfers NP-hardness if the problem being reduced from is itself NP-complete. We therefore need to justify that Vertex Cover is NP-complete before we can use it as our starting point. Vertex Cover was proved NP-complete by Richard Karp in his landmark 1972 paper "Reducibility Among Combinatorial Problems", which established 21 problems as NP-complete in a single paper.
The reduction chain that grounds Vertex Cover in the original NP-complete problem is:
3-SAT is NP-complete by Cook's theorem (1971) — the foundational result that proved the first NP-complete problem from first principles. Clique ≤ₚ Vertex Cover: a clique of size k in G corresponds to an independent set of size k in the complement graph Ḡ, and the complement of that IS is a VC of size |V|−k in Ḡ — a standard complement argument. We prove Vertex Cover ≤ₚ Independent Set (this step, below) using the same complement duality directly on the original graph. Each arrow ≤ₚ denotes a polynomial-time many-one reduction, so NP-hardness propagates along the entire chain.
Given a Vertex Cover instance (G, k), output the Independent Set instance
f(G, k) = (G, |V| − k). The graph is unchanged; only the parameter is transformed.
This is a complement reduction exploiting the fact that S is an IS iff V\S is a VC.
The symbol ⇐⇒ means "if and only if" — both statements are always true or always false together, on every possible graph. This is what makes the reduction valid: solving IS automatically solves VC, and vice versa. We prove this in two halves — ⟹ (2b) and ⟸ (2c) — and together they establish the full ⇐⇒.
How we prove it: We use contradiction — assume the leftover set is not independent, then show that assumption breaks the definition of a vertex cover.
If S is not independent, then somewhere inside S there must be two vertices —
call them u and v — that are connected by an edge.
Both are in S, meaning both are outside C (since S = V \ C).
A Vertex Cover must have at least one endpoint of every edge inside C. But edge u–v has both endpoints outside C — so C misses this edge entirely. That contradicts C being a vertex cover.
The assumption led to a contradiction, so it must be false. Therefore S = V \ C is an independent set. Its size is |V| − |C| = |V| − k. ⟹ proved ✓
How we prove it: We prove it directly — we pick any edge and show C must touch it, using only the definition of an independent set.
Take any edge — call its two endpoints u and v.
We need to show that at least one of them is in C.
S is an independent set — by definition, no two vertices inside S share an edge.
But u and v do share an edge.
So they cannot both be inside S.
That means at least one of them — say u — must be outside S.
C is defined as every vertex not in S.
Since u is outside S, u is in C.
The edge u–v has an endpoint in C, so it is covered.
Since this works for any edge we choose,
C covers every edge in the graph — C is a Vertex Cover.
⟸ proved ✓
A reduction is only valid if it runs in polynomial time.
Otherwise the reduction itself could be doing the hard work,
which would make the whole argument circular.
Here is exactly what the reduction function f(G, k) does
and how long each part takes:
We keep the same graph and pass it straight through to the IS solver. Copying a graph means copying its vertex list and edge list. That takes time proportional to the size of the input: O(|V| + |E|) — linear in the input size.
This is a single subtraction. We already know |V| (the number of vertices), so computing |V| − k is one arithmetic operation: O(1).
This is called a polynomial-time many-one reduction (also known as a Karp reduction). The fact that it runs in polynomial time is what allows NP-hardness to transfer from Vertex Cover to Independent Set.
Therefore Independent Set ∈ NP-Complete. ∎ QED
Enter a Vertex Cover instance to see the equivalent Independent Set instance derived by the complement reduction.
For the 5-cycle C₅ (|V|=5): If C₅ has a Vertex Cover of size k=3 (vertices {0,1,3}), then the reduction says: C₅ has an IS of size |V|−k = 5−3 = 2. Indeed, {2,4} is an IS of size 2. Both instances are YES-instances. ✓
Tries every possible subset of vertices — all 2ⁿ of them. For each subset it checks two things: is the size ≥ k, and does any edge exist inside it? The largest valid subset found is the maximum independent set. Always correct, always slow.
Makes one local decision at a time: pick the vertex with the fewest remaining neighbours, add it to the IS, remove it and all its neighbours, repeat. Runs in O(n²). Always fast, sometimes suboptimal.
For n = 10: greedy does ~100 operations; brute force checks 1 024 subsets — both feasible, but brute force is ~10× slower. For n = 30: greedy does ~900 operations in microseconds; brute force needs ~10⁹ checks — taking over a second. For n = 50: greedy finishes instantly; brute force would take millions of years. This exponential gap is why NP-complete problems are considered intractable and why no known algorithm bridges this divide.
| |V| | Brute-Force (2ⁿ) | Greedy (n²) | Speedup | BF Feasible? |
|---|
Greedy finds a valid (not necessarily maximum) independent set. For Independent Set, no polynomial approximation within n^(1-ε) of optimal exists unless P=NP (Håstad 1999). Greedy is used as a practical heuristic, not a guaranteed approximation algorithm.