You are on page 1of 8

The class NP

Computational Complexity

Cooks Theorem

The class NP contains all decision problems


that are decidable by a non-deterministic
algorithm that runs in polynomial time.
Represents algorithms that run in exponential
time

Does this define a class of languages? -- Yes

Reducing one language to


another

Worked well for deciabilityLets use it


here.
Basic idea

Reducing one language to


another

Formally (for complexity)

Take an encoding of one problem


Convert it to another problem we know to
be in P or NP
Conversion must be done in polynomial
time!

Reducing one language to


another

The set of all problems whose encodings of yes


instances (a language) is recognized by a NDTM M
M recognizes the above language in Polynomial Time.

Let L1 and L2 be languages over 1 and 2


We say L1 is polynomial time reducible to
L2 (L1 p L2) if

There exists a Turing computable function


f: 1* 2* such that
x L1 iff f(x) L2
f can be computed in polynomial time.

Reducing one language to


another

Informally (for complexity)

We can take any encoded instance of one problem

Use a TM to compute a corresponding encoded instance


of another problem.

In polynomial time

If this other problem has a TM that recognizes the set of


yes encodings in polynomial time (P), we can run that
TM to solve the first problem.
If this other problem has a NDTM that recognizes the set
of yes encodings in polynomial time (NP), we can run
that TM to solve the first problem.

Instance
of P1

Conversion
TM
Runs in Ptime

Corresponding
Instance of P2

TM
recognizing
L2
Runs in Ptime

YES

NO

Reducing one language to


another

Key facts:

If L2 is P/NP-compuatble then L1 is also P/NP-compuatble


If L1 is not P/NP-compuatble then L2 is not P/NPcompuatble

If P1 and P2 are decision problems with L1 and L2


the languages of yes encodings respectively and
if L1 is reducable to L2 then

INSTANCE

L NP
For every other language L1 NP

L1 p L

All NP-complete problems are equally


difficult.

Cooks Theorem

SATISFIABILITY is NP-Complete

variables xi
logical connectors &, |, and !

PROBLEM

Is there an assignment of truth values to


each of the variables such that the
expression will evaluate to true.

Theory Hall of Fame

The hardest of the problems in class NP are


in the class of NP-complete problems:
A language L is in NP if

A Logical expression containing

If P2 is in P/NP then P1 is also in P/NP


If P1 is not in P/NP then P2 is also not in P/NP

Satisfiability (SAT)

If L1 is reducable to L2 then

The class NP-complete

Steven Cook

A local boy

Cooks Theorem

SATISFIABILITY is NP-Complete

To prove:

b. Buffalo, NY.

PhD Harvard (1966)


At Berkley from 1966-1970
At University of Toronto
since 1970

Must show SAT is in NP


Must show that any language in NP can be
polynomial time reduced to SAT.

Published this Theorem in


1971.

Cooks Theorem Part 1

Running SAT on a non-deterministic TM.

Contents of
tape before
tape head
(nonblank)

xqy

If M accepts an input w,

There are a sequence of moves


(configurations) of the TM such that:

Note that k p(n)

k contains an accepting state.


i consists of non-blanks.

Cooks Theorem Part 2


Our configurations

Tape will be filled with TM configurations


Since machine will accept in at most p(n)
steps, the TM will use at most p(n) + 1
tape positions.

Contents of
tape at and
after tape
head (nonblank)

0 is the initial ID (with w on tape)


0 a1 a ak

x1x2xnqy1y2ym

There is a Non-deterministic TM, M that will


recognize L
M takes no more than p(n) (a polynomial) on
an input of length n.

Cooks Theorem Part 2

Thankfully, neither of these restrictions


affects the acceptance power of the TM.

Gives the current configuration of a TM

How can we do this? Go back to the


Turing Machine!
Let L be a language in NP

Will never place a blank on the tape.


M has a single accepting state

Configuration of a TM

Bounded on the left will never move before


the leftmost cell

Cooks Theorem Part 2

Semi-infinite Tape

Must show that any language in NP can


be polynomial time reduced to SAT.

Can certainly do each step in polynomial time

Some simplifying assumptions about M

