csci 2670 introduction to theory of computing
DESCRIPTION
CSCI 2670 Introduction to Theory of Computing. December 2, 2004. Agenda. Yesterday The Class NP Today NP-completeness. Announcement. If you want me to have a review session for the final exam, please email me your exam schedule. NP-completeness. - PowerPoint PPT PresentationTRANSCRIPT
CSCI 2670Introduction to Theory of
Computing
December 2, 2004
December 2, 2004 2
Agenda
• Yesterday– The Class NP
• Today– NP-completeness
December 2, 2004 3
Announcement
• If you want me to have a review session for the final exam, please email me your exam schedule
December 2, 2004 4
NP-completeness
• A problem C is NP-complete if finding a polynomial-time solution for C would imply P=NP
Definition: A language B is NP-complete if it satisfies two conditions:
1. B is in NP, and2. Every A in NP is polynomial time
reducible to B
December 2, 2004 5
Cook-Levin theorem
• SAT = {<B>|B is a satisfiable Boolean expression}
Theorem: SAT is NP-complete– If SAT can be solved in polynomial
time then any problem in NP can be solved in polynomial time
December 2, 2004 6
Proof of Cook-Levin theorem
• First show that SAT is in NP– Easy
• The show that SAT P implies P = NP– Proof converts a non-deterministic
Turing machine M with input w into a Boolean expression φ
– M accepts string w iff φ is satisfiable– <M,w> is converted into φ in
polynomial time
December 2, 2004 7
Variables in proof of Cook-Levin Thm
• xi,j,s is true if tape position i contains symbol s at step j of computation– O(p(n)2) variables
• Hi,k is true if M’s tape head is at position i at step k of computation– O(p(n)2) variables
• Qq,k is true if M is in state q at step k of the computation– O(p(n)) variables
December 2, 2004 8
Boolean expression
• Using the variables Ti,j,k, Hi,k, and Qq,k, Cook & Levin developed a Boolean expression that is satisfiable if and only if M accepts w– Expression reflects proper behavior of
M• Qstart,0 ensures starts in start state• H0,0 ensures starts with tape head at start of
tape• Ti,j,k Ti,j’,k ensures one symbol per tape
cell• Etc…
December 2, 2004 9
Purpose of Boolean expression
• If the Boolean expression in the proof of the Cook-Levin theorem can evaluate to TRUE then– Starting at the start state with w on
the tape, M can take steps based on the transition function and end at the accept state
– I.e., M accepts w
• If the Boolean expression is unsatisfiable, then M rejects w
December 2, 2004 10
Length of Boolean expression
• O((log p(n)) p(n)2)• Since p(n) is polynomial in the
length of the input, so is the Boolean expression
• If the satisfiability of the expression can be determined in polynomial time, we can determine in polynomial time whether M accepts or rejects w– Every problem in NP would be in P if
SAT is in P
December 2, 2004 11
Another NP-complete problem
• 3SAT – The Boolean expression must be in a
specific form called 3-cnf• Conjunctive normal form
– A literal is a Boolean variable or the negation of a Boolean variable
– A clause is the disjunction (OR) of literals
– A Boolean formula is in cnf if it is the conjunction (AND) of clauses• It is 3-cnf if all the clauses have 3 literals
December 2, 2004 12
Importance of Cook-Levin theorem
• Cook & Levin proved that SAT is NP-complete– If SAT can be solved in polynomial
time, then any problem in NP can be solved in polynomial time
• The showed that any problem in NP can be polynomially reduced to the SAT problem
• The proof that 3SAT is NP-complete is similar– Generate a 3-cnf formula from a TM
December 2, 2004 13
Polynomial functions
Definition: A function f:Σ*Σ* is a polynomial time computable function if some polynomial time Turing machine M exists that halts with just f(w) on its tape, when started on any input w.
December 2, 2004 14
Polynomial time reducible
Definition: Language A is polynomial time reducible to language B, written A ≤P B, if a polynomial time computable function f:Σ*Σ* exists where for every w, wA iff f(w) B
f
f
December 2, 2004 15
Reductions & NP-completeness
Theorem: If A ≤P B and BP, then AP.
Proof: Let M be the polynomial time algorithm that decides B and let f be the polynomial reduction from A to B. Consider the TM N
N = “On input w1. Compute f(w)2. Run M on f(w) and output M’s result”
Then N decides A in polynomial time.
December 2, 2004 16
Implications of NP-completeness
Theorem: If B is NP-complete and BP, then P = NP.
Theorem: If B is NP-complete and B≤PC for some C in NP, then C is NP-complete
December 2, 2004 17
Showing a problem in NP-complete
• Two steps to proving a problem L is NP-complete– Show the problem is in NP
• Demonstrate there is a polynomial time verifier for the problem
– Show some NP-complete problem can be polynomially reduced to L
December 2, 2004 18
NP-completeness proof
• CLIQUE is NP-complete– A clique in an undirected graph is a
subgraph with every pair of nodes connected by an edge
• CLIQUE = {<G,k> | G is an undirected graph with a k-clique}
December 2, 2004 19
Example
This graph has a 4-clique
December 2, 2004 20
Proving CLIQUE is NP-complete
1. Show CLIQUE is in NP2. Show some NP-complete problem
can be polynomially reduced to CLIQUE
December 2, 2004 21
Is CLIQUE in NP?
• Yes• Given a subset V’ of V
– Verify |V’|=k• O(k) time
– Verify every pair of vertices in |V’| have an edge in E• O(k2 |E|) time
December 2, 2004 22
Reducing 3SAT to CLIQUE
• Create a polynomial time function that converts a 3-cnf Boolean formula to a graph– The graph will have a k-clique if and
only if the formula is satisfiable– Cliques in the graph correspond to
satisfying assignments of truth values to variables in the formula
– Structures in the graph mimic behavior of clauses
December 2, 2004 23
3SAT reduction to CLIQUE
• Start with any 3-cnf formula with k clauses
φ = (a1b1c1)(a2b2c2)…(a2b2c2)
• Create a graph with 3k nodes– One node for each literal in φ– A single literal may have more than
one node
• A pair of nodes xi and xj has an edge if i ≠ j and xi ≠ xj
December 2, 2004 24
Example
φ = (x y y) (x y y) (x x y)
x
y
y
x y y
x
x
y
Q: Is φ satisfiable? A: Yes: x = y = 1
December 2, 2004 25
Correctness of construction
• Need to show the formula is satisfiable iff the graph has a k-clique
• If the formula is satisfiable, there is a way to assign values to the variables such that at least one literal is true in each clause– The corresponding nodes will create a
k-clique
December 2, 2004 26
Correctness of construction
• Need to show the formula is satisfiable iff the graph has a k-clique
• By construction, any k-clique will contain one node from each clause and will not contain both x and x for any variable x– Assigning the variable corresponding
to each node the value true will result in one literal in each clause being true
December 2, 2004 27
Are we done?
• We have shown that CLIQUE is in NP• We have found a reduction from
3SAT to CLIQUE– The 3-cnf formula is satisfiable iff the
graph has a k-clique
• What’s left?– Demonstrate the reduction is
polynomial– |V| = # of literals in φ– |E| ≤ (|V|-3)(|V|-6)(|V|-9)…(3) = O(|V|2)
=O( (# of literals in φ)2 )
December 2, 2004 28
Summary
• To show a language L is NP-complete
1. Demonstrate L is in NP2. Find a language C that is known to
be NP-complete3. Create a function f from C to L4. Demonstrate that if x is in C then
f(x) is in L5. Demonstrate that if f(x) is in L then
x is in C6. Demonstrate f is computable in
polynomial time