Sub topic 12
Worked Reduction: Independent Set to Vertex Cover
This chapter assumes you know what a polynomial-time many-one reduction is, that you have seen the definitions of NP-hard and NP-complete, and that you can read basic graph code in Python. It builds on the previous chapter's tour of classic NP-complete problems, where Independent Set appeared.
The Two Problems
Both problems take an undirected graph G = (V, E) and a number k. Let n = |V|.
| Problem | Question | A "yes" certificate |
|---|---|---|
| Independent Set | Is there a set S of at least k vertices with no edge between any two of them? | The set S |
| Vertex Cover | Is there a set C of at most k vertices that touches every edge? | The set C |
The two questions look different, but they describe the same structure from opposite sides.
The Key Fact
Claim: S is an independent set in G exactly when V \ S (every vertex not in S) is a vertex cover of G.
Proof, forward direction. Suppose S is independent and take any edge (u, v). The edge cannot have both endpoints in S. So at least one endpoint is outside S, which means it is in V \ S. Every edge is covered.
Proof, reverse direction. Suppose V \ S is a vertex cover and take any two vertices u, v in S. If (u, v) were an edge, neither endpoint would be in V \ S, so that edge would be uncovered. That contradicts the assumption, so no edge joins two vertices of S.
Sizes line up too. |S| ≥ k holds exactly when |V \ S| ≤ n − k.
The Reduction
The reduction keeps the graph as it is and changes only the number: map (G, k) to (G, n − k). The instance has a yes answer for Independent Set exactly when the new instance has a yes answer for Vertex Cover. Computing n − k takes linear time, so this is a polynomial-time many-one reduction.
The code below runs the mapping and checks the complement fact on every subset of a small graph.
from itertools import combinations
def is_vertex_cover(edges, cover):
cover = set(cover)
return all(u in cover or v in cover for u, v in edges)
def is_independent_set(edges, subset):
subset = set(subset)
return not any(u in subset and v in subset for u, v in edges)
def independent_set_to_vertex_cover(vertices, edges, k):
"""Maps an Independent Set instance (G, k) to a Vertex Cover instance (G, n - k)."""
return vertices, edges, len(vertices) - k
# Path a - b - c - d
vertices = ["a", "b", "c", "d"]
edges = [("a", "b"), ("b", "c"), ("c", "d")]
print(independent_set_to_vertex_cover(vertices, edges, 2)[2]) # 2
# Check the complement fact on every subset
for r in range(len(vertices) + 1):
for s in combinations(vertices, r):
rest = set(vertices) - set(s)
assert is_independent_set(edges, s) == is_vertex_cover(edges, rest)
print("Complement fact holds for all subsets")Which Way Hardness Flows
Independent Set is NP-complete. Because Independent Set reduces to Vertex Cover, a polynomial-time algorithm for Vertex Cover would also solve Independent Set in polynomial time. So Vertex Cover is NP-hard. Vertex Cover is also in NP, since is_vertex_cover plus a size check verifies a certificate in polynomial time. Together these make Vertex Cover NP-complete.
Exercise
A star graph has a center vertex joined to 4 leaves, so n = 5. The Independent Set instance has k = 4. What Vertex Cover instance does the reduction produce, and what certificate solves it?
Show answer
The reduction produces (G, 1), since 5 − 4 = 1. The four leaves form an independent set, and its complement is the center vertex alone. The center touches all 4 edges, so the set containing only the center is a vertex cover of size 1.
Exercise
Why is it not enough to show only that a yes instance of Independent Set maps to a yes instance of Vertex Cover?
Show answer
A many-one reduction must preserve the answer in both directions. If only yes instances were guaranteed to map to yes instances, some no instance might also map to a yes instance, and a Vertex Cover solver would then give wrong answers for Independent Set. The proof needs both directions of the complement fact.