Step 1: Guess a set of boolean assignments to


each variable (this is the non-deterministic part
2n different choices)
Step 2: Evaluate the truth of the entire expression
using the guessed assignment (this part is
deterministic)

Cooks Theorem Part 2

Cooks Theorem Part 2

A configuration will have at most p(n) + 1


symbols

Cooks Theorem Part 2

To make things easier, well assume

Configuration

ALL configurations have p(n) + 1 symbols

i = Xi0 X i1 Xip(n)

A trailing symbol may be blank.

ALL computations take p(n) moves

If accepts before then, simply stay in accepting


state until p(n) moves have been performed.

Cooks Theorem Part 2

Cooks Theorem Part 2


Move

Introduce Boolean variables:

Cooks Theorem Part 2


Strategy

yijA which will be true if symbol Xij = A

Xij is the jth symbol from the i th configuration


A can be either a tape symbol or a state.
i and j range from 0 to p(n)

Added (p(n) + 1)2 x (number of symbols +


number of states) boolean variables

Machine must start in starting configuration

p(n) +1 configurations (initial + at most p(n) moves)


p(n) + 1 symbols per configuration

Cooks Theorem Part 2

X00 must be the start state of M


X01 X0n must be the symbols of w
X0n+1 X0p(n) must be blank
Or if w = a1a2an

S = y00q0 & y01a1 & & y0nan & y0n+1B & & y0p(n)B
At start state

W on tape

All symbols after w are blank

Use the boolean variables to describe the valid


configurations (moves) of the machine when
accepting a string w.
Rules:
Machine must start in starting configuration
Each move must follow a transition defined by the TM
When finished, the machine must be in a final state.

Describe each of these using our set of boolean


variables.

Cooks Theorem Part 2

Machine must end in a final state.

Since were assuming that all computations will


take exactly p(n) steps we need only look at p(n)
Will be accepting if there is the accepting state
as one of its symbols
If we let F be the symbol corresponding to the
final state

F = yp(n)0F | yp(n)1F | | yp(n)p(n)F

Final state is 0th symbol


of last configuration

Final state is 1st


symbol of last
configuration

Final state is last symbol of


last configuration

Cooks Theorem Part 2

Machine must follow transitions of TM.

Cooks Theorem Part 2

Expressing Ni

Must assure that configutation i+1 can indeed


follow i

Let Ni be a boolean expression that indicates if


i+1 can indeed follow I

a boolean expression that indicates if i+1


can indeed follow i
We can always determine Xi+1j

Note that we have to assure true for i = 0, , p(n) 1

By considering Xi(j-1), Xi(j), Xi(j+1)

N = N0 & N1 & & Np(n) -1

Cooks Theorem Part 2

If you consider all symbol position j of i two


things can happen for a valid move:

The state of i is at position j

(q1,b) = (q2, a, R)

Example:

The state of i is at position j


Before:
a q1 b a b b a

After

In this case Xi+1j = Xij


No change in configuration near position j.

Cooks Theorem Part 2

Expressing Ni

a boolean expression that indicates if i+1


can indeed follow i

a a q2 a b b a

The state of i is nowhere near position j.

Xij is a state
Xij-1, Xij, Xij+1 is transformed to Xi+1j-1, Xi+1j, Xi+1j+1

The state of i is nowhere near position j.

The j-1st, jth, j + 1st symbol of the ith


configuration

Cooks Theorem Part 2

Cooks Theorem Part 2

The j th symbol of the i+1st configuration

Before: a
After

q1 b

a a

Ni = &j=0,,p(n) (Aij | Bij)

a b b a

q2 a

b b a

& over all


positions j

State is at
position j & valid
move

State is
nowhere near
position j

Cooks Theorem Part 2

Expressing Ni

Cooks Theorem Part 2

Bij - The state of i is nowhere near


position j.

Xij-1 is a tape symbol


Xij is a tape symbol
Xij+1 is a tape symbol
Xi+1j = Xij

Expressing Ni

Bij - The state of i is nowhere near position j.

Let Z1, Z2, , Zr be tape symbols

Symbol at j-1 is a tape symbol


