חישוביות וסיבוכיות Computability and Complexity Lecture 8
description
Transcript of חישוביות וסיבוכיות Computability and Complexity Lecture 8
Outline
Last week:• Non-deterministic TM• Poly-time verifiability• The classes NP and coNP
Today:• Poly-time reducibility• NP completeness• Existence of NP-complete problems
P, NP and coNP
• P = class of languages where membership can be decided in polynomial time.
• NP = class of languages where membership can be verified in polynomial time.
• coNP = class of languages whose complement is in NP.
Poly-time Verifiability
Definition: A verifier for a language A is an algorithm V, where
A = {w | string c s.t. V accepts <w,c> }
• V’s running time is measured in terms of |w|• A is polynomially verifiable if it has a poly-time
V
Two Definitions of NP
Definition 1: NP is the class of languages that have a polynomial time verifier.
Definition 2: NP is the class of languages that are decidable by a non-deterministic poly-time TM.
Theorem: Definition 1 is equivalent to Definition 2.
Example: A problem in NP
A path in a directed graph G that goes through each node of G exactly once.
HAMPATH={<G,s,t>|G is a directed graph with a Hamiltonian path from s to t}
c
a
d
b
s
te
Example: A Problem in NP II
• A clique in an undirected graph is a subgraph for which every two nodes are connected.
CLIQUE={<G,k>|G is undirected graph with a k-clique}
4-clique
2-clique
NP-Completeness
Cook-Levin (early 70’s): Certain problems in NP are at least as hard as any problem in NP.
Such problems are called NP-complete.
Many important problems are NP-complete (e.g. HAMPATH, CLIQUE, SAT, SUBSETSUM).
Most problems in NP: either in P or NP-complete (however some are not known to be neither).
Theoretical Importance
To answer the P vs. NP problem: • Focus on an NP complete problem:• To show P ≠ NP, prove it requires more than poly
time.• To show P = NP, find a poly-time algorithm for it.
P
NP NP=PNPC
P
NPC
Practical Importance
I can’t You’re firedSolve it in poly- time
I.
II.Solve it in poly- time
No one knows to do it. It is NP-hard!
First Example: SAT
Boolean variables: {0,1}Boolean operations: {, , }
0 0 = 0 0 0 = 0 0 = 1
0 1 = 0 1 0 = 1 1 = 0
1 0 = 0 0 1 = 1
1 1 = 1 1 1 = 1
Boolean formula: = (x y) (x z)
The satisfiability (SAT) problem:Given a Boolean expression on n variables, can we
assign values such that the expression is TRUE?
The Cook-Levin Theorem
SAT={<>| is a satisfiable Boolean formula}
Claim: SAT ∈ NP
Cook-Levin theorem: SAT ∈ P if and only if P = NP
Polynomial-Time Reducibility
Definition: A language A is polynomial time mapping reducible to a language B, A p B, if there exists a polynomial-time computable function f: where for every w,
A f() B
f(
f
f
Theorem: If A P B and BP, then AP.
A polynomial algorithm to decide A: • Given w, Compute f(w) in polynomial time• Decide whether f(w) B in polynomial time
A B
f(
f
A f() B
3SAT
SAT={<>| is a satisfiable Boolean formula}
A Boolean formula is in conjunctive normal form (CNF) if it is an AND of clauses, each of which is an OR of literals• Example: (x1 x2) (x1 x3 x4) (x5)
3CNF: each clause has exactly 3 distinct literals• Example: (x1 x2 x3) (x1 x2 x3) (x1 x3 x4)
3SAT={<>| is a satisfiable 3CNF formula}
3SAT PCLIQUE
Theorem: 3SAT is poly-time reducible to CLIQUE.
Proof: Given a 3CNF formula F, build a graph G and specify a number k such that a clique of size k exists in G iff the formula F is satisfiable.
3SAT PCLIQUE
The reduction:• Let F = C1 C2 … Ck be a 3-CNF formula with k clauses,
each of which has 3 distinct literals.
• For each clause, Ci, put three vertices in the graph, one for each literal.
• Put an edge between two vertices if they are in different triples and their literals are consistent, meaning not each other’s negation.
In other words: There are edges between all nodes of G except for nodes in the same triplet and nodes with contradictory labels.
Construction by Examplez)yx(z)yx(z)y(xF
-x y z
-zz
y
x
-y
-x
G
clauseliteral
An edge means ‘these two literals do not contradict each other’.
Construction by Examplez)yx(z)yx(z)y(xF
-x y z
-zz
y
x
-y
-x
1z0,y1,x
G
Any clique of size k must include exactly one literal from each clause.
General Construction
k 3
iji=1 j=1
F = a ij 1 1 n na {x ,¬x ,…,x ,¬x }where
G =(V,E) where
ijV ={a :1 i k,1 j 3}
k is the number of clauses
literals
E = {(aij, ai’,j’): ii’ and aij ai’j’}
The Reduction Argument
We need to show:1. F satisfiable implies G has a clique of size k.
Given a satisfying assignment for F, for each clause pick a literal that is satisfied. Those literals in the graph G form a k-clique.
2. G has a clique of size k implies F is satisfiable.Given a k-clique in G, assign TRUE to each literal in the
clique. This yields a satisfying assignment to F (why?).
Example: Clique to Assignment)()()( zyxzyxzyxF
-x y z
-zz
y
x
-y
-x
G
y=0, z=1, x can take either values
NP-Completeness
Definition: A Language B is NP-complete if it satisfies two conditions:
1. B is in NP, and2. Every A NP is poly-time reducible to B.
Definition: A Language B is NP-hard if it satisfies the following condition:
2. Every A NP is poly-time reducible to B.
Two Theorems on NP-Completeness
Theorem 1: If B is NP-complete and BP then P=NP.
Theorem 2: If B is NP-complete and B P C for some C NP, then C is NP-complete.
Do NP-Complete Languages Exist?
Yes: BOUNDED HALTING (BH)
BH = {<M,x> | M is a TM and ∃c so that M(x,c) accepts in less than poly(|x|) steps}
Claim: BH is NP-complete.Proof: First, note that BH NP (why?).
Let A NP. We will show that A P BH.
A P BH
Since A NP, then it is verifiable in polynomial time. That is, there exists a poly-time TM V for which
w A iff ∃c s.t. V(w,c)= ACCEPT
Given w, the reduction f(w) generates the pair <V,w> as an instance for BH.
Need to show that <V,w> BH if and only if w A.
Correctness of Reduction
<V,w> BH
⇕ ∃c s.t. V(w,c) = ACCEPT
⇕ w A
Conclusion: There exists an NP-complete language.
Cook-Levin Theorem
Shows a “natural” NP-complete language.
Cook-Levin Theorem: SAT is NP-Complete.
Proof: We have to show:1. SAT NP2. For every A NP, A P SAT
The proof will be given next lecture.
Let’s See if we Understand…
Cook-Levin Theorem: SAT is NP-Complete.
Previous version: SAT ∈ P if and only if P = NP
We saw before: 3SAT PCLIQUE
You will see in tirgul: SAT P 3SAT
Question: What can we say about CLIQUE?
Showing that other languages are NP-complete
To show that B is NP-complete it is sufficient to show that:1. B is in NP, and2. Every A NP, APB
or2’. CPB, where C NP-complete.
Summary So Far
• P = problems that can be solved in poly-time• NP = problems for which a solution can be
verified in poly-time• Unknown whether P = NP (most conjecture
not)
• SAT is in NP:• Probably cannot be solved in polynomial time.• Easy to verify solution in polynomial time.
NP-Complete Problems are the “Hardest” Problems in NP
• If any one NP-Complete problem can be solved in polynomial time…
• …then every NP-Complete problem can be solved in polynomial time…
• …and in fact every problem in NP can be solved in polynomial time (which would prove that P = NP)
• Solve SAT in O(n100) time, you’ve proved that P = NP. Retire rich & famous.
Why Prove NP-completeness?
• Though nobody has proven that P ≠ NP, if you prove a problem is NP-Complete, most people accept that it is probably intractable.
• Therefore it can be important to prove that a problem is NP-Complete• Don’t try to come up with efficient algorithm.• Instead:
• Try to solve a subproblem • Work on approximation algorithms.
Using Reductions
Given one NP-Complete problem, can prove that many interesting problems are NP-Complete.
For example:• Graph problems (Clique, Vertex Cover, coloring) • Hamiltonian path/cycle• Knapsack problem• Traveling salesman• Job scheduling • Many, many, many more…
A vertex cover for a graph G is a set of vertices incident to every edge in G
VERTEX-COVER={<G,k>| G is an undirected graph that has a k-node vertex cover}
Theorem: vertex cover is NP-Complete
Example: The Vertex Cover Problem
Proof: The following V is a polynomial verifier for VERTEX-COVER.
V=“On input <<G,k>,c>:1. Test whether c is a collection of nodes in
G. 2. Test whether c has k different nodes.3. Test whether all edges in G touches the
nodes in c.4. If 1-3 pass, accept; Otherwise, reject.
VERTEX-COVER is in NP
Clique P Vertex Cover
Reduce k-clique to vertex cover:• The complement GC of a graph G contains
exactly those edges not in G
• Compute GC in polynomial time
• Claim: G has a clique of size k iff GC has a
vertex cover of size |V| - k
G Gc