# COMS W3261 Computer Science Theory Lecture 17: November 19, 2012 The Classes P and NP

## Outline

• Review
• Polynomial-time reductions and NP-complete problems
• Boolean expressions
• The satisfiability problem
• Normal forms for boolean expressions
• The problems CSAT and kSAT
• SAT is NP-complete: the Cook-Levin theorem

## 1. Review

• P is the set of languages L such that L = L(M) for some deterministic Turing machine (DTM) M of time complexity T(n) where T(n) is a polynomial.
• NP is the set of languages L such that L = L(M) for some nondeterministic Turing machine (NTM) M where on any input of length n, there are no sequences of more than T(n) moves of M where T(n) is a polynomial.
• The question of whether P = NP is one of the most important open problems in computer science and mathematics.
• Another way to characterize P and NP is that P is the class of problems that can be solved in deterministic polynomial time and NP is the class of problems whose solutions can be verified in deterministic polynomial time. More formally, L is in NP iff there exists a DTM M (the verifier) that takes as input pairs of strings (w, c), and polynomials p and q, such that
• For all inputs (w,c), M runs in p(|w|) time,
• For all w in L, there exists a string c (the "certificate") of length q(|c|) such that M accepts (w,c), and
• For all w not in L and all strings c of length q(|c|), M does not accept (w,c).
• A problem is said to be intractable if it cannot be solved in polynomial time.

## 2. Polynomial-Time Reductions and NP-Complete Problems

• A polynomial-time reduction is an algorithm that maps any instance I of problem A into an instance J of problem B in a number of steps that is a polynomial function of the length of I such that I is in A iff J is in B.
• A language L is NP-complete if
1. L is in NP and
2. For every language L' in NP there is a polynomial-time reduction of L' to L.
• A language satisfying condition (2) is said to be NP-hard.
• If A is NP-complete, B is in NP, and there is a polynomial-time reduction of A to B, then B is NP-complete.
• If any one NP-complete problem is in P, then P = NP.

## 3. Boolean Expressions

• Boolean expressions are generated by the following CFG:
• ``````
E → E ∨ T | T
T → T ∧ F | F
F → ( E ) | ¬ F | var
``````
`var` represents a variable whose value can be either 1 (for true) or 0 (for false).
The operator ∧ stands for logical AND, ∨ for logical OR, and ¬ for logical NOT.
Note that the grammar gives the operator ¬ the highest precedence, then ∧, then ∨.

## 4. The Satisfiability Problem

• A truth assignment for a boolean expression assigns either the value true (1) or the value false (0) to each of the variables in the expression.
• The value E(T) of an expression E given a truth assignment T is the result of evaluating E with each variable x in E replaced by T(x).
• A truth assignment T satisfies E if E(T) = 1.
• An expression E is satisfiable if there exists a truth assignment T that satisfies E.
• The satisfiability problem (SAT) is to determine whether a given boolean expression is satisfiable.
• The value of E = x ∧ ¬(y ∨ z) given the truth assignment T(x) = 1, T(y) = 0, T(z) = 0 is 1. [1 ∧ ¬(0 ∨ 0) = 1]. Thus, E is satisfiable.
• The expression E = x ∧ (¬x ∨ y) ∧ ¬y is not satisfiable because none of the four truth assignments to the variables x and y causes E to have the value 1.
• SAT is NP-complete.

## 5. Normal Forms for Boolean Expressions

• In boolean expressions
• Logical AND, as in x ∧ y, is often called conjunction and is sometimes written as a product, as in xy.
• Logical OR, as in x ∨ y, is often called disjunction and is sometimes written as a sum, as in x + y.
• Logical NOT, as in ¬x, is often called negation and is sometimes written with an overbar, as in x̅.
• A literal is a variable or a negated variable;
• e.g., x and ¬x are both literals.
• A clause is the logical OR (disjunction) of one or more literals;
• e.g., x ∨ ¬y is a clause.
• A boolean expression is in conjunctive normal form (CNF) if it is the logical AND (conjunction) of clauses;
• e.g., (x ∨ ¬y) ∧ (¬x ∨ z) is in CNF.
• A boolean expression is in k-CNF if it is the logical AND of clauses each one of which is the logical OR of exactly k distinct literals;
• e.g., (w ∨ ¬x ∨ y) ∧ (x ∨ ¬y ∨ z) is in 3-CNF.
• Two boolean expressions are equivalent if they have the same result on any truth assignment to their variables.

## 6. The Problems CSAT and kSAT

• CSAT
• Given a boolean expression E in CNF, is E satisfiable?
• We can view CNF as the language { E | E is the representation of a satisfiable CNF boolean expression }.
• CSAT is NP-complete.
• kSAT
• Given a boolean expression E in k-CNF, is E satisfiable?
• 1SAT and 2SAT are in P; kSAT is NP-complete for k ≥ 3.

## 7. SAT is NP-complete: the Cook-Levin theorem

• SAT is in NP
• Given a boolean expression E of length n, a multitape nondeterministic Turing machine can guess a truth assignment T for E in O(n) time.
• The NTM can then evaluate E using the truth assignment T in O(n2) time.
• If E(T) = 1, then the NTM accepts E.
• The NTM can be simulated by a single-tape deterministic TM in O(n4) time.
• If L is in NP, then there is a polynomial-time reduction of L to SAT.
• If a NTM M accepts an input w of length n in p(n) time, then M has a sequence of moves such that
1. α0 is the initial ID of M with input w.
2. α0 |– α1 |– … |– αk where k ≤ p(n).
3. αk is an ID with an accepting state.
4. Each αi consists only of nonblanks unless αi ends in a state and a blank, and extends from the initial head position to the right.
• From M and w we can construct a boolean expression EM,w that is satisfiable iff M accepts w within p(n) moves. See HMU, pp. 440-446 for details.

## 8. Practice Problems

1. Is f(n) = nlog2 n (a) exponential, (b) polynomial?
2. List all satisfying truth assignments for x ∧ (y ∧ ¬x) ∧ (z ∨ ¬y).
3. Show that if A is NP-complete and A is in P, then P = NP.
4. Show that if A is NP-complete and A is polynomially reducible to a problem B in NP, then B is NP-complete.