Bij = (yij-1Z1 | yij-1Z2 | | yij-1Zr) &
Symbol at j is a tape symbol
(yijZ1 | yijZ2 | | yijZr) &
Symbol at j+1 is a tape symbol
(yij+1Z1 | yij+1Z2 | | yij+1Zr) &
(yijZ1 & yij+1Z1) | (yijZ2 & yij+1Z2) | | (yijZ1 & yij+1Zr)
Xij = Xi+1j

Cooks Theorem Part 2

Expressing Ni

Aij -- The state of i is at position j and a


valid move occurs

Cooks Theorem Part 2

Must assure

Must come up with boolean expressions for


each transition indicating valid move:
Example:

Xij is a state and Xi-1j and Xi+1j are not


Can be done like in last slide
Xij-1, Xij, Xij+1 is transformed to Xi+1j-1, Xi+1j, Xi+1j+1 via
a valid TM move

Say (q, A) contains (p, C, L)


Then if q is at position j of i (Xijq is true) then

Cooks Theorem Part 2

(q1,b) = (q2, a, R)

Example:

The state of i is at position j


Before:
a q1 b a b b a

After

a a q2 a b b a
j-1

j j+1

yij-1D & yijq & yij+1A & yi+1j-1p & y i+1jD & yi+1j+1C

Cooks Theorem Part 2

Must do this for all transitions in all


possible positions j

i+1

Thats a lot of boolean expressions


However

(X ij = q1) & (Xi+1j = a) &


(Xij-1 = a) & (Xi+1j-1 = a) &

Xij-1, Xij, Xij+1 (DqA) is transformed to


Xi+1j-1, Xi+1j, Xi+1j+1 (pDC) or

Number of Aij and Bij does not depend on size


of w

Depends on size of tape alphabet and number of


states

So it is constant with respect to running time!

(Xij+1 = b) & (Xi+1j+1 = q2)

Cooks Theorem Part 2

Putting it all together

Cooks Theorem Part 2

Use the boolean variables to describe the


valid configurations (moves) of the
machine when accepting a string w.
Rules:

Final boolean expression

Machine must start in starting configuration (S)


Each move must follow a transition defined by
the TM (N)
When finished, the machine must be in a final
state. (F)

Cooks Theorem Part 2

Our reduction is complete.

Any problem in NP can be reduced to SAT

Worked well for decidabilityLets use it here.


Basic idea

Our reduction is complete.

Reducing one language to another

SAT is in NP-Complete

Reducing one language to


another

This expression will be true only iff w is accepted


by M in polynomial time

Why we need to know this

S&N&F
Conversion from TM -> boolean expression can be
done in polynomial time (w.r.t. size of input to
TM)

Take an encoding of one problem


Convert it to another problem we know to be in P or NP
Conversion must be done in polynomial time!

Reducing one language to


another

Formally (for complexity)

Let L1 and L2 be languages over 1 and 2


We say L1 is polynomial time reducible to
L2 (L1 p L2) if

There exists a Turing computable function


f: 1* 2* such that
x L1 iff f(x) L2
f can be computed in polynomial time.

Instance
of P1

Conversion
TM
Runs in Ptime

Corresponding
Instance of P2

TM
recognizing
L2
Runs in Ptime

YES

NO

Reducing one language to


another

Reducing one language to


another

Key facts:

If L1 is reducable to L2 then

If L2 is P/NP-compuatble then L1 is also P/NP-compuatble


If L1 is not P/NP-compuatble then L2 is not P/NP-compuatble

If P1 and P2 are decision problems with L1 and L2 the


languages of yes encodings respectively and if L1 is
reducable to L2 then
If P2 is in P/NP then P1 is also in P/NP
If P1 is not in P/NP then P2 is also not in P/NP

Reduction
Assume Problem M is in P
YES

Known
NP-c
problem

Reduction
machine
(runs in
Ptime)

M TM
(runs on
Ptime)
NO

Then NP problem must be in PCONTRADICTION!

Why we need Cooks theorem

We need one NP-C problem to kick things


off

Now we have one

SAT!

Well use this fact next time.


Questions.

You might also like