Sub topic 16
Common Mistakes and How to Check a Reduction
This chapter assumes you know what many-one and polynomial-time reductions are, how NP-completeness proofs work, and how the 3-SAT to Independent Set gadget reduction is built. It covers the errors that most often break a reduction and gives a routine for catching them before you rely on a proof.
The mistakes that come up most often
Reducing in the wrong direction
To show a new problem B is hard, you must reduce a known hard problem A to B, written A ≤ B. A common slip is to reduce B to SAT instead. That only shows B is no harder than SAT, which is true of every problem in NP. The question to ask is: "If I had a fast solver for my new problem, could I use it to solve the old hard one?"
Proving only one direction of correctness
A many-one reduction f needs both of these:
- If x is a yes-instance of A, then f(x) is a yes-instance of B.
- If f(x) is a yes-instance of B, then x is a yes-instance of A.
The second direction gets skipped most often. A broken reduction can map every input to a yes-instance and still satisfy direction 1. When you prove direction 2, start from an arbitrary solution of f(x), not from one you built yourself.
A reduction that secretly solves the problem
The mapping f must run in polynomial time and must not depend on knowing the answer. "If x is satisfiable, output a triangle; otherwise output an edge" is a valid many-one reduction in principle, but computing it means solving SAT. If your construction branches on the answer to the source problem, it is not polynomial time.
Blowing up the instance size
The output of f must have polynomial size. Two common ways to break this are writing one gadget for each possible assignment (exponentially many) and writing a number k in unary when the input stored it in binary. The second turns a polynomial-looking construction into an exponential one. It is also how pseudo-polynomial problems such as Subset Sum get misclassified.
Forgetting membership in NP
NP-hardness is only half of NP-completeness. You must also give a certificate and a polynomial-time verifier for B.
A checking routine
Proofs can hide gaps, so also test the reduction mechanically. On small random instances, solve both A and B by brute force and confirm that the answers match.
import random
from itertools import combinations, product
def three_sat_to_independent_set(clauses):
vertices, edges = [], []
for i, clause in enumerate(clauses):
nodes = [(i, j, lit) for j, lit in enumerate(clause)]
vertices.extend(nodes)
edges.extend(combinations(nodes, 2))
for a, b in combinations(vertices, 2):
if a[2] == -b[2]:
edges.append((a, b))
return vertices, edges, len(clauses)
def satisfiable(clauses):
names = sorted({abs(l) for c in clauses for l in c})
for bits in product([False, True], repeat=len(names)):
val = dict(zip(names, bits))
if all(any(val[abs(l)] == (l > 0) for l in c) for c in clauses):
return True
return False
def has_independent_set(vertices, edges, k):
edge_set = {frozenset(e) for e in edges}
return any(all(frozenset(p) not in edge_set for p in combinations(s, 2))
for s in combinations(vertices, k))
random.seed(0)
for _ in range(200):
n, m = random.randint(1, 4), random.randint(1, 4)
clauses = [tuple(random.choice([1, -1]) * random.randint(1, n)
for _ in range(3)) for _ in range(m)]
assert satisfiable(clauses) == has_independent_set(
*three_sat_to_independent_set(clauses)), clauses
print("all tests passed")| Symptom in testing | Likely mistake |
|---|---|
| A says no, B says yes | Direction 2 is missing a constraint, so the gadget allows cheating |
| A says yes, B says no | Gadgets are over-constrained or the parameter k is wrong |
| Output grows fast with input | Exponential construction or unary encoding |
Exercise
A student reduces 3-SAT to Independent Set but leaves out the conflict edges between x and NOT x. Which correctness direction fails, and what does a counterexample look like?
Show answer
Direction 2 fails. Without conflict edges, you can choose one vertex from each triangle even when the choices contradict each other. The unsatisfiable formula (x1) AND (NOT x1), padded to three literals per clause as (1,1,1) and (-1,-1,-1), yields an independent set of size 2, so the graph instance says yes while the formula says no.
Exercise
A reduction outputs a graph with one vertex for each subset of the input's n variables. Is it a valid Karp reduction?
Show answer
No. The graph has 2^n vertices, so the output size and the running time are exponential, even if the yes/no answers are preserved.