6.045: Automata, Computability, and Complexity (GITCS) : Class 15 Nancy Lynch
6.045: Automata, Computability, and Complexity (GITCS) : Class 15 Nancy Lynch
Class 15
Nancy Lynch
Reading:
Sipser Sections 7.4-7.5
Next:
Sipser Sections 7.4-7.5
Introduction
Introduction
P = { L | there is some polynomial-time deterministic Turing
machine that decides L }
NP = { L | there is some polynomial-time nondeterministic
Turing machine that decides L }
Alternatively, L NP if and only if ( V, a polynomial-time
verifier ) ( p, a polynomial ) such that:
x L iff ( c, |c| p(|x|) ) [ V( x, c ) accepts ]
certificate
Introduction
P = { L | poly-time deterministic TM that decides L }
NP = { L | poly-time nondeterministic TM that decides L }
L NP if and only if ( V, poly-time verifier ) ( p, poly)
x L iff ( c, |c| p(|x|) ) [ V( x, c ) accepts ]
Some languages are in NP, but are not known to be in P (and
are not known to not be in P ):
SAT = { < > | is a satisfiable Boolean formula }
3COLOR = { < G > | G is an (undirected) graph whose
vertices can be colored with 3 colors with no 2 adjacent
vertices colored the same }
CLIQUE = { < G, k > | G is a graph with a k-clique }
VERTEX-COVER = { < G, k > | G is a graph having a
vertex cover of size k }
CLIQUE
CLIQUE = { < G, k > | G is a graph with a k-clique }
k-clique: k vertices with edges between all pairs in
the clique.
In NP, not known to be in P, not known to not be in
P.
b
c
f
3-cliques: { b, c, d }, { c, d, f }
Cliques are easy to verify, but may be hard to find.
CLIQUE
CLIQUE = { < G, k > | G is a graph with a k-clique }
b
a
c
f
VERTEX-COVER
VERTEX-COVER = { < G, k > | G is a graph with a
vertex cover of size k }
Vertex cover of G = (V, E): A subset C of V such
that, for every edge (u,v) in E, either u C or v C.
A set of vertices that covers all the edges.
c
f
d
3-vc: { a, b, d }
e
Vertex covers are easy to verify, may be hard to find.
VERTEX-COVER
VERTEX-COVER = { < G, k > | G is a graph with a
vertex cover of size k }
b
a
c
f
Introduction
Polynomial-Time Reducibility
Polynomial-Time Reducibility
Definition: A * is polynomial-time reducible to
B *, A p B, provided there is a polynomial-time
computable function f: * * such that:
(w) [ w A if and only if f(x) B ]
*
*
f
B
f
Polynomial-Time Reducibility
Definition: A * is polynomial-time reducible to B *,
A p B, provided there is a polynomial-time computable
function f: * * such that:
(w) [ w A if and only if f(x) B ]
Theorem: (Transitivity of p)
If A p B and B p C then A p C.
Proof:
Let f be a polynomial-time reducibility function from A to B.
Let g be a polynomial-time reducibility function from B to C.
*
A
*
C
Polynomial-Time Reducibility
Definition: A p B, provided there is a polynomial-time
computable function f: * * such that:
(w) [ w A if and only if f(w) B ]
Theorem: If A p B and B p C then A p C.
Proof:
Let f be a polynomial-time reducibility function from A to B.
Let g be a polynomial-time reducibility function from B to C.
*
A
*
C
Polynomial-Time Reducibility
Theorem: If A p B and B p C then A p C.
Proof:
Let f be a polynomial-time reducibility function from A to B.
Let g be a polynomial-time reducibility function from B to C.
*
A
*
C
Polynomial-Time Reducibility
Definition: A p B, provided there is a polynomial-time
computable function f: * * such that:
(w) [ w A if and only if f(x) B ]
Theorem: If A p B and B P then A P.
Proof:
Let f be a polynomial-time reducibility function from A to B.
Let M be a polynomial-time decider for B.
To decide whether w A:
Compute x = f(w).
Run M to decide whether x B, and accept / reject accordingly.
Polynomial time.
Polynomial-Time Reducibility
Can use p to relate the difficulty of two problems:
Theorem: If A p B and B p A then either both A and B are
in P or neither is.
Also, for problems in NP:
Theorem: If A p B and B NP then A NP.
Proof:
Let f be a polynomial-time reducibility function from A to B.
Let M be a polynomial-time nondeterministic TM that decides B.
Poly-bounded on all branches.
Accepts on at least one branch iff and only if input string is in B.
NTM M to decide membership in A:
On input w:
Compute x = f(w); |x| is bounded by a polynomial in |w|.
Run M on x and accept/reject (on each branch) if M does.
Polynomial time-bounded NTM.
Polynomial-Time Reducibility
Theorem: If A p B and B NP then A NP.
Proof:
Polynomial-Time Reducibility
Theorem: If A p B and B NP then A NP.
Corollary: If A p B and A is not in NP, then B is
not in NP.
Polynomial-Time Reducibility
A technical result (curiosity):
Theorem: If A P and B is any nontrivial language
(meaning not , not *), then A p B.
Proof:
Suppose A P.
Suppose B is a nontrivial language; pick b0 B, b1 Bc.
Define f(w) = b0 if w A, b1 if w is not in A.
f is polynomial-time computable; why?
Because A is polynomial time decidable.
Clearly w A if and only if f(w) B.
So A p B.
Example:
G = (V, E), k = 4
G = (V, E), k = n k = 3
Other n k = 3
vertices
Clique of size k = 4
k vertices
Size n k
Vertex cover
Other n k = 3
vertices
Clique of size k = 4
k vertices
Size n k
Vertex cover
Example:
G = (V, E), k = 3
G = (V, E), k = 4
3-VC
4-clique
3-VC
4-clique
We have shown:
Theorem: CLIQUE p VC.
Theorem: VC p CLIQUE.
So, they are essentially equivalent.
Either both CLIQUE and VC are in P or
neither is.
NP-Completeness
NP-Completeness
p allows us to relate problems in NP, saying
which allow us to solve which others efficiently.
Even though we dont know whether all of these
problems are in P, we can use p to impose some
structure on the class NP:
NP
A B here means A p B.
P
NP
A
B
P
NP-Completeness
Some languages in NP are hardest, in the sense that
every language in NP is p-reducible to them.
Call these NP-complete.
NP
Definition: Language B is NP-complete if both
of the following hold:
(a) B NP, and
P
(b) For any language A NP, A p B.
Sometimes, we consider languages that arent, or might
not be, in NP, but to which all NP languages are reducible.
Call these NP-hard.
Definition: Language B is NP-hard if, for any language A
NP, A p B.
NP-Completeness
Today, and next time, well:
Give examples of interesting problems that are NPcomplete, and
Develop methods for showing NP-completeness.
Theorem: B, B is NP-complete.
There is at least one NP-complete problem.
Well show this later.
NP-Completeness
Theorem: If some NP-complete language is in P,
then P = NP.
That is, if a polynomial-time algorithm exists for any NPcomplete problem, then the entire class NP collapses
into P.
Polynomial algorithms immediately arise for all
problems in NP.
Proof:
NP-Completeness
Theorem: The following are equivalent.
1. P = NP.
2. Every NP-complete language is in P.
3. Some NP-complete language is in P.
Proof:
1 2:
Assume P = NP, and suppose that B is NP-complete.
Then B NP, so B P, as needed.
2 3:
Immediate because there is at least NP-complete language.
3 1:
By the previous theorem.
Satisfiability is NP-Complete
Satisfiability is NP-Complete
SAT = { < > | is a satisfiable Boolean formula }
Definition: (Boolean formula):
Variables: x, x1, x2, , y,, z,
Can take on values 1 (true) or 0 (false).
Definition: (Satisfiability):
A Boolean formula is satisfiable iff there is an
assignment of 0s and 1s to the variables that makes the
entire formula evaluate to 1 (true).
Satisfiability is NP-Complete
SAT = { < > | is a satisfiable Boolean formula }
Boolean formula: Constructed from literals using
operations, e.g.:
= x ( ( y z ) (y z ) ) ( x z )
Example: x ( ( y z ) (y z ) ) ( x z )
Not in SAT.
x must be set to 1, so z must = 0.
Satisfiability is NP-Complete
Satisfiability is NP-Complete
Lemma 2: SAT is NP-hard.
Proof of Lemma 2:
Need to show that, for any A NP, A p SAT.
Fix A NP.
Construct a poly-time f such that
w A if and only if f(w) SAT.
A formula, write it as w.
Satisfiability is NP-Complete
Lemma 2: SAT is NP-hard.
Proof, contd:
Need w A if and only if f(w) (= w) SAT.
w A if and only if there is an accepting CH of M on w.
So we must construct formula w to be satisfiable iff there
is an accepting CH of M on w.
Recall definitions of computation history and accepting
computation history from Post Correspondence Problem:
# C0 # C1 # C2
Configurations include tape contents, state, head position.
cell
For each position (i,j), write the conjunction of two formulas:
two values.
start
The right symbols appear in the first row:
# q0 w1 w2 w3 wn -- -- -- #
start: x1,1,# x1,2,q0 x1,3,w1 x1,4,w2
x1,n+2,wn x1,n+3,--
x1,p(n)+2,-- x1,p(n)+3,#
accept
For each j, 2 j p(|w|) + 2, write the formula:
xp(|w|)+1,j,qacc
qacc appears in position j of the last row.
accept: Take disjunction (or) of all formulas for all j.
That is, qacc appears in some position of the last
row.
move
As for PCP, correct moves depend on
correct changes to local portions of
configurations.
Its enough to consider 2 3 rectangles:
If every 2 3 rectangle is good, i.e.,
consistent with the transitions, then the
entire matrix represents an accepting CH.
For each position (i,j), 1 i p(|w|), 1 j
p(|w|)+1, write a formula saying that the
rectangle with upper left at (i,j) is good.
Then conjoin all of these, O(p(|w|)2) clauses.
Good tiles for (i,j), for a, b, c in :
move
Other good tiles are defined in terms of the
nondeterministic transition function .
E.g., if (q1, a) includes tuple (q2, b, L), then
the following are good:
q1
q2
q1
q1
q2
q2
move
The good tiles give partial constraints on the computation.
When taken together, they give enough constraints so that
only a correct CH can satisfy them all.
The part (conjunct) of move for (i,j) should say that the
rectangle with upper left at (i,j) is good:
It is simply the disjunction (or), over all allowable tiles, of
the subformula:
a1
a2
a3
b1
b2
b3
move
move is the conjunction over all (i,j), of the
disjunction over all good tiles, of the given sixterm conjunctive formula.
Q: How big is the formula move?
O(p(|w|)2) clauses, one for each (i,j) pair.
Each clause is only constant length, O(1).
Because machine M yields only a constant number of
good tiles.
And there are only 6 terms for each tile.
move
w = cell start accept move , length poly in |w|.
More importantly, can produce w from w in time that is
polynomial in |w|.
w A if and only if M has an accepting CH for w if and
only if w is satisfiable.
Thus, A p SAT.
Since A was any language in NP, this proves that SAT is
NP-hard.
Since SAT is in NP and is NP-hard, SAT is NP-complete.
Next time
NP-completeness---more examples
Reading:
Sipser Sections 7.4-7.5
MIT OpenCourseWare
http://ocw.mit.edu
For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.