Sub topic 2
Polynomial-Time Reductions
This chapter assumes you know many-one reductions, Big-O notation, and the Independent Set, Vertex Cover, and Clique problems.
Polynomial-Time Reductions
A polynomial-time (Karp) reduction from A to B is a many-one reduction f where f itself runs in time polynomial in the input size. We write A ≤p B. The time bound matters. A reduction that is allowed to take exponential time could just solve A by brute force and output a trivial yes or no instance of B. That would tell us nothing about B.
If A ≤p B and B has a polynomial-time algorithm, then A has one too: compute f(x), then run B's algorithm. The output f(x) has polynomial size, so the total time stays polynomial.
Chaining Reductions Together
Polynomial-time reductions compose. If A ≤p B and B ≤p C, then A ≤p C, because a polynomial of a polynomial is still a polynomial.
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):
return vertices, complement_edges(vertices, edges), k
def independent_set_to_vertex_cover(vertices, edges, k):
return vertices, edges, len(vertices) - k
def clique_to_vertex_cover(vertices, edges, k):
return independent_set_to_vertex_cover(
*clique_to_independent_set(vertices, edges, k))
print(clique_to_vertex_cover([1, 2, 3, 4], [(1, 2), (2, 3), (1, 3)], 3))
# ([1, 2, 3, 4], [(1, 4), (2, 4), (3, 4)], 1)NP as Problems with Checkable Certificates
A decision problem is in NP if every yes instance has a certificate, a short proof of polynomial size, that a polynomial-time verifier can check. For Independent Set, the certificate is the set itself. The verifier checks its size and checks every edge. No instances need no certificate.
NP-Hardness and NP-Completeness
B is NP-hard if every problem in NP reduces to B. B is NP-complete if it is NP-hard and also in NP. To prove a new problem B is NP-complete:
- Show B ∈ NP by giving a certificate and a verifier.
- Reduce a known NP-complete problem A to B. Do not reduce B to A.
Transitivity makes step 2 enough: every NP problem reduces to A, and A reduces to B.
SAT and the Cook-Levin Theorem
The chain needs a first NP-complete problem to start from. The Cook-Levin theorem supplies it: SAT, which asks whether a Boolean formula is satisfiable, is NP-complete. The proof encodes the computation of any polynomial-time verifier as a formula. That formula is satisfiable exactly when some certificate makes the verifier accept.
Exercise
You show Vertex Cover ≤p Problem X, and you give a polynomial-time verifier for X. What can you conclude, and why?
Show answer
X is NP-complete. The verifier puts X in NP. Vertex Cover is NP-complete, so every NP problem reduces to it, and by transitivity every NP problem reduces to X. That makes X NP-hard.