CS310 : Automata Theory 2020
Lecture 32: The complexity class NP and NP completeness
Instructor: S. Akshay
IITB, India
Spring 2020
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 2
Recap
Turing machines and computability 1. Turing machines
(i) Definition & variants
(ii) Decidable and Turing recognizable languages (iii) Church-Turing Hypothesis
2. Undecidability
(i) A proof technique by diagonalization (ii) Via reductions
(iii) Rice’s theorem
3. Applications: showing (un)decidability of other problems (i) A string matching problem: Post’s Correspondance Problem (ii) A problem for compilers: Unambiguity of Context-free languages 4. Efficiency in computation: run-time complexity.
(i) Running time complexity
(ii) Polynomial and exponential time complexity
Recap
Turing machines and computability 1. Turing machines
(i) Definition & variants
(ii) Decidable and Turing recognizable languages (iii) Church-Turing Hypothesis
2. Undecidability
(i) A proof technique by diagonalization (ii) Via reductions
(iii) Rice’s theorem
3. Applications: showing (un)decidability of other problems (i) A string matching problem: Post’s Correspondance Problem (ii) A problem for compilers: Unambiguity of Context-free languages 4. Efficiency in computation: run-time complexity.
(i) Running time complexity
(ii) Polynomial and exponential time complexity
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 2
Recap
Turing machines and computability 1. Turing machines
(i) Definition & variants
(ii) Decidable and Turing recognizable languages (iii) Church-Turing Hypothesis
2. Undecidability
(i) A proof technique by diagonalization (ii) Via reductions
(iii) Rice’s theorem
3. Applications: showing (un)decidability of other problems (i) A string matching problem: Post’s Correspondance Problem (ii) A problem for compilers: Unambiguity of Context-free languages
4. Efficiency in computation: run-time complexity. (i) Running time complexity
(ii) Polynomial and exponential time complexity
Recap
Turing machines and computability 1. Turing machines
(i) Definition & variants
(ii) Decidable and Turing recognizable languages (iii) Church-Turing Hypothesis
2. Undecidability
(i) A proof technique by diagonalization (ii) Via reductions
(iii) Rice’s theorem
3. Applications: showing (un)decidability of other problems (i) A string matching problem: Post’s Correspondance Problem (ii) A problem for compilers: Unambiguity of Context-free languages 4. Efficiency in computation: run-time complexity.
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 3
This lecture
The complexity class NP
In this lecture we will cover I The NP complexity class I The P vs NP problem I NP completeness
I The Cook-Levin Theorem Reading Material
I Section 10.1, 10.2, 10.3 , Introduction to Automata Theory, Languages and Computation, Hopcroft, Motwani and Ullman
I Section 7.3, 7.4, Introduction to the Theory of Computation, Michael Sipser
This lecture
The complexity class NP
In this lecture we will cover I The NP complexity class I The P vs NP problem I NP completeness
I The Cook-Levin Theorem Reading Material
I Section 10.1, 10.2, 10.3, Introduction to Automata Theory, Languages and Computation, Hopcroft, Motwani and Ullman
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 4
The class NP
NTIME(t(n)) is set of all languages decidable by aO(t(n)) 1-tape non-det Turing machine
Definition
NP is the class of languages that are decidable in polynomial time on a non-deterministic single-tape Turing machine, i.e.,
NP =[
k
NTIME(nk)
Verifier
for languageAis an algorithm V s.t. w ∈A iffV accepts hw,ci for some witness or proof stringc. Examples: HAMPATH, Composities
Theorem
A language is in NP iff it has a poly-time verifier
The class NP
NTIME(t(n)) is set of all languages decidable by aO(t(n)) 1-tape non-det Turing machine
Definition
NP is the class of languages that are decidable in polynomial time on a non-deterministic single-tape Turing machine, i.e.,
NP =[
k
NTIME(nk)
Verifier
for languageAis an algorithm V s.t. w ∈A iffV accepts hw,ci for some witness or proof stringc. Examples: HAMPATH, Composities
Theorem
A language is in NP iff it has a poly-time verifier
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 4
The class NP
NTIME(t(n)) is set of all languages decidable by aO(t(n)) 1-tape non-det Turing machine
Definition
NP is the class of languages that are decidable in polynomial time on a non-deterministic single-tape Turing machine, i.e.,
NP =[
k
NTIME(nk)
Verifier
for language Ais an algorithm V s.t. w ∈A iffV accepts hw,ci for some witness or proof string c.
Examples: HAMPATH, Composities Theorem
A language is in NP iff it has a poly-time verifier
The class NP
NTIME(t(n)) is set of all languages decidable by aO(t(n)) 1-tape non-det Turing machine
Definition
NP is the class of languages that are decidable in polynomial time on a non-deterministic single-tape Turing machine, i.e.,
NP =[
k
NTIME(nk)
Verifier
for language Ais an algorithm V s.t. w ∈A iffV accepts hw,ci for some witness or proof string c. Examples: HAMPATH, Composities
Theorem
A language is in NP iff it has a poly-time verifier
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 4
The class NP
NTIME(t(n)) is set of all languages decidable by aO(t(n)) 1-tape non-det Turing machine
Definition
NP is the class of languages that are decidable in polynomial time on a non-deterministic single-tape Turing machine, i.e.,
NP =[
k
NTIME(nk)
Verifier
for language Ais an algorithm V s.t. w ∈A iffV accepts hw,ci for some witness or proof string c. Examples: HAMPATH, Composities
Theorem
A language is in NP iff it has a poly-time verifier
Non-determinism vs Poly-time verifiers
Theorem
A language is in NP iff it has a poly-time verifier
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 5
Non-determinism vs Poly-time verifiers
Theorem
A language is in NP iff it has a poly-time verifier I =⇒
Non-determinism vs Poly-time verifiers
Theorem
A language is in NP iff it has a poly-time verifier
I =⇒ SupposeN is the NTM that decidesL∈NP, we define verifier V: I On input hw,ci, where w,c are strings,
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 5
Non-determinism vs Poly-time verifiers
Theorem
A language is in NP iff it has a poly-time verifier
I =⇒ SupposeN is the NTM that decidesL∈NP, we define verifier V: I On input hw,ci, where w,c are strings,
1. SimulateN onw, withc as a description of the non-det choice.
2. If this branch ofN’s computation accepts, accept, else reject.
Non-determinism vs Poly-time verifiers
Theorem
A language is in NP iff it has a poly-time verifier
I =⇒ SupposeN is the NTM that decidesL∈NP, we define verifier V: I On input hw,ci, where w,c are strings,
1. SimulateN onw, withc as a description of the non-det choice.
2. If this branch ofN’s computation accepts, accept, else reject.
I ⇐= Given verifierV which runs in timenk, we construct NTM N as follows:
I On input w of lengthn;
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 5
Non-determinism vs Poly-time verifiers
Theorem
A language is in NP iff it has a poly-time verifier
I =⇒ SupposeN is the NTM that decidesL∈NP, we define verifier V: I On input hw,ci, where w,c are strings,
1. SimulateN onw, withc as a description of the non-det choice.
2. If this branch ofN’s computation accepts, accept, else reject.
I ⇐= Given verifierV which runs in timenk, we construct NTM N as follows:
I On input w of lengthn;
1. Guess (i.e., non-det choice) stringc of length at mostnk 2. RunV on hw,ci
3. Accept ifV accepts, else reject
Examples of problems in NP class
Exercises
I CLIQUE: Does an undir graph G contain a clique of sizek? I SUBSET-SUM: Given a set of numbers, does some set add up to
exactly S?
CLIQUE:{hG,ki |G is an undirected graph with ak-clique}. Give two proofs!
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 6
Examples of problems in NP class
Exercises
I CLIQUE: Does an undir graph G contain a clique of sizek? I SUBSET-SUM: Given a set of numbers, does some set add up to
exactly S?
CLIQUE: {hG,ki |G is an undirected graph with ak-clique}. Give two proofs!
The start of many many questions
What about complementation?
I Is CLIQUES in NP?
I We define Co-NP for problems whose complement is in NP. I Give an example of a problem in Co-NP. COMPOSITES I Is NP separated from Co-NP?
What aboutNP vs EXPTIME? I NP ⊆EXPTIME, but is it strict?
One question to rule them all: isP =NP?
Also ifP =NP, then what happens to the earlier questions?
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 7
The start of many many questions
What about complementation?
I IsCLIQUES in NP?
I We define Co-NP for problems whose complement is in NP. I Give an example of a problem in Co-NP. COMPOSITES I Is NP separated from Co-NP?
What aboutNP vs EXPTIME? I NP ⊆EXPTIME, but is it strict?
One question to rule them all: isP =NP?
Also ifP =NP, then what happens to the earlier questions?
The start of many many questions
What about complementation?
I IsCLIQUES in NP?
I We define Co-NP for problems whose complement is in NP.
I Give an example of a problem in Co-NP. COMPOSITES I Is NP separated from Co-NP?
What aboutNP vs EXPTIME? I NP ⊆EXPTIME, but is it strict?
One question to rule them all: isP =NP?
Also ifP =NP, then what happens to the earlier questions?
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 7
The start of many many questions
What about complementation?
I IsCLIQUES in NP?
I We define Co-NP for problems whose complement is in NP.
I Give an example of a problem in Co-NP.
COMPOSITES I Is NP separated from Co-NP?
What aboutNP vs EXPTIME? I NP ⊆EXPTIME, but is it strict?
One question to rule them all: isP =NP?
Also ifP =NP, then what happens to the earlier questions?
The start of many many questions
What about complementation?
I IsCLIQUES in NP?
I We define Co-NP for problems whose complement is in NP.
I Give an example of a problem in Co-NP. COMPOSITES
I Is NP separated from Co-NP?
What aboutNP vs EXPTIME? I NP ⊆EXPTIME, but is it strict?
One question to rule them all: isP =NP?
Also ifP =NP, then what happens to the earlier questions?
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 7
The start of many many questions
What about complementation?
I IsCLIQUES in NP?
I We define Co-NP for problems whose complement is in NP.
I Give an example of a problem in Co-NP. COMPOSITES I Is NP separated from Co-NP?
What aboutNP vs EXPTIME? I NP ⊆EXPTIME, but is it strict?
One question to rule them all: isP =NP?
Also ifP =NP, then what happens to the earlier questions?
The start of many many questions
What about complementation?
I IsCLIQUES in NP?
I We define Co-NP for problems whose complement is in NP.
I Give an example of a problem in Co-NP. COMPOSITES I Is NP separated from Co-NP?
What about NP vs EXPTIME?
I NP ⊆EXPTIME, but is it strict?
One question to rule them all: isP =NP?
Also ifP =NP, then what happens to the earlier questions?
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 7
The start of many many questions
What about complementation?
I IsCLIQUES in NP?
I We define Co-NP for problems whose complement is in NP.
I Give an example of a problem in Co-NP. COMPOSITES I Is NP separated from Co-NP?
What about NP vs EXPTIME? I NP ⊆EXPTIME, but is it strict?
One question to rule them all: isP =NP?
Also ifP =NP, then what happens to the earlier questions?
The start of many many questions
What about complementation?
I IsCLIQUES in NP?
I We define Co-NP for problems whose complement is in NP.
I Give an example of a problem in Co-NP. COMPOSITES I Is NP separated from Co-NP?
What about NP vs EXPTIME? I NP ⊆EXPTIME, but is it strict?
One question to rule them all: is P =NP?
Also ifP =NP, then what happens to the earlier questions?
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 7
The start of many many questions
What about complementation?
I IsCLIQUES in NP?
I We define Co-NP for problems whose complement is in NP.
I Give an example of a problem in Co-NP. COMPOSITES I Is NP separated from Co-NP?
What about NP vs EXPTIME? I NP ⊆EXPTIME, but is it strict?
One question to rule them all: is P =NP?
Also if P =NP, then what happens to the earlier questions?
The P vs NP problem
I P: class of problems solvable in polynomial time I NP: class of problems verifiable in polynomial time
= class of problems solvable in polynomial time in a non-determistic TM. I EXP: class of problems solvable in exponential time.
I Co− C: class of problems whose complement is solvable inC.
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 8
The P vs NP problem
I P: class of problems solvable in polynomial time I NP: class of problems verifiable in polynomial time
= class of problems solvable in polynomial time in a non-determistic TM.
I EXP: class of problems solvable in exponential time.
I Co− C: class of problems whose complement is solvable in C.
NP completeness
The problem of satisfiability SAT
Given a Boolean formula, i.e., an expression with Boolean variables and operations, does it have a satisfying assignment?
SAT ={hφi |φis a satisfiable Boolean formula.} Example: φ= (x∧y∧z)∨(x∧z)
Theorem
SAT ∈P iff P =NP
SAT ={hφi |φ is a satisfiable 3-cnf-formula.} where 3-cnf-formula is a formula in special form:
I conjunction of “clauses”
I each clause has literals, i.e., variables or their negations, separated by disjunction
I each clause has 3 literals
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 9
NP completeness
The problem of satisfiability SAT
Given a Boolean formula, i.e., an expression with Boolean variables and operations, does it have a satisfying assignment?
SAT ={hφi |φis a satisfiable Boolean formula.}
Example: φ= (x∧y∧z)∨(x∧z) Theorem
SAT ∈P iff P =NP
SAT ={hφi |φ is a satisfiable 3-cnf-formula.} where 3-cnf-formula is a formula in special form:
I conjunction of “clauses”
I each clause has literals, i.e., variables or their negations, separated by disjunction
I each clause has 3 literals
NP completeness
The problem of satisfiability SAT
Given a Boolean formula, i.e., an expression with Boolean variables and operations, does it have a satisfying assignment?
SAT ={hφi |φis a satisfiable Boolean formula.}
Example: φ= (x∧y∧z)∨(x∧z)
Theorem
SAT ∈P iff P =NP
SAT ={hφi |φ is a satisfiable 3-cnf-formula.} where 3-cnf-formula is a formula in special form:
I conjunction of “clauses”
I each clause has literals, i.e., variables or their negations, separated by disjunction
I each clause has 3 literals
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 9
NP completeness
The problem of satisfiability SAT
Given a Boolean formula, i.e., an expression with Boolean variables and operations, does it have a satisfying assignment?
SAT ={hφi |φis a satisfiable Boolean formula.}
Example: φ= (x∧y∧z)∨(x∧z) Theorem
SAT ∈P iff P =NP
SAT ={hφi |φ is a satisfiable 3-cnf-formula.} where 3-cnf-formula is a formula in special form:
I conjunction of “clauses”
I each clause has literals, i.e., variables or their negations, separated by disjunction
I each clause has 3 literals
NP completeness
The problem of satisfiability SAT
Given a Boolean formula, i.e., an expression with Boolean variables and operations, does it have a satisfying assignment?
SAT ={hφi |φis a satisfiable Boolean formula.}
Example: φ= (x∧y∧z)∨(x∧z) Theorem
SAT ∈P iff P =NP
SAT ={hφi |φ is a satisfiable 3-cnf-formula.}
where 3-cnf-formula is a formula in special form:
I conjunction of “clauses”
I each clause has literals, i.e., variables or their negations, separated by
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 10
Polynomial time reductions
Ptime computable functions
f : Σ∗ →Σ∗ is Ptime computable if there is a polytime TMM, which started on any input w halts with justf(w) on its tape.
Polynomial time reduction
LanguageApolynomtial time reducible to B, denoted A≤P B if there is a Ptime computable functionf s.t.
w ∈A⇔f(w)∈B Such a function is called a Ptime reduction ofA toB. Theorem
IfA≤pB andB ∈P, then A∈P
(Note: if there is a “halting TM” reduction fromAto B, then Aundecidable impliedB undecidable!)
Polynomial time reductions
Ptime computable functions
f : Σ∗ →Σ∗ is Ptime computable if there is a polytime TMM, which started on any input w halts with justf(w) on its tape.
Polynomial time reduction
Language Apolynomtial time reducible to B, denoted A≤P B if there is a Ptime computable function f s.t.
w ∈A⇔f(w)∈B Such a function is called a Ptime reduction of A toB.
Theorem
IfA≤pB andB ∈P, then A∈P
(Note: if there is a “halting TM” reduction fromAto B, then Aundecidable impliedB undecidable!)
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 10
Polynomial time reductions
Ptime computable functions
f : Σ∗ →Σ∗ is Ptime computable if there is a polytime TMM, which started on any input w halts with justf(w) on its tape.
Polynomial time reduction
Language Apolynomtial time reducible to B, denoted A≤P B if there is a Ptime computable function f s.t.
w ∈A⇔f(w)∈B Such a function is called a Ptime reduction of A toB.
Theorem
IfA≤pB andB ∈P, then A∈P
(Note: if there is a “halting TM” reduction fromAto B, then Aundecidable impliedB undecidable!)
Polynomial time reductions
Ptime computable functions
f : Σ∗ →Σ∗ is Ptime computable if there is a polytime TMM, which started on any input w halts with justf(w) on its tape.
Polynomial time reduction
Language Apolynomtial time reducible to B, denoted A≤P B if there is a Ptime computable function f s.t.
w ∈A⇔f(w)∈B Such a function is called a Ptime reduction of A toB.
Theorem
IfA≤pB andB ∈P, then A∈P
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 11
Exercise (H.W)
I Show that 3SAT is polytime reducible to CLIQUE.
I Show that 3SAT is polytime reducible to SUBSETSUM.
NP-completeness
Definition
A languageB is NP-complete if two conditions hold:
1. B is in NP,
2. every Ain NP is polynomial time reducible to B
If only condition 2 holdsB is said to be NP-hard. Exercises:
I IfB is NP-complete, and B∈P, thenP =NP. I IfB is NP-complete, and B≤P C, thenC is NP-hard. The Cook-Levin Theorem
SAT is NP-complete.
Proof: Reading exercise! Section 7.5 from Sipser’s book or Section 10.2 from Hopcroft, Motwani, Ullman’s book.
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 12
NP-completeness
Definition
A languageB is NP-complete if two conditions hold:
1. B is in NP,
2. every Ain NP is polynomial time reducible to B If only condition 2 holds B is said to be NP-hard.
Exercises:
I IfB is NP-complete, and B∈P, thenP =NP. I IfB is NP-complete, and B≤P C, thenC is NP-hard. The Cook-Levin Theorem
SAT is NP-complete.
Proof: Reading exercise! Section 7.5 from Sipser’s book or Section 10.2 from Hopcroft, Motwani, Ullman’s book.
NP-completeness
Definition
A languageB is NP-complete if two conditions hold:
1. B is in NP,
2. every Ain NP is polynomial time reducible to B If only condition 2 holds B is said to be NP-hard.
Exercises:
I IfB is NP-complete, and B∈P, thenP =NP.
I IfB is NP-complete, and B≤P C, thenC is
NP-hard.
The Cook-Levin Theorem SAT is NP-complete.
Proof: Reading exercise! Section 7.5 from Sipser’s book or Section 10.2 from Hopcroft, Motwani, Ullman’s book.
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 12
NP-completeness
Definition
A languageB is NP-complete if two conditions hold:
1. B is in NP,
2. every Ain NP is polynomial time reducible to B If only condition 2 holds B is said to be NP-hard.
Exercises:
I IfB is NP-complete, and B∈P, thenP =NP.
I IfB is NP-complete, and B≤P C, thenC is NP-hard.
The Cook-Levin Theorem SAT is NP-complete.
Proof: Reading exercise! Section 7.5 from Sipser’s book or Section 10.2 from Hopcroft, Motwani, Ullman’s book.
NP-completeness
Definition
A languageB is NP-complete if two conditions hold:
1. B is in NP,
2. every Ain NP is polynomial time reducible to B If only condition 2 holds B is said to be NP-hard.
Exercises:
I IfB is NP-complete, and B∈P, thenP =NP.
I IfB is NP-complete, and B≤P C, thenC is NP-hard.
The Cook-Levin Theorem SAT is NP-complete.
Proof: Reading exercise! Section 7.5 from Sipser’s book or Section 10.2 from Hopcroft, Motwani, Ullman’s book.
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 12
NP-completeness
Definition
A languageB is NP-complete if two conditions hold:
1. B is in NP,
2. every Ain NP is polynomial time reducible to B If only condition 2 holds B is said to be NP-hard.
Exercises:
I IfB is NP-complete, and B∈P, thenP =NP.
I IfB is NP-complete, and B≤P C, thenC is NP-hard.
The Cook-Levin Theorem SAT is NP-complete.
Proof: Reading exercise! Section 7.5 from Sipser’s book or Section 10.2 from Hopcroft, Motwani, Ullman’s book.
Cook-Levin Theorem
The Cook-Levin Theorem SAT is NP-complete.
I SAT ∈NP.
I Take any language A∈NP and show it is polytime reducible to SAT. I Reduction via computation histories!
Sketch: Step 1 - language to tableau 1. Spse N is NTM decides Ain nk time.
2. Writenk×nk tableau for each computation ofN onw, rows are config. 3. Every accepting tableau (some config is acc) is an accepting
computation branch of N onw.
4. Thus, N acc w iff there exists an accepting tableau forN onw.
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 13
Cook-Levin Theorem
The Cook-Levin Theorem SAT is NP-complete.
I SAT ∈NP.
I Take any language A∈NP and show it is polytime reducible to SAT. I Reduction via computation histories!
Sketch: Step 1 - language to tableau 1. Spse N is NTM decides Ain nk time.
2. Writenk×nk tableau for each computation ofN onw, rows are config. 3. Every accepting tableau (some config is acc) is an accepting
computation branch of N onw.
4. Thus, N acc w iff there exists an accepting tableau forN onw.
Cook-Levin Theorem
The Cook-Levin Theorem SAT is NP-complete.
I SAT ∈NP.
I Take any language A∈NP and show it is polytime reducible to SAT.
I Reduction via computation histories! Sketch: Step 1 - language to tableau
1. Spse N is NTM decides Ain nk time.
2. Writenk×nk tableau for each computation ofN onw, rows are config. 3. Every accepting tableau (some config is acc) is an accepting
computation branch of N onw.
4. Thus, N acc w iff there exists an accepting tableau forN onw.
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 13
Cook-Levin Theorem
The Cook-Levin Theorem SAT is NP-complete.
I SAT ∈NP.
I Take any language A∈NP and show it is polytime reducible to SAT.
I Reduction via computation histories!
Sketch: Step 1 - language to tableau 1. Spse N is NTM decides Ain nk time.
2. Writenk×nk tableau for each computation ofN onw, rows are config. 3. Every accepting tableau (some config is acc) is an accepting
computation branch of N onw.
4. Thus, N acc w iff there exists an accepting tableau forN onw.
Cook-Levin Theorem
The Cook-Levin Theorem SAT is NP-complete.
I SAT ∈NP.
I Take any language A∈NP and show it is polytime reducible to SAT.
I Reduction via computation histories!
Sketch: Step 1 - language to tableau 1. Spse N is NTM decides Ain nk time.
2. Writenk×nk tableau for each computation ofN onw, rows are config. 3. Every accepting tableau (some config is acc) is an accepting
computation branch of N onw.
4. Thus, N acc w iff there exists an accepting tableau forN onw.
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 13
Cook-Levin Theorem
The Cook-Levin Theorem SAT is NP-complete.
I SAT ∈NP.
I Take any language A∈NP and show it is polytime reducible to SAT.
I Reduction via computation histories!
Sketch: Step 1 - language to tableau 1. Spse N is NTM decides Ain nk time.
2. Writenk×nk tableau for each computation ofN onw, rows are config.
3. Every accepting tableau (some config is acc) is an accepting computation branch of N onw.
4. Thus, N acc w iff there exists an accepting tableau forN onw.
Cook-Levin Theorem
The Cook-Levin Theorem SAT is NP-complete.
I SAT ∈NP.
I Take any language A∈NP and show it is polytime reducible to SAT.
I Reduction via computation histories!
Sketch: Step 1 - language to tableau 1. Spse N is NTM decides Ain nk time.
2. Writenk×nk tableau for each computation ofN onw, rows are config.
3. Every accepting tableau (some config is acc) is an accepting computation branch of N onw.
4. Thus, N acc w iff there exists an accepting tableau forN onw.
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 13
Cook-Levin Theorem
The Cook-Levin Theorem SAT is NP-complete.
I SAT ∈NP.
I Take any language A∈NP and show it is polytime reducible to SAT.
I Reduction via computation histories!
Sketch: Step 1 - language to tableau 1. Spse N is NTM decides Ain nk time.
2. Writenk×nk tableau for each computation ofN onw, rows are config.
3. Every accepting tableau (some config is acc) is an accepting computation branch of N onw.
4. Thus, N acc w iff there exists an accepting tableau forN onw.
Cook-Levin Theorem (Contd.)
Sketch: Step 2 - language to tableau to SAT Given N and w, produce formulaϕ:
1. Variable xi,j,s for each 1≤i,j ≤nk,s ∈C =Q∪Γ∪ {#}. 2. Idea: cell[i,j] =s iff xi,j,s = 1.
3. Design ϕs.t., SAT assignment corresponds to acc tableau forN on w. 4. ϕ=ϕcell ∧ϕstart∧ϕmove∧ϕacc
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 14
Cook-Levin Theorem (Contd.)
Sketch: Step 2 - language to tableau to SAT Given N and w, produce formulaϕ:
1. Variable xi,j,s for each 1≤i,j ≤nk,s ∈C =Q∪Γ∪ {#}.
2. Idea: cell[i,j] =s iff xi,j,s = 1.
3. Design ϕs.t., SAT assignment corresponds to acc tableau forN on w. 4. ϕ=ϕcell ∧ϕstart∧ϕmove∧ϕacc
Cook-Levin Theorem (Contd.)
Sketch: Step 2 - language to tableau to SAT Given N and w, produce formulaϕ:
1. Variable xi,j,s for each 1≤i,j ≤nk,s ∈C =Q∪Γ∪ {#}.
2. Idea: cell[i,j] =s iff xi,j,s = 1.
3. Design ϕs.t., SAT assignment corresponds to acc tableau forN on w. 4. ϕ=ϕcell ∧ϕstart∧ϕmove∧ϕacc
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 14
Cook-Levin Theorem (Contd.)
Sketch: Step 2 - language to tableau to SAT Given N and w, produce formulaϕ:
1. Variable xi,j,s for each 1≤i,j ≤nk,s ∈C =Q∪Γ∪ {#}.
2. Idea: cell[i,j] =s iff xi,j,s = 1.
3. Design ϕs.t., SAT assignment corresponds to acc tableau forN on w.
4. ϕ=ϕcell ∧ϕstart∧ϕmove∧ϕacc
Cook-Levin Theorem (Contd.)
Sketch: Step 2 - language to tableau to SAT Given N and w, produce formulaϕ:
1. Variable xi,j,s for each 1≤i,j ≤nk,s ∈C =Q∪Γ∪ {#}.
2. Idea: cell[i,j] =s iff xi,j,s = 1.
3. Design ϕs.t., SAT assignment corresponds to acc tableau forN on w. 4. ϕ=ϕcell ∧ϕstart∧ϕmove∧ϕacc
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 15
Cook-Levin Theorem (Contd.)
Sketch: Step 3 - SAT formula
ϕ=ϕcell ∧ϕstart∧ϕmove ∧ϕacc where,
1. for each cell one variable is “on”, and only one is: ϕcell =V
1≤i,j≤nk[W
s∈Cxi,j,s∧W
s6=t∈C(xi,j,s ∨xi,j,t)] 2. start encodes that first row is starting config:
ϕstart =x1,1,#∧x1,2,q0∧. . .
3. accept says that accepting config should occur somewhere in tableau ϕacc =W
1≤i,j≤nkxi,j,qacc
4. move encodes that each row correponds to config that “legally” follows the preceding row config acc to N
ϕmove =V
1,≤i,j<nk (the (i,j)-window is legal)
Cook-Levin Theorem (Contd.)
Sketch: Step 3 - SAT formula
ϕ=ϕcell ∧ϕstart∧ϕmove ∧ϕacc where,
1. for each cell one variable is “on”, and only one is:
ϕcell =V
1≤i,j≤nk[W
s∈Cxi,j,s∧W
s6=t∈C(xi,j,s ∨xi,j,t)] 2. start encodes that first row is starting config:
ϕstart =x1,1,#∧x1,2,q0∧. . .
3. accept says that accepting config should occur somewhere in tableau ϕacc =W
1≤i,j≤nkxi,j,qacc
4. move encodes that each row correponds to config that “legally” follows the preceding row config acc to N
ϕmove =V
1,≤i,j<nk (the (i,j)-window is legal)
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 15
Cook-Levin Theorem (Contd.)
Sketch: Step 3 - SAT formula
ϕ=ϕcell ∧ϕstart∧ϕmove ∧ϕacc where,
1. for each cell one variable is “on”, and only one is:
ϕcell =V
1≤i,j≤nk[W
s∈Cxi,j,s ∧W
s6=t∈C(xi,j,s∨xi,j,t)]
2. start encodes that first row is starting config: ϕstart =x1,1,#∧x1,2,q0∧. . .
3. accept says that accepting config should occur somewhere in tableau ϕacc =W
1≤i,j≤nkxi,j,qacc
4. move encodes that each row correponds to config that “legally” follows the preceding row config acc to N
ϕmove =V
1,≤i,j<nk (the (i,j)-window is legal)
Cook-Levin Theorem (Contd.)
Sketch: Step 3 - SAT formula
ϕ=ϕcell ∧ϕstart∧ϕmove ∧ϕacc where,
1. for each cell one variable is “on”, and only one is:
ϕcell =V
1≤i,j≤nk[W
s∈Cxi,j,s ∧W
s6=t∈C(xi,j,s∨xi,j,t)]
2. start encodes that first row is starting config:
ϕstart =x1,1,#∧x1,2,q0∧. . .
3. accept says that accepting config should occur somewhere in tableau ϕacc =W
1≤i,j≤nkxi,j,qacc
4. move encodes that each row correponds to config that “legally” follows the preceding row config acc to N
ϕmove =V
1,≤i,j<nk (the (i,j)-window is legal)
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 15
Cook-Levin Theorem (Contd.)
Sketch: Step 3 - SAT formula
ϕ=ϕcell ∧ϕstart∧ϕmove ∧ϕacc where,
1. for each cell one variable is “on”, and only one is:
ϕcell =V
1≤i,j≤nk[W
s∈Cxi,j,s ∧W
s6=t∈C(xi,j,s∨xi,j,t)]
2. start encodes that first row is starting config:
ϕstart =x1,1,#∧x1,2,q0∧. . .
3. accept says that accepting config should occur somewhere in tableau ϕacc =W
1≤i,j≤nkxi,j,qacc
4. move encodes that each row correponds to config that “legally” follows the preceding row config acc to N
ϕmove =V
1,≤i,j<nk (the (i,j)-window is legal)
Cook-Levin Theorem (Contd.)
Sketch: Step 3 - SAT formula
ϕ=ϕcell ∧ϕstart∧ϕmove ∧ϕacc where,
1. for each cell one variable is “on”, and only one is:
ϕcell =V
1≤i,j≤nk[W
s∈Cxi,j,s ∧W
s6=t∈C(xi,j,s∨xi,j,t)]
2. start encodes that first row is starting config:
ϕstart =x1,1,#∧x1,2,q0∧. . .
3. accept says that accepting config should occur somewhere in tableau
ϕacc =W
1≤i,j≤nkxi,j,qacc
4. move encodes that each row correponds to config that “legally” follows the preceding row config acc to N
ϕmove =V
1,≤i,j<nk (the (i,j)-window is legal)
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 15
Cook-Levin Theorem (Contd.)
Sketch: Step 3 - SAT formula
ϕ=ϕcell ∧ϕstart∧ϕmove ∧ϕacc where,
1. for each cell one variable is “on”, and only one is:
ϕcell =V
1≤i,j≤nk[W
s∈Cxi,j,s ∧W
s6=t∈C(xi,j,s∨xi,j,t)]
2. start encodes that first row is starting config:
ϕstart =x1,1,#∧x1,2,q0∧. . .
3. accept says that accepting config should occur somewhere in tableau ϕacc =W
1≤i,j≤nkxi,j,qacc
4. move encodes that each row correponds to config that “legally” follows the preceding row config acc to N
ϕmove =V
1,≤i,j<nk (the (i,j)-window is legal)
Cook-Levin Theorem (Contd.)
Sketch: Step 3 - SAT formula
ϕ=ϕcell ∧ϕstart∧ϕmove ∧ϕacc where,
1. for each cell one variable is “on”, and only one is:
ϕcell =V
1≤i,j≤nk[W
s∈Cxi,j,s ∧W
s6=t∈C(xi,j,s∨xi,j,t)]
2. start encodes that first row is starting config:
ϕstart =x1,1,#∧x1,2,q0∧. . .
3. accept says that accepting config should occur somewhere in tableau ϕacc =W
1≤i,j≤nkxi,j,qacc
4. move encodes that each row correponds to config that “legally” follows the preceding row config acc to N
ϕmove =V
1,≤i,j<nk (the (i,j)-window is legal)
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 15
Cook-Levin Theorem (Contd.)
Sketch: Step 3 - SAT formula
ϕ=ϕcell ∧ϕstart∧ϕmove ∧ϕacc where,
1. for each cell one variable is “on”, and only one is:
ϕcell =V
1≤i,j≤nk[W
s∈Cxi,j,s ∧W
s6=t∈C(xi,j,s∨xi,j,t)]
2. start encodes that first row is starting config:
ϕstart =x1,1,#∧x1,2,q0∧. . .
3. accept says that accepting config should occur somewhere in tableau ϕacc =W
1≤i,j≤nkxi,j,qacc
4. move encodes that each row correponds to config that “legally” follows the preceding row config acc to N
ϕmove =V
1,≤i,j<nk (the (i,j)-window is legal)
Cook-Levin Theorem (Contd.)
Step 3 (Contd.) - Encoding NTM as SAT
ϕmove encodes that each row corresponds to config that “legally” follows preceding row acc to N
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 16
Cook-Levin Theorem (Contd.)
Step 3 (Contd.) - Encoding NTM as SAT
ϕmove encodes that each row corresponds to config that “legally” follows preceding row acc to N
1. enough to ensure that each 2×3 window of cells is legal, i.e., does not violate the transition function of N.
Cook-Levin Theorem (Contd.)
Step 3 (Contd.) - Encoding NTM as SAT
ϕmove encodes that each row corresponds to config that “legally” follows preceding row acc to N
1. enough to ensure that each 2×3 window of cells is legal, i.e., does not violate the transition function of N.
2. legal windows are “like” the dominos that we used in PCP!
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 16
Cook-Levin Theorem (Contd.)
Step 3 (Contd.) - Encoding NTM as SAT
ϕmove encodes that each row corresponds to config that “legally” follows preceding row acc to N
1. enough to ensure that each 2×3 window of cells is legal, i.e., does not violate the transition function of N.
2. legal windows are “like” the dominos that we used in PCP!
3. Ex: Give 3 examples of legal windows and 3 illegal windows, given δ(q,a) ={q,b,R},δ(q,b) ={(q0,c,L),(q0,a,R)}
Cook-Levin Theorem (Contd.)
Step 3 (Contd.) - Encoding NTM as SAT
ϕmove encodes that each row corresponds to config that “legally” follows preceding row acc to N
1. enough to ensure that each 2×3 window of cells is legal, i.e., does not violate the transition function of N.
2. legal windows are “like” the dominos that we used in PCP!
3. Claim: If top row is start, every window is legal, then each row is config that follows prev one.
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 16
Cook-Levin Theorem (Contd.)
Step 3 (Contd.) - Encoding NTM as SAT
ϕmove encodes that each row corresponds to config that “legally” follows preceding row acc to N
1. enough to ensure that each 2×3 window of cells is legal, i.e., does not violate the transition function of N.
2. legal windows are “like” the dominos that we used in PCP!
3. Claim: If top row is start, every window is legal, then each row is config that follows prev one.
ϕmove = ^
1≤i,j<nk
((i,j)−window is legal)
Cook-Levin Theorem (Contd.)
Step 3 (Contd.) - Encoding NTM as SAT
ϕmove encodes that each row corresponds to config that “legally” follows preceding row acc to N
1. enough to ensure that each 2×3 window of cells is legal, i.e., does not violate the transition function of N.
2. legal windows are “like” the dominos that we used in PCP!
3. Claim: If top row is start, every window is legal, then each row is config that follows prev one.
ϕmove = ^
1≤i,j<nk
((i,j)−window is legal)
Encode this as a disjunct W
a...a is legal(xi,j−1,a1)∧xi,j,a2∧...)
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 17
Cook-Levin Theorem (Completed!)
Completing the proof
I N has an acc computation onw iff ϕis SAT.
For detailed proof, read: Section 7.5 from Sipser’s book or Section 10.2 from Hopcroft, Motwani, Ullman’s book.
Cook-Levin Theorem (Completed!)
Completing the proof
I N has an acc computation onw iff ϕis SAT.
I Size of formula isO(n2k) and can be constructed in polynomial time (from w).
For detailed proof, read: Section 7.5 from Sipser’s book or Section 10.2 from Hopcroft, Motwani, Ullman’s book.
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 17
Cook-Levin Theorem (Completed!)
Completing the proof
I N has an acc computation onw iff ϕis SAT.
I Size of formula isO(n2k) and can be constructed in polynomial time (from w).
1. No. of cells is (nk)2=n2k, no. of cells in top row isnk.
For detailed proof, read: Section 7.5 from Sipser’s book or Section 10.2 from Hopcroft, Motwani, Ullman’s book.
Cook-Levin Theorem (Completed!)
Completing the proof
I N has an acc computation onw iff ϕis SAT.
I Size of formula isO(n2k) and can be constructed in polynomial time (from w).
1. No. of cells is (nk)2=n2k, no. of cells in top row isnk. 2. ϕstart is O(nk) (why?)
For detailed proof, read: Section 7.5 from Sipser’s book or Section 10.2 from Hopcroft, Motwani, Ullman’s book.
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 17
Cook-Levin Theorem (Completed!)
Completing the proof
I N has an acc computation onw iff ϕis SAT.
I Size of formula isO(n2k) and can be constructed in polynomial time (from w).
1. No. of cells is (nk)2=n2k, no. of cells in top row isnk. 2. ϕstart is O(nk) (why?)
3. All others are fixed size for each cell =O(n2k)
For detailed proof, read: Section 7.5 from Sipser’s book or Section 10.2 from Hopcroft, Motwani, Ullman’s book.
Cook-Levin Theorem (Completed!)
Completing the proof
I N has an acc computation onw iff ϕis SAT.
I Size of formula isO(n2k) and can be constructed in polynomial time (from w).
1. No. of cells is (nk)2=n2k, no. of cells in top row isnk. 2. ϕstart is O(nk) (why?)
3. All others are fixed size for each cell =O(n2k)
4. Can be constructed in polynomial time fromN,w, i.e., polytime reduction For detailed proof, read: Section 7.5 from Sipser’s book or Section 10.2 from Hopcroft, Motwani, Ullman’s book.
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 17
Cook-Levin Theorem (Completed!)
Completing the proof
I N has an acc computation onw iff ϕis SAT.
I Size of formula isO(n2k) and can be constructed in polynomial time (from w).
1. No. of cells is (nk)2=n2k, no. of cells in top row isnk. 2. ϕstart is O(nk) (why?)
3. All others are fixed size for each cell =O(n2k)
4. Can be constructed in polynomial time fromN,w, i.e., polytime reduction Thus, we have a PTime reduction from any NP problem to SAT, i.e., SAT is NP-hard.
For detailed proof, read: Section 7.5 from Sipser’s book or Section 10.2 from Hopcroft, Motwani, Ullman’s book.
NP-completeness examples
1. 3SAT is NP-complete. (why?)
2. CLIQUE is NP-complete. 3. SUBSETSUM is NP-complete. 4. Vertex cover is NP-complete.
5. A whole growing book of NP-complete problems! (Garey-Johnson) So, why are so many natural problems either inP or NP-complete? Well, there are some natural problems that are not known to be inP, but that are inNP and not known to beNP-hard.
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 18
NP-completeness examples
1. 3SAT is NP-complete. (why?) 2. CLIQUE is NP-complete.
3. SUBSETSUM is NP-complete. 4. Vertex cover is NP-complete.
5. A whole growing book of NP-complete problems! (Garey-Johnson) So, why are so many natural problems either inP or NP-complete? Well, there are some natural problems that are not known to be inP, but that are inNP and not known to beNP-hard.
NP-completeness examples
1. 3SAT is NP-complete. (why?) 2. CLIQUE is NP-complete.
3. SUBSETSUM is NP-complete.
4. Vertex cover is NP-complete.
5. A whole growing book of NP-complete problems! (Garey-Johnson) So, why are so many natural problems either inP or NP-complete? Well, there are some natural problems that are not known to be inP, but that are inNP and not known to beNP-hard.
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 18
NP-completeness examples
1. 3SAT is NP-complete. (why?) 2. CLIQUE is NP-complete.
3. SUBSETSUM is NP-complete.
4. Vertex cover is NP-complete.
5. A whole growing book of NP-complete problems! (Garey-Johnson) So, why are so many natural problems either inP or NP-complete? Well, there are some natural problems that are not known to be inP, but that are inNP and not known to beNP-hard.
NP-completeness examples
1. 3SAT is NP-complete. (why?) 2. CLIQUE is NP-complete.
3. SUBSETSUM is NP-complete.
4. Vertex cover is NP-complete.
5. A whole growing book of NP-complete problems! (Garey-Johnson)
So, why are so many natural problems either inP or NP-complete? Well, there are some natural problems that are not known to be inP, but that are inNP and not known to beNP-hard.
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 18
NP-completeness examples
1. 3SAT is NP-complete. (why?) 2. CLIQUE is NP-complete.
3. SUBSETSUM is NP-complete.
4. Vertex cover is NP-complete.
5. A whole growing book of NP-complete problems! (Garey-Johnson) So, why are so many natural problems either in P or NP-complete?
Well, there are some natural problems that are not known to be inP, but that are inNP and not known to beNP-hard.
NP-completeness examples
1. 3SAT is NP-complete. (why?) 2. CLIQUE is NP-complete.
3. SUBSETSUM is NP-complete.
4. Vertex cover is NP-complete.
5. A whole growing book of NP-complete problems! (Garey-Johnson) So, why are so many natural problems either in P or NP-complete?
Well, there are some natural problems that are not known to be in P, but that are in NP and not known to be NP-hard.
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 19
Getting around NP-hardness
Many problems are NP-complete. So what do people do?
An algorithmician’s answer:
1. Approximate!
2. Randomize. 3. Parametrize. 4. Quantize!
5. average/amortized/smoothed complexity.
A practitioner’s answer
1. What hardness? SAT is easy (almost always)!
2. The advent of SAT-solvers. Can solve SAT queries on millions of variables in seconds!
3. Goal nowadays: develop efficient encodinginto SAT!
Getting around NP-hardness
Many problems are NP-complete. So what do people do?
An algorithmician’s answer:
1. Approximate!
2. Randomize.
3. Parametrize. 4. Quantize!
5. average/amortized/smoothed complexity.
A practitioner’s answer
1. What hardness? SAT is easy (almost always)!
2. The advent of SAT-solvers. Can solve SAT queries on millions of variables in seconds!
3. Goal nowadays: develop efficient encodinginto SAT!
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 19
Getting around NP-hardness
Many problems are NP-complete. So what do people do?
An algorithmician’s answer:
1. Approximate!
2. Randomize.
3. Parametrize.
4. Quantize!
5. average/amortized/smoothed complexity.
A practitioner’s answer
1. What hardness? SAT is easy (almost always)!
2. The advent of SAT-solvers. Can solve SAT queries on millions of variables in seconds!
3. Goal nowadays: develop efficient encodinginto SAT!
Getting around NP-hardness
Many problems are NP-complete. So what do people do?
An algorithmician’s answer:
1. Approximate!
2. Randomize.
3. Parametrize.
4. Quantize!
5. average/amortized/smoothed complexity.
A practitioner’s answer
1. What hardness? SAT is easy (almost always)!
2. The advent of SAT-solvers. Can solve SAT queries on millions of variables in seconds!
3. Goal nowadays: develop efficient encodinginto SAT!
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 19
Getting around NP-hardness
Many problems are NP-complete. So what do people do?
An algorithmician’s answer:
1. Approximate!
2. Randomize.
3. Parametrize.
4. Quantize!
5. average/amortized/smoothed complexity.
A practitioner’s answer
1. What hardness? SAT is easy (almost always)!
2. The advent of SAT-solvers. Can solve SAT queries on millions of variables in seconds!
3. Goal nowadays: develop efficient encodinginto SAT!
Getting around NP-hardness
Many problems are NP-complete. So what do people do?
An algorithmician’s answer:
1. Approximate!
2. Randomize.
3. Parametrize.
4. Quantize!
5. average/amortized/smoothed complexity.
A practitioner’s answer
1. What hardness? SAT is easy (almost always)!
2. The advent of SAT-solvers. Can solve SAT queries on millions of variables in seconds!
3. Goal nowadays: develop efficient encodinginto SAT!
CS310 : Automata Theory 2020 Instructor: S. Akshay IITB, India 19
Getting around NP-hardness
Many problems are NP-complete. So what do people do?
An algorithmician’s answer:
1. Approximate!
2. Randomize.
3. Parametrize.
4. Quantize!
5. average/amortized/smoothed complexity.
A practitioner’s answer
1. What hardness? SAT is easy (almost always)!
2. The advent of SAT-solvers. Can solve SAT queries on millions of variables in seconds!
3. Goal nowadays: develop efficient encodinginto SAT!
Getting around NP-hardness
Many problems are NP-complete. So what do people do?
An algorithmician’s answer:
1. Approximate!
2. Randomize.
3. Parametrize.
4. Quantize!
5. average/amortized/smoothed complexity.
A practitioner’s answer
1. What hardness? SAT is easy (almost always)!
2. The advent of SAT-solvers. Can solve SAT queries on millions of