Sub topic 4
Which Way Does It Go? Transferring Algorithms and Hardness
This chapter assumes you know what a decision problem is and how a many-one reduction works. A many-one reduction is a computable function f where x is a yes-instance of A exactly when f(x) is a yes-instance of B. We write this as A ≤ B. The question here is what such a reduction actually tells you, and in which direction.
Algorithms Move Forward
Suppose A ≤ B through f, and you have a decider for B. To decide A on input x, compute f(x) and ask the B decider. Correctness of f guarantees the answer is right for A.
def f(n):
# Reduce A = "is n even?" to B = "does a binary string end in '0'?"
return bin(n)[2:]
def decide_B(s):
return s.endswith("0")
def decide_A(n):
return decide_B(f(n))
assert decide_A(10) is True
assert decide_A(7) is FalseThe solver for B does all the work. A is solved by translating its input first. So an algorithm for the target, B, gives an algorithm for the source, A.
Hardness Moves Backward
Take the contrapositive. If A has no algorithm (or no fast one), then B cannot have one either, because an algorithm for B would give one for A through the composition above. Hardness of the source A therefore passes to the target B.
Read A ≤ B as "A is no harder than B." The inequality points toward the harder problem, or at least toward one that is equally hard.
| You know | You reduce | You conclude |
|---|---|---|
| B is easy | A ≤ B | A is easy |
| A is hard | A ≤ B | B is hard |
| B is hard | A ≤ B | Nothing about A |
| A is easy | A ≤ B | Nothing about B |
The Common Error
The most frequent mistake is reducing in the wrong direction. To show a new problem X is hard, you need Known-Hard ≤ X. You map every instance of the known hard problem into X. If you reduce X to a known hard problem, you have only shown that X is no harder than something hard, and that is true of easy problems too. Deciding whether a list is sorted reduces to SAT, but that says nothing about how hard checking a list is.
A second error is checking only one direction of correctness. If f maps yes-instances to yes-instances but can also send a no-instance to a yes-instance, then composing f with the B solver gives wrong answers. In that case neither algorithms nor hardness transfer.
Why the Reduction's Cost Matters
The forward composition costs the time to compute f plus the time to solve B on f(x). If f takes exponential time, or makes the output exponentially larger, a fast B solver no longer gives a fast A solver. Later chapters require f to run in polynomial time, and this is the reason.
Exercise
You want to prove that a new scheduling problem S is NP-hard. A colleague gives a polynomial-time reduction from S to 3-SAT. Does this prove S is NP-hard? What reduction would?
Show answer
No. S ≤ 3-SAT shows only that S is no harder than 3-SAT, which also holds for problems solvable in polynomial time. You need a polynomial-time reduction in the other direction, 3-SAT ≤ S (or from any other known NP-hard problem to S), mapping every 3-SAT instance to an S instance with the same answer.
Exercise
Suppose A ≤ B and B ≤ A. What can you say about the two problems?
Show answer
Each is no harder than the other. If either one has an algorithm, so does the other, and if either one is hard, so is the other. They are equivalent under this kind of reduction.