NP-Completeness - Hampden-Sydney College
NP-Completeness - Hampden-Sydney College
NP-Completeness - Hampden-Sydney College
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
Robb T.<br />
Koether<br />
Homework<br />
Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
The SAT<br />
Problem<br />
Cook’s<br />
Theorem<br />
The<br />
Reduction of<br />
3SAT to<br />
CLIQUE<br />
Assignment<br />
<strong>NP</strong>-<strong>Completeness</strong><br />
Lecture 40<br />
Section 7.4<br />
Robb T. Koether<br />
<strong>Hampden</strong>-<strong>Sydney</strong> <strong>College</strong><br />
Wed, Dec 3, 2008
Outline<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
Robb T.<br />
Koether<br />
Homework<br />
Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
The SAT<br />
Problem<br />
Cook’s<br />
Theorem<br />
The<br />
Reduction of<br />
3SAT to<br />
CLIQUE<br />
Assignment<br />
1 Homework Review<br />
2 <strong>NP</strong>-<strong>Completeness</strong><br />
3 The SAT Problem<br />
4 Cook’s Theorem<br />
5 The Reduction of 3SAT to CLIQUE<br />
6 Assignment
Homework Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
Robb T.<br />
Koether<br />
Homework<br />
Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
The SAT<br />
Problem<br />
Cook’s<br />
Theorem<br />
The<br />
Reduction of<br />
3SAT to<br />
CLIQUE<br />
Assignment<br />
Exercise 7.12, page 295.<br />
Let<br />
MODEXP = {〈a, b, c, p〉 | a, b, c, and p are binary<br />
integers such that a b ≡ c (mod p)}.<br />
Show that MODEXP ∈ P. (Note that the most obvious<br />
algorithm doesn’t run in polynomial time. Hint: Try it first<br />
where b is a power of 2.)
Homework Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
Robb T.<br />
Koether<br />
Homework<br />
Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
The SAT<br />
Problem<br />
Cook’s<br />
Theorem<br />
The<br />
Reduction of<br />
3SAT to<br />
CLIQUE<br />
Assignment<br />
Solution<br />
The efficient algorithm to raise a number to the power n<br />
(n > 0) is to use repeated squaring.<br />
For example,<br />
a 16 =<br />
( ((a<br />
2 ) 2 ) 2 ) 2<br />
.<br />
If the exponent is not a power of 2, then there are some<br />
more details.<br />
For example,<br />
a 13 =<br />
( (a2 · a ) 2 ) 2<br />
· a.
Homework Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
Robb T.<br />
Koether<br />
Homework<br />
Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
The SAT<br />
Problem<br />
Cook’s<br />
Theorem<br />
The<br />
Reduction of<br />
3SAT to<br />
CLIQUE<br />
Assignment<br />
Solution<br />
Use this algorithm together with reduction modulo p<br />
after each operation.<br />
For example, 3 13 (mod 5):<br />
3 2 ≡ 9 ≡ 4 (mod 5).<br />
4 · 3 ≡ 12 ≡ 2 (mod 5).<br />
2 2 ≡ 4 (mod 5).<br />
4 2 ≡ 16 ≡ 1 (mod 5).<br />
1 · 3 ≡ 3 (mod 5).
Homework Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
Robb T.<br />
Koether<br />
Homework<br />
Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
The SAT<br />
Problem<br />
Cook’s<br />
Theorem<br />
The<br />
Reduction of<br />
3SAT to<br />
CLIQUE<br />
Factoring<br />
On a related note, if it were possible (is possible) to<br />
compute (n − 1)! (mod n) in polynomial time, then it<br />
would be possible (is possible) to factor n in polynomial<br />
time.<br />
How so?<br />
Assignment
<strong>NP</strong>-<strong>Completeness</strong><br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
Robb T.<br />
Koether<br />
Homework<br />
Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
The SAT<br />
Problem<br />
Cook’s<br />
Theorem<br />
The<br />
Reduction of<br />
3SAT to<br />
CLIQUE<br />
Certain problems in <strong>NP</strong> have been shown to have a<br />
special property:<br />
If they are solvable deterministically in polynomial time,<br />
then so are all problems in <strong>NP</strong>.<br />
These problems are called <strong>NP</strong>-complete.<br />
We will show that SAT is <strong>NP</strong>-complete.<br />
Assignment
The Satisfiability Problem<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
Robb T.<br />
Koether<br />
Homework<br />
Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
The SAT<br />
Problem<br />
Cook’s<br />
Theorem<br />
The<br />
Reduction of<br />
3SAT to<br />
CLIQUE<br />
The SAT Problem<br />
Given a Boolean expression in m variables x 1 , x 2 , . . . , x m<br />
consisting of n literals (occurrences of x i or ¬x i ), do there<br />
exist Boolean values for x 1 , x 2 , . . . , x m that make the<br />
expression true? (n is the size of the problem.)<br />
Assignment
The Satisfiability Problem<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
Robb T.<br />
Koether<br />
Homework<br />
Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
The SAT<br />
Problem<br />
Cook’s<br />
Theorem<br />
The<br />
Reduction of<br />
3SAT to<br />
CLIQUE<br />
For example, is the expression<br />
(x ∧ (y ∨ ¬z)) ∧ ((¬x ∨ y) ∧ z) ∨ ¬ (x ∧ ¬z)<br />
satisfiable?<br />
How can we tell?<br />
Assignment
Cook’s Theorem<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
Robb T.<br />
Koether<br />
Homework<br />
Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
The SAT<br />
Problem<br />
Cook’s<br />
Theorem<br />
The<br />
Reduction of<br />
3SAT to<br />
CLIQUE<br />
Assignment<br />
Theorem (Cook’s Theorem)<br />
SAT ∈ P if and only if P = <strong>NP</strong>.<br />
Proof idea.<br />
First show that SAT is in <strong>NP</strong>.<br />
Then show that every problem in <strong>NP</strong> is polynomial-time<br />
reducible to SAT.<br />
Details in the next lecture.
Polynomial-Time Computability<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
Robb T.<br />
Koether<br />
Homework<br />
Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
The SAT<br />
Problem<br />
Cook’s<br />
Theorem<br />
The<br />
Reduction of<br />
3SAT to<br />
CLIQUE<br />
Assignment<br />
Definition (Polynomial-time computable)<br />
A function f : Σ ∗ → Σ ∗ is polynomial-time computable if<br />
there is a polynomial-time Turing machine M that halts on<br />
all inputs w with f(w) on its tape.<br />
Definition (Polynomial-time reducible)<br />
A language A is polynomial-time reducible to a language B<br />
if there exists a polynomial-time computable function f such<br />
that<br />
w ∈ A ⇔ f(w) ∈ B.<br />
We write A ≤ P B.
<strong>NP</strong>-Complete<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
Robb T.<br />
Koether<br />
Homework<br />
Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
The SAT<br />
Problem<br />
Cook’s<br />
Theorem<br />
Definition<br />
A language B is <strong>NP</strong>-complete if B ∈ <strong>NP</strong>, and every problem<br />
A in <strong>NP</strong> is polynomial-time reducible to B.<br />
The<br />
Reduction of<br />
3SAT to<br />
CLIQUE<br />
Assignment
A Polynomial-Time Reduction<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
Robb T.<br />
Koether<br />
Homework<br />
Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
The SAT<br />
Problem<br />
Cook’s<br />
Theorem<br />
The<br />
Reduction of<br />
3SAT to<br />
CLIQUE<br />
Before proving Cook’s Theorem, we will look at an<br />
example of a polynomial-time reduction.<br />
We will reduce 3SAT to CLIQUE.<br />
That is, we will show that<br />
3SAT ≤ P SAT.<br />
Assignment
Reduction of 3SAT to CLIQUE<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
Robb T.<br />
Koether<br />
Homework<br />
Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
The SAT<br />
Problem<br />
Cook’s<br />
Theorem<br />
The<br />
Reduction of<br />
3SAT to<br />
CLIQUE<br />
Let f be a Boolean expression in conjunctive normal<br />
form with exactly 3 literals per clause.<br />
Create a graph G by the following two steps.<br />
(1) For each clause, create a group of nodes labeled with<br />
the literals in that clause.<br />
Assignment
Reduction of 3SAT to CLIQUE<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
Robb T.<br />
Koether<br />
Homework<br />
Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
The SAT<br />
Problem<br />
Cook’s<br />
Theorem<br />
The<br />
Reduction of<br />
3SAT to<br />
CLIQUE<br />
For example, let<br />
f = (x∨y ∨z)∧(¬x∨¬y ∨z)∧(¬x∨y ∨¬z)∧(x∨y ∨¬z).<br />
Then there are four groups of three nodes each.<br />
Assignment
Reduction of 3SAT to CLIQUE<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
Robb T.<br />
Koether<br />
Homework<br />
Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
The SAT<br />
Problem<br />
Cook’s<br />
Theorem<br />
The<br />
Reduction of<br />
3SAT to<br />
CLIQUE<br />
x<br />
y<br />
z<br />
¬x<br />
¬y z<br />
¬x<br />
y<br />
¬z<br />
Assignment<br />
x<br />
y<br />
¬z
Reduction of 3SAT to CLIQUE<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
Robb T.<br />
Koether<br />
Homework<br />
Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
The SAT<br />
Problem<br />
Cook’s<br />
Theorem<br />
The<br />
Reduction of<br />
3SAT to<br />
CLIQUE<br />
(2) Connect each node in one group with every node in the<br />
other groups that is logically compatible with it.<br />
That is, for every variable x, connect x with everything<br />
except ¬x in every other clause.<br />
Do this for each group.<br />
Assignment
Reduction of 3SAT to CLIQUE<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
Robb T.<br />
Koether<br />
Homework<br />
Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
The SAT<br />
Problem<br />
Cook’s<br />
Theorem<br />
The<br />
Reduction of<br />
3SAT to<br />
CLIQUE<br />
x<br />
y<br />
z<br />
¬x<br />
¬y z<br />
¬x<br />
y<br />
¬z<br />
Assignment<br />
x<br />
y<br />
¬z
Reduction of 3SAT to CLIQUE<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
Robb T.<br />
Koether<br />
Homework<br />
Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
The SAT<br />
Problem<br />
Cook’s<br />
Theorem<br />
The<br />
Reduction of<br />
3SAT to<br />
CLIQUE<br />
x<br />
y<br />
z<br />
¬x<br />
¬y z<br />
¬x<br />
y<br />
¬z<br />
Assignment<br />
x<br />
y<br />
¬z
Reduction of 3SAT to CLIQUE<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
Robb T.<br />
Koether<br />
Homework<br />
Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
The SAT<br />
Problem<br />
Cook’s<br />
Theorem<br />
The<br />
Reduction of<br />
3SAT to<br />
CLIQUE<br />
x<br />
y<br />
z<br />
¬x<br />
¬y z<br />
¬x<br />
y<br />
¬z<br />
Assignment<br />
x<br />
y<br />
¬z
Reduction of 3SAT to CLIQUE<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
Robb T.<br />
Koether<br />
Homework<br />
Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
The SAT<br />
Problem<br />
Cook’s<br />
Theorem<br />
The<br />
Reduction of<br />
3SAT to<br />
CLIQUE<br />
x<br />
y<br />
z<br />
¬x<br />
¬y z<br />
¬x<br />
y<br />
¬z<br />
Assignment<br />
x<br />
y<br />
¬z
Reduction of 3SAT to CLIQUE<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
Robb T.<br />
Koether<br />
Homework<br />
Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
The SAT<br />
Problem<br />
Cook’s<br />
Theorem<br />
The<br />
Reduction of<br />
3SAT to<br />
CLIQUE<br />
x<br />
y<br />
z<br />
¬x<br />
¬y z<br />
¬x<br />
y<br />
¬z<br />
Assignment<br />
x<br />
y<br />
¬z
Reduction of 3SAT to CLIQUE<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
Robb T.<br />
Koether<br />
Homework<br />
Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
The SAT<br />
Problem<br />
Cook’s<br />
Theorem<br />
The<br />
Reduction of<br />
3SAT to<br />
CLIQUE<br />
x<br />
y<br />
z<br />
¬x<br />
¬y z<br />
¬x<br />
y<br />
¬z<br />
Assignment<br />
x<br />
y<br />
¬z
Reduction of 3SAT to CLIQUE<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
Robb T.<br />
Koether<br />
Homework<br />
Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
The SAT<br />
Problem<br />
Cook’s<br />
Theorem<br />
The<br />
Reduction of<br />
3SAT to<br />
CLIQUE<br />
x<br />
y<br />
z<br />
¬x<br />
¬y z<br />
¬x<br />
y<br />
¬z<br />
Assignment<br />
x<br />
y<br />
¬z
Reduction of 3SAT to CLIQUE<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
Robb T.<br />
Koether<br />
Homework<br />
Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
The SAT<br />
Problem<br />
Cook’s<br />
Theorem<br />
The<br />
Reduction of<br />
3SAT to<br />
CLIQUE<br />
x<br />
y<br />
z<br />
¬x<br />
¬y z<br />
¬x<br />
y<br />
¬z<br />
Assignment<br />
x<br />
y<br />
¬z
Reduction of 3SAT to CLIQUE<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
Robb T.<br />
Koether<br />
Homework<br />
Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
The SAT<br />
Problem<br />
Cook’s<br />
Theorem<br />
The<br />
Reduction of<br />
3SAT to<br />
CLIQUE<br />
x<br />
y<br />
z<br />
¬x<br />
¬y z<br />
¬x<br />
y<br />
¬z<br />
Assignment<br />
x<br />
y<br />
¬z
Reduction of 3SAT to CLIQUE<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
Robb T.<br />
Koether<br />
Homework<br />
Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
The SAT<br />
Problem<br />
Cook’s<br />
Theorem<br />
The<br />
Reduction of<br />
3SAT to<br />
CLIQUE<br />
x<br />
y<br />
z<br />
¬x<br />
¬y z<br />
¬x<br />
y<br />
¬z<br />
Assignment<br />
x<br />
y<br />
¬z
Reduction of 3SAT to CLIQUE<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
Robb T.<br />
Koether<br />
Homework<br />
Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
The SAT<br />
Problem<br />
Cook’s<br />
Theorem<br />
The<br />
Reduction of<br />
3SAT to<br />
CLIQUE<br />
x<br />
y<br />
z<br />
¬x<br />
¬y z<br />
¬x<br />
y<br />
¬z<br />
Assignment<br />
x<br />
y<br />
¬z
Reduction of 3SAT to CLIQUE<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
Robb T.<br />
Koether<br />
Homework<br />
Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
The SAT<br />
Problem<br />
Cook’s<br />
Theorem<br />
Let k be the number of clauses in the expression.<br />
We now ask, does the graph have a clique of size k?<br />
The<br />
Reduction of<br />
3SAT to<br />
CLIQUE<br />
Assignment
Reduction of 3SAT to CLIQUE<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
Robb T.<br />
Koether<br />
Does this graph have a clique of size 4?<br />
Homework<br />
Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
¬x<br />
¬y z<br />
The SAT<br />
Problem<br />
Cook’s<br />
Theorem<br />
The<br />
Reduction of<br />
3SAT to<br />
CLIQUE<br />
Assignment<br />
x<br />
y<br />
z<br />
¬x<br />
y<br />
¬z<br />
x<br />
y<br />
¬z
Reduction of 3SAT to CLIQUE<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
Robb T.<br />
Koether<br />
Yes it does, namely {x, ¬y, ¬z}.<br />
Homework<br />
Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
¬x<br />
¬y z<br />
The SAT<br />
Problem<br />
Cook’s<br />
Theorem<br />
The<br />
Reduction of<br />
3SAT to<br />
CLIQUE<br />
Assignment<br />
x<br />
y<br />
z<br />
¬x<br />
y<br />
¬z<br />
x<br />
y<br />
¬z
Reduction of 3SAT to CLIQUE<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
Robb T.<br />
Koether<br />
Homework<br />
Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
The SAT<br />
Problem<br />
Cook’s<br />
Theorem<br />
The<br />
Reduction of<br />
3SAT to<br />
CLIQUE<br />
Assignment<br />
This clique gives us values for x, y, and z that will<br />
satisfy the expression.<br />
Namely, x is true, y is false, and z is false.<br />
This shows that “yes” to CLIQUE implies “yes” to 3SAT.<br />
It is also easy to see that “no” to CLIQUE implies “no”<br />
to 3SAT.<br />
It is also the case that this reduction can be done in<br />
polynomial time.
<strong>NP</strong>-Complete<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
Robb T.<br />
Koether<br />
Homework<br />
Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
The SAT<br />
Problem<br />
Cook’s<br />
Theorem<br />
Theorem<br />
If B is <strong>NP</strong>-complete and B ∈ P, then P = <strong>NP</strong>.<br />
The<br />
Reduction of<br />
3SAT to<br />
CLIQUE<br />
Assignment
<strong>NP</strong>-Complete<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
Robb T.<br />
Koether<br />
Homework<br />
Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
The SAT<br />
Problem<br />
Cook’s<br />
Theorem<br />
The<br />
Reduction of<br />
3SAT to<br />
CLIQUE<br />
Theorem<br />
If B is <strong>NP</strong>-complete and B ≤ P C for some C ∈ <strong>NP</strong>, then C<br />
is <strong>NP</strong>-complete.<br />
Proof.<br />
The relation ≤ P is transitive.<br />
Assignment
Assignment<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
Robb T.<br />
Koether<br />
Homework<br />
Review<br />
<strong>NP</strong>-<br />
<strong>Completeness</strong><br />
The SAT<br />
Problem<br />
Cook’s<br />
Theorem<br />
The<br />
Reduction of<br />
3SAT to<br />
CLIQUE<br />
Homework<br />
Read Section 7.4, pages 271 - 276.<br />
Exercises 9, 10, page 295.<br />
Problems 13, 18, page 295.<br />
Assignment