Sub topic 7
Reductions: Comparing the Difficulty of Problems
This chapter assumes you know what decision problems are, what the class P is, and basic graph terms such as vertices, edges, and complement graphs. A reduction lets you say "problem A is no harder than problem B" without knowing how to solve either one.
The Working Model
A polynomial-time many-one reduction from problem A to problem B is a function f with two properties:
fruns in polynomial time in the size of its input.- For every instance
x,xis a yes-instance of A exactly whenf(x)is a yes-instance of B.
You write this as A ≤p B. If you have a fast solver for B, you can solve A by computing f(x) and passing it to that solver. The extra cost is polynomial, and polynomials composed with polynomials stay polynomial. So if B is in P, A is in P too.
Which Direction Transfers Hardness
The reduction shows that A is at most as hard as B. That gives two consequences that point in opposite directions:
| You know | You conclude |
|---|---|
| B is easy (in P) | A is easy |
| A is hard | B is at least as hard |
To prove a new problem is hard, reduce a known hard problem to it. Reducing your new problem to a known hard problem only shows that a hard solver could handle it, which tells you nothing about how hard your problem is.
Example: Clique to Independent Set
A clique is a set of vertices that are all adjacent to each other. An independent set is a set of vertices with no edges between them. A clique in G is an independent set in G's complement, the graph that has an edge exactly where G does not. Building the complement takes O(V²) time, so the reduction maps (G, k) to (complement of G, k).
from itertools import combinations
def complement(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_independent_set(vertices, edges, k):
es = {frozenset(e) for e in edges}
return any(all(frozenset(p) not in es for p in combinations(s, 2))
for s in combinations(vertices, k))
def clique_to_independent_set(vertices, edges, k):
return vertices, complement(vertices, edges), k
V = [1, 2, 3, 4]
E = [(1, 2), (2, 3), (1, 3), (3, 4)] # triangle 1-2-3 plus edge 3-4
print(has_independent_set(*clique_to_independent_set(V, E, 3))) # True
print(has_independent_set(*clique_to_independent_set(V, E, 4))) # FalseThe brute-force solver here is exponential. It only demonstrates that the answers match. The reduction itself is the cheap clique_to_independent_set function.
Common Errors
- Reversing the direction. People often get this backwards. To show B is hard, the arrow must go from a known hard problem into B.
- Proving only one direction of correctness. You must show both "yes maps to yes" and "no maps to no". In practice, the second is usually proved as "if f(x) is yes, then x is yes".
- A slow or bloated transformation. If
ftakes exponential time or produces an exponentially large output, the reduction transfers nothing. - Calling the solver more than once. A many-one reduction makes exactly one call and returns its answer unchanged. Reductions that make several calls are a different notion, called Turing reductions.
Exercise
Suppose you build a polynomial-time reduction from your new problem Z to SAT. Does this prove Z is hard? What does it prove?
Show answer
No. Z ≤p SAT shows that Z is no harder than SAT, so a fast SAT solver would give a fast solver for Z. To show Z is hard, you need a reduction in the other direction, from a known hard problem such as SAT to Z.
Exercise
Why must the reduction function f itself run in polynomial time?
Show answer
The goal is to conclude "if B is in P then A is in P." If computing f took exponential time, solving A through B would still take exponential time, so a fast solver for B would not give a fast solver for A.