Reducibility and \mathcal {NP}-completeness [00UY]
- November 30, 2026
Reducibility [00WC]
- December 3, 2026
Suppose we have an algorithm to solve problem B, which we can think of as a black box that takes some inputs describing a problem instance and yields an appropriate output:
We can then think of our algorithm as a “subroutine” to turn it into a solution to another problem:
- The function f translates inputs for problem A into inputs for problem B.
- The function g translates outputs for problem B into outputs for problem A.
- Note we can even allow multiple “calls” to B.
Of course, this is only useful if this really does solve problem A. That is, we need the property that if y is a solution of problem B for input f(x), then g(y) is a solution of problem A for input x. In this case we write A \leq B (“A is reducible to B”). Note we can prove such a reduction without having an actual algorithm to solve problem B: we just show that if we had an algorithm to solve B then we could also use it to solve A.
Poly-time reducibility [00WK]
- December 3, 2026
We also typically care about how long the reduction takes.
Definition Polynomial-time reducibility [00WD]
- December 3, 2026
If A \leq B and the translation functions f and g take polynomial time to compute, and the reduction makes only a polynomial number of subroutine calls to B, then we say that A is polynomial-time reducible to B, and write A \leq _P B.
Example Bipartite matching \leq _P max flow [00WE]
- December 3, 2026
As we saw earlier in the semester, finding bipartite matchings is poly-time reducible to max flow. The "translation functions" only take an amount of time which is linear (hence polynomial) in the size of the input graph.
Example IND-SET and Reducibility and \mathcal {NP}-completeness [00WF]
- December 3, 2026
As another simple example, we saw that IND-SET \leq _P VERTEX-COVER and vice versa: given a graph G = (V,E) and natural number k as input, all the translation function f has to do is replace k by |V| - k.
Example 3-SAT \leq _P SAT [00WG]
- December 3, 2026
Clearly 3-SAT \leq _P SAT: any instance of 3-SAT is in fact a valid instance of SAT as well, so the "reduction" doesn't even have to do any work.
It turns out (but is extremely nonobvious!) that the other direction is true as well: SAT \leq _P 3-SAT (we will prove this eventually). So in some sense even though the special case of 3-SAT seems like it might be “easier” than the general case of SAT, it is not.
Why 3, you ask? Because 3 is the smallest k for which k-SAT is just as hard as SAT. It turns out that 2-SAT, where all clauses have exactly two variables, is much easier, and can even be solved in linear time. (1-SAT, of course, is trivial (though not as trivial as 0-SAT).)
Lemma Poly-time reducibility preserves poly-time solvability [00WL]
- December 3, 2026
Suppose A and B are decision problems with A \leq _P B. If B is solvable in polynomial time, then so is A.
Proof.
- December 3, 2026
Suppose we have an input x to A of size n. Suppose the translation function f (which converts x into an input suitable for B) takes time p(n) to compute, for some polynomial p. Note that this means the size of f’s output is also O(p(n)), since it takes p(n) time and it has to produce the entire output in that time.
Now suppose B can be solved in time q(m), where q is a polynomial and m is the size of its input. Then the total time to solve problem A on input x, using the reduction to B, is the time to convert the input plus the time to run B on an input of size O(p(n)), that is, p(n) + q(p(n)). Since p and q are polynomials, and polynomials are closed under addition and substitution, this is a polynomial.
Remark [00WM]
- December 3, 2026
It is not too hard to extend the above lemma and proof in a couple ways:
- If A and B are not decision problems then we must also take into account the time needed to run the output conversion.
- We can also take into account the case where B is called a polynomial number of times as a subroutine—it essentially involves multiplying by another polynomial, though to do it formally one has to be a bit more careful to state that we have not just a single input conversion function but many, which are all bounded by some polynomial runtime.
Corollary [00WN]
- December 3, 2026
Suppose A \leq _P B. If A is not solvable in polynomial time, then neither is B.
Remark [00WO]
- December 3, 2026
Intuitively, if A \leq _P B then B is “at least as hard as” A (that is, with respect to solvability in polynomial time).
Lemma Properties of \leq _P [00WP]
- December 3, 2026
\leq _P is reflexive and transitive.
Proof.
- December 3, 2026
Theorem 3-SAT \leq _P IND-SET [00WQ]
- December 3, 2026
Although the two problems seem totally unrelated, it turns out that we can reduce 3-SAT to IND-SET (in fact, as we will see, we can reduce in the other direction as well)!
Proof.
- December 3, 2026
We want to exhibit a polynomial reduction from 3-SAT to IND-SET. That is, given a black box to solve IND-SET, we want to show how we could use it to solve 3-SAT, using only a polynomial amount of additional work.
Given a set of 3-SAT clauses, we want to find a satisfying assignment, which has to make each clause true. In order to make a clause true it suffices to choose exactly one term from each clause which will be set to \mathsf {T}. (Note that “setting \overline {x_i} to True” of course means setting x_i to \mathsf {F}.) However, we have to choose consistently: we can never pick both x_i and \overline {x_i}.
We start by constructing a graph G with 3k vertices arranged in k triangles, like so:
Each triangle corresponds to a clause, and each vertex corresponds to a term; in particular, label v_{ij} by the jth term from clause C_i. So, for example, given the clauses (x_1 \lor \overline {x_3} \lor x_4), (x_2 \lor x_1 \lor x_3), (\overline {x_1} \lor x_3 \lor \overline {x_4}), we would start by constructing the graph
This graph always has independent sets of size k (but no bigger): just pick exactly one node from each triangle. However, we don’t want to allow picking just any old combination of nodes. So we add more edges: in particular, add an edge between every pair of nodes labelled by x_i and \overline {x_i} for some i. So our example graph becomes:
An independent set can’t contain both endpoints of an edge. These edges therefore encode the constraint that we have to choose variables consistently: we can never choose both x_i and \overline {x_i}.
The claim is now that this graph has an independent set of size \geq k iff the original 3-SAT instance is satisfiable—and hence we can solve the original 3-SAT instance by asking our black box for whether this graph has an independent set of size \geq k. If the graph has an independent set of size \geq k, it must in fact have size exactly k and consist of a choice of one term from each clause. Just making these terms \mathsf {T} will result in a satisfying assignment (variables which do not correspond to any chosen term can be set to anything, say, \mathsf {F}); this is well-defined because we will never have both x_i and \overline {x_i} selected (because of the extra edges we added). Conversely, if there is a satisfying assignment, just choose one vertex from each triangle whose label is \mathsf {T} under the assignment (since it is a satisfying assignment, each clause must have at least one term which is \mathsf {T}). Any two vertices connected by an edge are either in the same triangle (and we only pick one vertex from each triangle) or are labelled with inverse terms (and hence can’t both be labelled \mathsf {T}), so this is an independent set of size k.
Finally, this reduction does only a polynomial amount of work: given k clauses we construct a graph with \Theta (k) vertices and O(k^2) edges.
\mathcal {NP}-hardness [00WH]
- December 3, 2026
Definition \mathcal {NP}-hard [00WI]
- December 3, 2026
A decision problem X is \mathcal {NP}-hard if for all D \in \mathcal {NP}, D \leq _P X.
Remark Intuition for \mathcal {NP}-hardness [00WJ]
- December 3, 2026
Intuitively, a problem is \mathcal {NP}-hard if it is “at least as hard as everything in \mathcal {NP}”. It seems reasonable that there might be some extremely hard problems which fit the bill—though how on earth would we go about proving it? To show that X is \mathcal {NP}-hard, we have to somehow show that every \mathcal {NP} problem can be reduced to X, which at first glance seems impossible.
Lemma Chaining \mathcal {NP}-hardness [00WR]
- December 4, 2026
If X is \mathcal {NP}-hard and X \leq _P Y then Y is \mathcal {NP}-hard.
Proof.
- December 4, 2026
So, if we can find just one \mathcal {NP}-hard problem, we can potentially use this lemma to find others.
\mathcal {NP}-completeness [00WT]
- December 4, 2026
Definition \mathcal {NP}-complete [00WS]
- December 4, 2026
A decision problem X is \mathcal {NP}-complete if both X \in \mathcal {NP} and X is \mathcal {NP}-hard.
Remark [00WU]
- December 4, 2026
It is not at all clear that any such problems exist at all! We could just as easily imagine a situation where there are just a bunch of problems in \mathcal {NP} which are “maximally hard”—that is, no other problems in \mathcal {NP} are harder—but are still not harder than everything in \mathcal {NP}. Or we could imagine that the only problems harder than everything in \mathcal {NP} are themselves so hard that they are not in \mathcal {NP}.
Proposition \mathcal {NP}-completeness and \mathcal {P} vs \mathcal {NP} [00WV]
- December 4, 2026
If a decision problem X is \mathcal {NP}-complete, then X is solvable in polynomial time if and only if \mathcal {P} = \mathcal {NP}.
Proof.
- December 4, 2026
(\Longrightarrow ) If X is solvable in polynomial time, then by a previous lemma, any Y with Y \leq _P X is also solvable in polynomial time. But if X is \mathcal {NP}-complete then by definition it is \mathcal {NP}-hard, meaning that every problem in \mathcal {NP} is reducible to X and hence solvable in polynomial time.
(\Longleftarrow ) If X is \mathcal {NP}-complete then by definition X \in \mathcal {NP}, so if \mathcal {P} = \mathcal {NP} then X \in \mathcal {P}.
Corollary [00WW]
- December 4, 2026
If you come up with a polynomial-time algorithm to solve an \mathcal {NP}-complete problem, you win $1 million.
Remark [00WX]
- December 4, 2026
Good luck. Note that this is not just theoretical; it turns out that there are a great many \mathcal {NP}-complete problems that people actually care about on a practical level. So lots of smart people have been trying hard for a long time to develop good algorithms to solve them, but no one has ever come up with any polynomial-time algorithms for any of them.
The first \mathcal {NP}-complete problem [00WY]
- December 4, 2026
Definition Boolean circuit [00WZ]
- December 4, 2026
A boolean circuit is a directed, acyclic graph G such that:
- Each indegree-0 vertex (“input”) is labelled with either \mathsf {T}, \mathsf {F}, or a distinct variable.
- All other vertices have indegree 1 or 2, and are labelled with either \neg (if indegree 1) or \lor or \land (if indegree 2).
- Only one vertex has outdegree 0, which we call the “output”.
(Note this is not really a “circuit” as we would usually conceive it, since in particular there are no loops!)
Remark [00X2]
- December 4, 2026
Given a truth assignment for the variables labelling the inputs, we think of a Boolean circuit as resulting in a \mathsf {T} / \mathsf {F} value in the obvious way: each edge corresponds to a wire which carries a single \mathsf {T} / \mathsf {F} value to the input of the next logic gate. Boolean circuits come with a natural decision problem.
Problem CIRCUIT-SAT [00X0]
- December 4, 2026
Given a boolean circuit, is there an assignment of the input variables such that the circuit outputs \mathsf {T}?
Theorem CIRCUIT-SAT is \mathcal {NP}-complete [00X1]
- December 4, 2026
Around 1971, Stephen Cook and Leonid Levin independently proved that \mathcal {NP}-complete problems exist, although their proofs were a bit different than the one presented here.
Proof.
- December 4, 2026
First, it is easy to see that CIRCUIT-SAT \in \mathcal {NP}: a certificate is a truth assignment; to verify it in polynomial time we can just run the circuit and check that it outputs \mathsf {T}.
Now we must show CIRCUIT-SAT is \mathcal {NP}-hard. Suppose X \in \mathcal {NP}, i.e. X has a polynomial-time certifier B. We must show X \leq _P CIRCUIT-SAT.
Since B is an algorithm, it can be encoded as a boolean circuit (proof: computers exist, and any boolean function can be encoded using \land , \lor , \neg ). Well, except for one problem: our boolean circuits have no loops. But we can circumvent that by simply “unrolling” any loops, by making a whole bunch of copies of a circuit that computes a single step. If the algorithm only runs for a polynomial amount of time then we need at most a polynomial number of copies to make this work. So, intuitively, we can build a polynomial-sized boolean circuit that simulates the algorithm B. Given an input s, we fix the inputs corresponding to s, and leave as variables the inputs corresponding to t. Now we ask whether the resulting circuit is satisfiable. If it is, that means there is some t such that B(s,t) = \mathsf {T}, that is, s \in X. If it is not satisfiable, then there is no such t, so s \notin X. Hence X \leq _P CIRCUIT-SAT.
Now that we know there is one \mathcal {NP}-hard problem, finding others is a lot simpler!
Theorem [00X3]
- December 4, 2026
Corollary [00X4]
- December 4, 2026
SAT, IND-SET, and Vertex cover are all \mathcal {NP}-complete.
Proof.
- December 4, 2026
Remark [00X5]
- December 4, 2026
This is amazing. Just by looking at the definitions it wasn’t at all clear whether we would be able to find a single problem which was \mathcal {NP}-complete, and now we have found five. In fact, it turns out that we currently know of hundreds of “natural” problems which are \mathcal {NP}-complete. Richard Karp got this all started with his 1979 paper proving 21 different \mathcal {NP}-hard problems.
So, the “reason” CIRCUIT-SAT is \mathcal {NP}-hard is that we can use it to model arbitrary computation, by essentially building a little computer. But think about what this transitive chain of reductions is then showing us: we can take a circuit modelling a computer and reduce it to a 3-SAT instance which models the same computer. But we can then in turn take that 3-SAT instance modelling a computer and reduce it to a graph, such that finding an independent set of a certain size in the graph models the same computation! Computation is sneaky like that; you end up finding it in places you would not expect. Who would have guessed that finding independent sets in a graph turns out to be equivalent to doing arbitrary computation? But in some sense \mathcal {NP}-complete problems are like this, and this gives us some intuition as to why they are so hard to analyze: because you can smuggle arbitrary computation into them!
Super Mario Bros is \mathcal {NP}-hard [00X6]
- December 4, 2026
See this 2012 paper by Aloupis et al. showing that Super Mario Bros (and a bunch of other classic video games) are \mathcal {NP}-hard, in the sense that it is hard to decide whether a given level can be beaten or not. The proof is by reduction from 3-SAT.