Sub topic 7
Chaining Reductions Together
This chapter assumes you know what a many-one reduction is, how to argue both directions of its correctness, and what makes a reduction polynomial-time. It also assumes you have seen the Clique, Independent Set, and Vertex Cover reductions from the earlier chapter. You should be comfortable composing functions and reading Big-O bounds.
Once you have a few reductions, you can link them. If you can reduce A to B and B to C, you get a reduction from A to C without building a new one. This property is called transitivity. Almost every NP-completeness proof depends on it. Nobody reduces a new problem directly from the Cook-Levin construction. Each new problem is reduced from one that is already known to be hard, and transitivity carries the hardness down the chain.
Composing Many-One Reductions
Suppose f is a many-one reduction from A to B, and g is a many-one reduction from B to C. That means:
- for every instance x, x ∈ A if and only if f(x) ∈ B;
- for every instance y, y ∈ B if and only if g(y) ∈ C.
Define h(x) = g(f(x)). Then, for every x:
x ∈ A ⇔ f(x) ∈ B ⇔ g(f(x)) ∈ C.
The middle step applies the second property with y = f(x). This works because g's guarantee covers every instance of B, including the ones f produces. So h is a many-one reduction from A to C. If f and g are both computable, h is computable too, because you just run one program after the other.
The proof only works if each link is a genuine "if and only if". A link that is correct in just one direction, for example "yes maps to yes" with nothing said about no-instances, breaks the chain. The composed map could send a no-instance of A to a yes-instance of C.
Why Polynomial Time Survives Composition
For Karp reductions, you also have to show that h runs in polynomial time. Say f runs in time p(n) on inputs of size n, and g runs in time q(m) on inputs of size m, where p and q are polynomials.
The key observation is that output size is bounded by running time. A machine that runs for p(n) steps can write at most p(n) symbols. So |f(x)| ≤ p(n). Running g on f(x) then takes at most q(p(n)) steps. The total time is:
T(n) ≤ p(n) + q(p(n)).
A polynomial composed with a polynomial is a polynomial. For example, p(n) = n² and q(m) = m³ give q(p(n)) = n⁶. The bound can grow quickly, but it stays polynomial.
A Worked Chain: Clique to Vertex Cover
The earlier chapter gave two separate reductions: Clique to Independent Set (complement the edges) and Independent Set to Vertex Cover (replace k with |V| − k). Composing them gives a reduction from Clique to Vertex Cover. The code below builds the composition generically and then checks it by brute force on every graph with four vertices.
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 compose(*reductions):
def composed(*instance):
for r in reductions:
instance = r(*instance)
return instance
return composed
clique_to_vertex_cover = compose(clique_to_independent_set,
independent_set_to_vertex_cover)
def has_clique(vertices, edges, k):
present = {frozenset(e) for e in edges}
return any(all(frozenset(p) in present for p in combinations(s, 2))
for s in combinations(vertices, k))
def has_vertex_cover(vertices, edges, k):
return any(all(u in s or v in s for u, v in edges)
for size in range(0, k + 1)
for s in map(set, combinations(vertices, size)))
vertices = [1, 2, 3, 4]
all_pairs = list(combinations(vertices, 2))
for mask in range(1 << len(all_pairs)):
edges = [p for i, p in enumerate(all_pairs) if mask >> i & 1]
for k in range(0, len(vertices) + 2):
expected = has_clique(vertices, edges, k)
got = has_vertex_cover(*clique_to_vertex_cover(vertices, edges, k))
assert expected == got, (edges, k)
print("composed reduction agrees on all 64 graphs")Two details are worth noticing. First, the composition did not need its own correctness proof. The two existing proofs were enough. Second, the test includes k = 5, which is larger than the number of vertices. The composed map produces a Vertex Cover bound of −1, and both sides correctly answer "no". Testing edge values like these is a cheap way to catch links that only work for typical inputs.
How Hardness Flows Along a Chain
Transitivity makes the "at least as hard as" relation consistent. If A ≤ B and B ≤ C, then A ≤ C. So C is at least as hard as everything earlier in the chain. In later chapters you will see the chain SAT ≤ 3-SAT ≤ Independent Set ≤ Vertex Cover. Once SAT is known to be NP-hard, every problem further along the chain is NP-hard as well.
Reducibility is also reflexive, because the identity map reduces any problem to itself. A relation that is reflexive and transitive is called a preorder. It is not antisymmetric. A ≤ B and B ≤ A can both hold for different problems, as they do for Clique and Independent Set. Such problems are equivalent under reductions. They fall into the same hardness class even though they are different problems.
Which Reduction Types Compose
| Reduction type | Composes? | Reason |
|---|---|---|
| Computable many-one | Yes | Running two programs one after the other is computable |
| Polynomial-time many-one (Karp) | Yes | Total time p(n) + q(p(n)) is polynomial |
| Polynomial-time Turing | Yes | At most p(n) oracle calls, each on input of size at most p(n), each simulated in q(p(n)) time |
| Log-space many-one | Yes, but harder to prove | The intermediate output may not fit in log space, so g recomputes bits of f(x) on demand |
| Many-one followed by Turing | Yes, as a Turing reduction | A many-one reduction is a special case of a Turing reduction |
The log-space row is a reminder that "obviously composes" depends on the resource you are bounding. Time composes easily because you can store the intermediate result. Space does not, because storing f(x) could take polynomial space. The fix is to never store f(x). Each time g asks for bit i of its input, you rerun f from the start and keep only that bit.
Gotcha: The Chain Must Have Fixed Length
The polynomial argument covers composing a constant number of reductions. It fails if the chain length grows with the input. Suppose one step doubles the instance size and you apply it k times. The output size is n · 2^k. With k = log₂ n, the output size is n², which is still polynomial. With k = n, it is n · 2^n, which is exponential. Each step is polynomial, but the composition is not.
This mistake appears in recursive constructions that reduce a problem to "the same problem, slightly smaller" and repeat. If you write such a construction, bound the total size directly rather than appealing to transitivity.
Exercise
Reduction f runs in time O(n^2) and reduction g runs in time O(m^4). Give a polynomial bound on the running time of g ∘ f, and explain where the output-size argument is used.
Show answer
f's output has size at most O(n^2), because it cannot write more symbols than it takes steps. g then runs on an input of size O(n^2), taking O((n^2)^4) = O(n^8) time. The total is O(n^2) + O(n^8) = O(n^8).
Exercise
A student proves that f maps yes-instances of A to yes-instances of B, and that g is a correct many-one reduction from B to C. They conclude that g ∘ f reduces A to C. What is missing, and what can go wrong?
Show answer
The student has not shown that f maps no-instances of A to no-instances of B. Without that, f might send some no-instance x of A to a yes-instance of B. Then g sends f(x) to a yes-instance of C, and the composed map gives the wrong answer for x. Each link needs both directions.
Exercise
A step T maps an instance of size n to an instance of size 3n in linear time. Is applying T a total of log₂ n times a polynomial-time reduction? What about applying it √n times?
Show answer
After k applications the size is n · 3^k. With k = log₂ n, 3^k = n^(log₂ 3) ≈ n^1.585, so the size is about n^2.585, and the total time is polynomial. With k = √n, 3^√n grows faster than every polynomial, so the composition is not polynomial-time.