# Lecture 36: P, NP, and NP-completeness

• P, NP
• Reductions
• NP completeness
• SAT is NP complete

## Definitions

• A language L is polynomial-time computable if there is a polynomial f and a (deterministic) turing machine M such that M is guaranteed to halt on input x within f(∣x∣) steps and accepts x if and only if x ∈ L. P is the set of all polynomial-time computable languages.

• The definition of nondeterministic polynomial-time computable is almost the same, except that the turing machine is allowed to be nondeterministic. NP is the set of all nondeterministic polynomial-time computable languages.

• A reduction from a language L to a language Lʹ is an algorithm for transforming problem instances of L to problem instances of Lʹ. If you have an efficient reduction f from L to Lʹ and an efficient solution for Lʹ, then you can efficiently decide whether x ∈ L by checking whether f(x) ∈ Lʹ. In this case, Lʹ is harder than L.

• A language L is NP-hard if it is harder than every NP problem.

• A language is NP-complete if it is both NP-hard and NP.

## P = NP?

• Nobody knows whether P = NP.

• If P = NP, then many interesting optimization problems have polynomial time solutions

• If P = NP, then any cryptographic algorithm can be broken in polynomial time

• If any NP-complete problem is solvable in (deterministic) polynomial time, then P = NP (and vice-versa)

## Satisfiability is NP-complete

Given any language L in NP, there is a polynomial time reduction from L to the boolean satisfiability problem. That is, you can transform any string x to a formula ϕ such that x ∈ L if and only if ϕ is satisfiable.

Proof sketch: since L ∈ NP, there is a (potentially non-deterministic) turing machine M with L(M) = L, and M is guaranteed to terminate on input x in f(∣x∣) steps.

• at a high level, ϕ is a logical formula that says "M accepts x".

• the variables represent things like "the position of the head at time t is i" and "the tape contains a in position i at time t"

• ϕ contains several clauses describing the transitions of M. For example, a transition from state q to qʹ on character a that writes b and moves left would be encoded as the logical formula "if at time t, the head is in position i, and the tape at position i contains an 'a', and the state at time t is q, then at time t + 1 the state should be qʹ and the tape at position i should contain b and the head should be at position i − 1.

• ϕ needs to contain clauses for every time t. However, since we know M halts in f(∣x∣) steps, we only need to include the clauses for 0≤t < f(∣x∣), so there are only polynomially many

• ϕ also contains clauses for every position in the tape. However, the machine can move left or right at most f(∣x∣) times (since each move takes one transition), so we only need clauses describing the tape with  − f(∣x∣) < i < f(∣x∣). Again, there are only polynomially many.

• ϕ is satisfiable if and only if x ∈ L(M).

• Thus, if you had a polynomial-time SAT solver, you could solve your favorite NP problem (say 3-colorability) by first transforming the graph to be collored along with a non-deterministic coloring turing machine into a big logical formula. You could then use your SAT solver to solve the formula; if the formula is satisfiable then the graph is 3-colorable, and vice-versa.