Sub topic 5
First Examples: Independent Set, Vertex Cover, and Clique
This chapter assumes you know basic graph vocabulary (vertices, edges, adjacency) and the definition of a many-one reduction from earlier chapters. All three problems below are decision problems on an undirected graph G = (V, E) with n vertices.
| Problem | Instance | Question |
|---|---|---|
| Independent Set | G, k | Is there a set of at least k vertices with no edge between any two of them? |
| Vertex Cover | G, m | Is there a set of at most m vertices that touches every edge? |
| Clique | G, k | Is there a set of at least k vertices where every pair is joined by an edge? |
These three problems look different, but each reduction between them is a one-line transformation, and each correctness proof is a short chain of "if and only if" steps.
Independent Set to Vertex Cover
Key fact: S is an independent set exactly when V \ S is a vertex cover.
Proof: S is independent iff no edge has both endpoints in S. That holds iff every edge has at least one endpoint outside S, which means V \ S covers every edge.
Complementing the set changes its size from k to n − k. So the reduction keeps the graph and maps the bound k to n − k:
- If G has an independent set S with |S| ≥ k, then V \ S is a cover with |V \ S| ≤ n − k.
- If G has a cover C with |C| ≤ n − k, then V \ C is independent with |V \ C| ≥ k.
Both directions hold, so yes-instances map to yes-instances and no-instances map to no-instances.
Clique to Independent Set
The complement graph Ḡ has the same vertices as G, and two vertices are adjacent in Ḡ exactly when they are not adjacent in G.
Key fact: S is a clique in G exactly when S is an independent set in Ḡ.
Proof: every pair in S is adjacent in G iff no pair in S is adjacent in Ḡ. The reduction maps (G, k) to (Ḡ, k). Building Ḡ means checking all n(n − 1)/2 vertex pairs, which is cheap.
Testing the Reductions in Code
The script below implements both reductions. It then uses brute force on a small graph to confirm that every instance and its image give the same answer for every k.
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(p) in present for p 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 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
def brute(vertices, edges, test, sizes):
return any(test(edges, set(c))
for r in sizes for c in combinations(vertices, r))
V = [1, 2, 3, 4, 5]
E = [(1, 2), (2, 3), (1, 3), (3, 4), (4, 5)]
n = len(V)
for k in range(n + 1):
is_ans = brute(V, E, is_independent_set, range(k, n + 1))
V2, E2, m = independent_set_to_vertex_cover(V, E, k)
assert is_ans == brute(V2, E2, is_vertex_cover, range(0, m + 1))
cl_ans = brute(V, E, is_clique, range(k, n + 1))
V3, E3, k3 = clique_to_independent_set(V, E, k)
assert cl_ans == brute(V3, E3, is_independent_set, range(k3, n + 1))
print("all reductions agree")Common Errors
- Mapping k to k in the Vertex Cover reduction. The bound must become n − k, and "at least" must become "at most."
- Proving only one direction. If you show only that yes maps to yes, a reduction that always outputs a yes-instance would also pass.
- Building the complement with self-loops or duplicate edges. Use unordered pairs of distinct vertices, as
combinationsdoes.
Exercise
Compose the two reductions to get a direct reduction from Clique to Vertex Cover. What instance does (G, k) map to, and why is it correct?
Show answer
(G, k) maps to (Ḡ, n − k). S is a k-clique in G iff S is an independent set in Ḡ iff V \ S is a vertex cover of Ḡ of size n − k. Each step is an "if and only if", so the composed map preserves both yes and no answers.
Exercise
A path on 4 vertices, 1-2-3-4, has a maximum independent set of size 2. What is its minimum vertex cover size, and which cover corresponds to the independent set {1, 3}?
Show answer
The minimum cover size is 4 − 2 = 2. The set {1, 3} corresponds to its complement {2, 4}, which touches edges (1,2), (2,3), and (3,4).