Sub topic 5
First Examples: Independent Set, Vertex Cover, and Clique
This chapter assumes you know what a decision problem is, how a many-one reduction is defined, and why proving one correct takes two directions. All of these come from the earlier chapters. You also need basic graph vocabulary: vertices, edges, and subsets of vertices. The running time of reductions gets a formal treatment in the next chapter. Here we only note that every map we build is fast.
Independent Set, Vertex Cover, and Clique are the standard first examples because their reductions are short and the proofs are easy to check completely. One of the reductions changes only a number. Another changes only the edge set. Small as they are, both show the full pattern: describe the map, prove that yes-instances go to yes-instances, then prove that no-instances go to no-instances.
The Three Problems
All three problems take an undirected simple graph G = (V, E), meaning a graph with no self-loops and no repeated edges, together with an integer.
| Problem | Instance | Question | Certificate property | Column | Column |
|---|---|---|---|---|---|
| Independent Set (IS) | G, k | Is there S ⊆ V with \ | S\ | ≥ k and no edge inside S? | No edge has both ends in S |
| Vertex Cover (VC) | G, b | Is there C ⊆ V with \ | C\ | ≤ b touching every edge? | Every edge has at least one end in C |
| Clique | G, k | Is there K ⊆ V with \ | K\ | ≥ k and every pair in K adjacent? | Every pair in K is an edge |
The problems point in different directions. IS and Clique ask for large sets, and VC asks for a small one. That difference shows up in how the reductions transform the size bound.
Independent Set and Vertex Cover
The key lemma
For any graph G = (V, E) and any S ⊆ V: S is an independent set if and only if V \ S is a vertex cover.
Proof. Take any edge uv. Both endpoints lie in S exactly when neither endpoint lies in V \ S. So "no edge has both ends in S" says the same thing as "every edge has an end in V \ S." ∎
The reduction
The map sends the IS instance (G, k) to the VC instance (G, |V| − k). The graph does not change. Only the bound does.
Correctness needs both directions.
- Yes maps to yes. Suppose G has an independent set S with |S| ≥ k. By the lemma, V \ S is a vertex cover, and |V \ S| = |V| − |S| ≤ |V| − k.
- No maps to no. Prove the contrapositive: if the output is a yes-instance, so is the input. Suppose G has a vertex cover C with |C| ≤ |V| − k. Then V \ C is independent by the lemma, and |V \ C| ≥ k.
The second direction is the one people tend to skip. To prove it, you start from an arbitrary solution of the target instance and build a solution of the source instance. Showing that the solution you had in mind survives the map is not enough.
def is_independent_set(edges, s):
return all(not (u in s and v in s) for u, v in edges)
def is_vertex_cover(edges, c):
return all(u in c or v in c for u, v in edges)
def independent_set_to_vertex_cover(vertices, edges, k):
# G has an independent set of size >= k
# iff G has a vertex cover of size <= |V| - k
return vertices, edges, len(vertices) - k
vertices = [1, 2, 3, 4]
edges = [(1, 2), (2, 3), (3, 4)]
s = {1, 3}
c = set(vertices) - s
assert is_independent_set(edges, s)
assert is_vertex_cover(edges, c)The same lemma also gives a reduction from VC to IS: send (G, b) to (G, |V| − b). Each problem therefore reduces to the other. That is unusual. Most pairs of problems you meet later reduce in only one direction, or only through a long chain.
Clique and Independent Set
The complement graph
The complement of G, written Ḡ, has the same vertices as G. A pair u ≠ v is an edge of Ḡ exactly when it is not an edge of G. A set K is a clique in G if and only if K is an independent set in Ḡ. Every pair in K is adjacent in G, which means no pair in K is adjacent in Ḡ.
The reduction
The map sends (G, k) to (Ḡ, k). Correctness:
- Yes maps to yes. A clique K of size ≥ k in G is an independent set of the same size in Ḡ.
- No maps to no. An independent set S of size ≥ k in Ḡ is a clique in G, because the complement of Ḡ is G.
from itertools import combinations
def complement_edges(vertices, edges):
present = {frozenset(e) for e in edges}
return [(u, v) for u, v in combinations(vertices, 2)
if frozenset((u, v)) not in present]
def clique_to_independent_set(vertices, edges, k):
# A k-clique in G is a k-independent set in the complement of G
return vertices, complement_edges(vertices, edges), kBuilding Ḡ means looking at all n(n − 1)/2 vertex pairs, so the map runs in O(n²) time. That is polynomial. A sparse input with few edges can still produce a dense output, though. This does not matter for NP-completeness, but it does matter for the fine-grained questions discussed at the end of the tutorial.
Testing the Reductions Mechanically
A proof is what establishes correctness. Brute-force testing on small random graphs is still a cheap way to catch an off-by-one in the bound before you write the proof. The script below decides each problem by exhaustive search and checks that every reduction preserves the answer.
import random
from itertools import combinations
def is_independent_set(edges, s):
return all(not (u in s and v in s) for u, v in edges)
def is_vertex_cover(edges, c):
return all(u in c or v in c for u, v in edges)
def is_clique(edges, s):
present = {frozenset(e) for e in edges}
return all(frozenset((u, v)) in present for u, v in combinations(s, 2))
def complement_edges(vertices, edges):
present = {frozenset(e) for e in edges}
return [(u, v) for u, v in combinations(vertices, 2)
if frozenset((u, v)) not in present]
def has_is(vertices, edges, k):
return any(is_independent_set(edges, set(s))
for r in range(max(k, 0), len(vertices) + 1)
for s in combinations(vertices, r))
def has_vc(vertices, edges, b):
return any(is_vertex_cover(edges, set(c))
for r in range(0, b + 1)
for c in combinations(vertices, r))
def has_clique(vertices, edges, k):
return any(is_clique(edges, set(s))
for r in range(max(k, 0), len(vertices) + 1)
for s in combinations(vertices, r))
def independent_set_to_vertex_cover(vertices, edges, k):
return vertices, edges, len(vertices) - k
def clique_to_independent_set(vertices, edges, k):
return vertices, complement_edges(vertices, edges), k
rng = random.Random(0)
for _ in range(500):
n = rng.randint(0, 7)
vertices = list(range(n))
edges = [(u, v) for u, v in combinations(vertices, 2) if rng.random() < 0.5]
k = rng.randint(0, n + 1)
assert has_is(vertices, edges, k) == has_vc(
*independent_set_to_vertex_cover(vertices, edges, k))
assert has_clique(vertices, edges, k) == has_is(
*clique_to_independent_set(vertices, edges, k))
print("all reductions agree on 500 random instances")The test deliberately allows k = n + 1. In that case the VC bound becomes −1, and no set has negative size, so both sides correctly answer no.
Edge Cases and Common Errors
- Wrong direction of the bound. Writing the VC bound as k, or as |V| − k with ≥ in place of ≤, breaks the reduction. Check the boundary case directly. The empty graph on n vertices has an independent set of size n and a vertex cover of size 0, so the bound n − n = 0 is right.
- Decision versus optimization. The lemma also gives α(G) + τ(G) = |V|. Here α(G) is the size of a maximum independent set, and τ(G) is the size of a minimum vertex cover. That identity is a statement about optimal values, not a reduction between decision problems. For approximation the distinction matters a lot: a 2-approximation for VC gives no constant-factor guarantee for IS. That point comes back in the final chapter.
- Self-loops and multi-edges. With a self-loop at v, no independent set can contain v, and every vertex cover must contain v. The lemma still holds. Complementing such a graph is not well defined, so fix "simple graph" in the problem definition before you build Ḡ.
- Proving only one direction. Showing that the source solution maps to a target solution proves only that yes maps to yes. You also have to turn an arbitrary target solution back into a source solution.
Exercise
Give a direct reduction from Clique to Vertex Cover and state the output instance. Then verify on G = the path 1–2–3 with k = 2.
Show answer
Map (G, k) to (Ḡ, |V| − k). This is the composition of the two reductions in this chapter. A k-clique K in G is independent in Ḡ, so V \ K is a vertex cover of Ḡ of size |V| − k, and the reverse argument is the same. For the path, Ḡ has the single edge 1–3, and the bound is 3 − 2 = 1. The cover {1} works, so the answer is yes, which matches the clique {1, 2} in G.
Exercise
A classmate proposes reducing Independent Set to Vertex Cover by mapping (G, k) to (G, k). Find a small counterexample.
Show answer
Take G as a single edge 1–2 with k = 1. The set {1} is independent, so the IS answer is yes. The vertex cover {1} has size 1 ≤ 1, so the VC answer is also yes, and this instance does not separate the two maps. Now take the empty graph on 3 vertices with k = 3. IS says yes, because {1, 2, 3} is independent. VC with bound 3 also says yes. Try the triangle with k = 1 instead. IS says yes, since any single vertex is independent. A cover of size ≤ 1 misses one of the three edges, so VC says no. The proposed map sends a yes-instance to a no-instance and is wrong.
Exercise
Explain why the map (G, k) ↦ (Ḡ, k) is also a valid reduction from Independent Set to Clique, and what the complement's size means for a graph with n vertices and m edges.
Show answer
The complement of Ḡ is G, so S is independent in G exactly when S is a clique in Ḡ, and the same two-direction proof applies. The output has n(n−1)/2 − m edges. Building it takes O(n²) time even when m is small, which is polynomial but may be much larger than the input size n + m.