1 of 32

Lecture 22

P, NP, and computational hardness II

CSE 421 Autumn 2026

1

2 of 32

Previously…

2

3 of 32

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.

    • Input: Program code.
    • Output: Whether the program terminates or runs forever.

3

Theorem [Turing, 1936]: There is no algorithm for solving the halting problem.

We say that the halting problem is undecidable.

4 of 32

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, ..

5 of 32

Decision problems

Definition: A decision problem is any problem which has a boolean (“yes” or “no”) answer.

5

Examples:

    • Input: . Output: Does a graph have a vertex cover of size?
    • Input: . Output: Is there an MST of weight?
    • Input: Boolean circuit . Output: Is there an such that ?
    • Input: . Output: Is there a valid Knapsack of weight and value?
    • Input: Sudoku problem. Output: Is there a solution to this problem?
    • Input: . Output: Is there a max flow of size?

6 of 32

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

7 of 32

Example of problems in

Some of the problems in :

    • Input: . Output: Is there a path to of length?
    • Input: . Output: Is there a max flow of size?
    • Input: matrices . Output: If .
    • Input: expressed in binary. Output: if is prime.
    • And most of the problems we saw in this class..

7

8 of 32

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.

9 of 32

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”.

10 of 32

Examples of problems in

Factoring

  • Proof: is the prime factor.
  • Verifier :
    • Check if divides . Output “yes” if it does, and “no” otherwise.

10

Input: an integer (expressed in binary), and another integer .

Output: “yes” if has a prime factor , and “no” otherwise.

11 of 32

Today

11

  • Reductions, and NP-completeness

12 of 32

Examples of problems in

Knapsack

  • Proof: such that if we should include item .
  • Verifier :
    • Check if and . Output “yes” if both conditions hold, and “no” otherwise.

12

Input: .

Output: “yes” if there is a valid Knapsack of weight and value, and “no” otherwise.

13 of 32

Examples of problems in

k-coloring

  • Proof: is the coloring itself (i.e. an assignment of a color to each vertex)
  • Verifier :
    • Check that is a valid coloring. If so, output “yes”. Otherwise “no”.

13

Input: A graph .

Output: “yes” if there is a valid -coloring, and “no” otherwise.

14 of 32

Examples of problems in

3SAT

  • Proof: Let simply be such that .
  • Verifier :
    • Check that . If so, output “yes”. Otherwise “no”.

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

15 of 32

Examples of problems in

Min Cut

  • Proof: describes the vertices in for an s-t cut
  • Verifier :
    • Check that describes a valid s-t cut.
    • Compute,
    • Check if

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?

16 of 32

Examples of problems in

Min Cut

  • Proof: empty string
  • Verifier :
    • Compute a min cut using Edmonds-Karp flow algorithm.
    • Compute,
    • Check if .

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.

17 of 32

and

  • : decision problems with a poly-time algorithm
  • : decision problems with a poly-time verifier
  • : decision problems with a exp-time algorithm

17

Theorem:

Theorem:

by the previous slide

Proof:

18 of 32

and

  • : decision problems with a poly-time algorithm
  • : decision problems with a poly-time verifier
  • : decision problems with a exp-time algorithm

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..

19 of 32

The million dollar question: Is ?

  • Morally, the questions asks: is the problem of deciding if something is true as easy as verifying a proof that it is true?
  • There is a $1 million bounty for solving the problem (in either direction!)

19

  • If yes: There is a poly-time algorithm for every problem
  • If no: No efficient/poly-time algorithm for some problems such as 3-coloring, Traveling Salesman, 3SAT, Knapsack, Vertex Cover..

20 of 32

-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

21 of 32

-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.

  • is polynomial-time
  • is a “yes” instance of if and only if is a “yes” instance of

Note: If , then we can solve any instance of as follows:

  • Compute , an instance of .
  • Run a subroutine to solve .

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 .

22 of 32

-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.

23 of 32

-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”.

24 of 32

We’ve seen reductions before…

  • We’ve seen reductions many times before in this class
  • Anytime you used an algorithm as a subroutine — you were performing a reduction
  • Examples:
    • From stable matching with arbitrary numbers of proposers and receivers to stable matching with equal number of proposers and receivers
    • From bipartite matching to Max Flow
    • From shortest path picking up items to standard shortest path
    • Etc..

24

25 of 32

Example of a reduction

Subset Sum Decision-Knapsack

  • Subset Sum: Given input , decide if there exists a subset such that .
  • Decision-Knapsack: Given input , decide if there exists a subset such that and .
  • Reduction: We want to come up with an algorithm for solving Subset Sum from an algorithm for solving Knapsack. does the following:
    • Given input , define and .
    • Then run on ().

25

26 of 32

Proving a reduction is correct

Recall: a reduction between two decision problems and is a poly-time algorithm such that:

  • “yes” “yes”: If is a “yes” instance, then is also a “yes” instance
  • “no” “no”: If is a “no” instance, then is also a “no” instance

26

Crucially, you have to show both implications!

27 of 32

Example of a reduction

Subset Sum Decision-Knapsack

  • Subset Sum,
  • If is a “yes” instance, then there exists s.t.
    • Therefore, So is a “yes” instance.
  • If is a “no” instance, then for all , .
    • Suppose for a contradiction that was a “yes” instance
    • Then, there is such that , i.e. . This is a contradiction.

27

Proof of correctness of the reduction:

28 of 32

Consequences of -completeness

Theorem: Let be a -complete problem. Then is solvable in poly-time iff .

Proof:

    • () If , then has a poly-time algorithm since
    • () Let be any problem in . Since , we can solve in poly-time using the poly-time algorithm for as a subroutine. So . So .

28

Definition: A problem is -complete if �(a) �(b) For every problem , it holds that

Fundamental question: Do there exist “natural” -complete problems?

29 of 32

A partial list of -complete problems

  • Boolean function satisfiability, 3-SAT
  • Graph problems: Vertex Cover, 3-coloring, Independent Set, Max Cut
  • Path and cycle problems: Hamiltonian path, Traveling Salesman
  • Combinatorial optimization problems: Knapsack, Subset Sum
  • 0-1 Integer Programming

29

30 of 32

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.

31 of 32

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 .

  • “Yes” maps to “Yes”:
  • “No” maps to “No”:

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.

32 of 32

Proving more problems are -complete

Recipe for showing that a problem is -complete

    • Step 1: Show that .
    • Step 2: Choose a known -complete problem .
    • Step 3: Prove that .

Correctness of recipe:

  • First, notice that is a transitive operation, i.e. if and then .
  • Now, suppose you have shown Steps 1,2,3. Consider any . We have , since is -complete. The latter combined with step 3 (and transitivity) implies. So, is -complete.

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