Lecture 22
P, NP, and computational hardness II
CSE 421 Autumn 2026
1
Previously…
2
When does a problem not have an efficient algorithm?
Let’s back up. Are there problems that don’t have any algorithms?
Yes! One example is the halting problem.
3
Theorem [Turing, 1936]: There is no algorithm for solving the halting problem.
We say that the halting problem is undecidable.
When does a problem not have an efficient algorithm?
Let’s restrict to problems that are decidable, i.e. there is some algorithm that always outputs the correct answer. Is it necessary that those algorithms are efficient?
4
Theorem (“time hierarchy”): There exist decision problems that can be solved in exponential time but cannot be solved in polynomial time.
Are there (decision) problems that can be solved in exponential time, but not in polynomial time?
These are “artificial” problems. The theorem doesn’t say anything about “natural”problems that we care about, e.g. Knapsack, Traveling Salesman, 3-SAT, ..
Decision problems
Definition: A decision problem is any problem which has a boolean (“yes” or “no”) answer.
5
Examples:
The classes and
Definition: is the class of decision problems that can be solved in polynomial time, �i.e. in time = for some constant .
Definition: is the class of decision problems that can be solved in exponential time, i.e. in time = for some constant .
6
Roughly speaking, we take to be the class of (decision) problems that can be solved “efficiently”.
on every input
Example of problems in
Some of the problems in :
7
The class
8
Informally: the class of problems for which “yes” inputs have an efficiently verifiable “proof”, and “no” inputs don’t.
Input: an integer (expressed in binary), and another integer .
Output: “yes” if has a prime factor , and “no” otherwise.
The problem of “factoring” is an example.
If is a “yes” instance, then, given a prime factor, one can efficiently verify that it divides (even though such a factor may be hard to find).
Conversely, if is a “no” instance, then there is no number one can give you that will (wrongly) convince you that is a “yes” instance.
The class
Definition: An algorithm is a verifier for the problem if, for every input , the answer is “yes” iff there exists a proof of length such that .
Definition: is the class of decision problems that have a polynomial-time verifier.
9
Informally: the class of problems for which “yes” inputs have an efficiently verifiable “proof”.
Remark: stands for non-deterministic polynomial time.
More formally:
*and for a “no” input, there’s no proof that (wrongly) convinces you it is “yes”.
Examples of problems in
Factoring
10
Input: an integer (expressed in binary), and another integer .
Output: “yes” if has a prime factor , and “no” otherwise.
Today
11
Examples of problems in
Knapsack
12
Input: .
Output: “yes” if there is a valid Knapsack of weight and value, and “no” otherwise.
Examples of problems in
k-coloring
13
Input: A graph .
Output: “yes” if there is a valid -coloring, and “no” otherwise.
Examples of problems in
3SAT
14
Input: A 3-CNF formula .
Output: “yes” if there exists a such that . “No” otherwise.
e.g.
A 3-CNF is a function defined as an AND of ORs, where each OR acts on at most 3 variables (i.e. bits of the input) or their negations
Examples of problems in
Min Cut
15
Input: .
Output: “Yes” if there is an s-t cut of size, “no” otherwise.
Can you think of a different verifier (and proof) for this problem?
Examples of problems in
Min Cut
16
Input: .
Output: “Yes” if there is an s-t cut of size, “no” otherwise.
Any problem in is also in : �the verifier can ignore the proof, and solve the problem by itself.
and
17
Theorem:
Theorem:
by the previous slide
Proof:
and
18
Theorem:
Theorem:
by the previous slide
Proof: If a problem is in , then one can always do a brute force search for a proof that is accepted by the verifier. Since the proof is required to be of length , this search can be done in time .
We don’t know if inclusions are strict..
The million dollar question: Is ?
19
-completeness
Definition: A problem is -complete if (a) it is in and (b) it is the “hardest” problem in .
20
What does it mean for problem to be harder than (or at least as hard as) problem ?
Informally: it means that a subroutine to solve can be used to efficiently solve
-completeness
21
What does it mean for problem to be harder than (or, at least as hard as) problem ?
Informally: it means that a subroutine to solve can be used to efficiently solve .
Definition: We say that reduces to , denoted , if there exists an algorithm that maps instances of to instances of such that:
This is formalized by the notion of a reduction.
Note: If , then we can solve any instance of as follows:
This is also known as a “Karp reduction”
In other words, up to the polynomial-time overhead of (which we consider “efficient”), we can solve in the same time it takes to solve .
-completeness
Definition: A problem is -complete if (a) it is in and (b) it is the “hardest” problem in .
22
We can now formalize the definition of completeness.
-completeness
Definition: A problem is -complete if �(a) �(b) For every problem , it holds that
23
We can now formalize the definition of completeness.
Condition (b) on its own is known as “-hardness”.
We’ve seen reductions before…
24
Example of a reduction
Subset Sum Decision-Knapsack
25
Proving a reduction is correct
Recall: a reduction between two decision problems and is a poly-time algorithm such that:
26
Crucially, you have to show both implications!
Example of a reduction
Subset Sum Decision-Knapsack
27
Proof of correctness of the reduction:
Consequences of -completeness
Theorem: Let be a -complete problem. Then is solvable in poly-time iff .
Proof:
28
Definition: A problem is -complete if �(a) �(b) For every problem , it holds that
Fundamental question: Do there exist “natural” -complete problems?
A partial list of -complete problems
29
The “first” -complete problem
Satisfiability
Theorem: Satisfiability is -complete.
30
Satisfiability is “trivially” in : for a “yes” instance , take the proof to be
such that and . The verifier simply checks that this is the case.
Input: , the description of a polynomial-time algorithm and integer in unary.
Output: Whether there exists a such that and .
Proof:
By definition of satisfiability, for a “no” instance, such a doesn’t exist.
The “first” -complete problem
Satisfiability
Theorem: Satisfiability is -complete.
31
Input: , the description of a polynomial-time algorithm and integer in unary.
Output: Whether there exists a such that and .
Proof:
-hardness: let be any other problem in . Our goal is to show .
Since , there is poly-time verifier satisfying the properties in the definition of . Let denote the length of a proof for an instance of size . Define the reduction algorithm so that:
where is shorthand for .
If is a “yes” instance, there exists of length s.t. .
If is a “no” instance, then for all of length ,
This means precisely that is a “yes” instance of satisfiability.
This means precisely that is a “no” instance of satisfiability.
Proving more problems are -complete
Recipe for showing that a problem is -complete
Correctness of recipe:
32
Alternatively, you can skip Step 2, and instead show that Step 3 holds for any problem .
As we did for the “first” -complete problem