BU CS 332 – Theory of Computation Lecture 22: Reading: • NP ‐ Completeness Example Sipser Ch 8.1 ‐ 8.2 • Space Complexity • Savitch’s Theorem Mark Bun April 22, 2020
NP ‐ completeness Definition: A language is NP ‐ complete if 1) and 2) Every language is poly ‐ time reducible to , i.e., (“ is NP ‐ hard”) � Theorem: If and for some NP ‐ complete � language , then is also NP ‐ complete 4/22/2020 CS332 ‐ Theory of Computation 2
(3 ‐ CNF Satisfiability) Definition(s): • A literal either a variable of its negation � , � • A clause is a disjunction (OR) of literals Ex. � � � • A 3 ‐ CNF is a conjunction (AND) of clauses where each clause contains exactly 3 literals Ex. … � � � � � � � � � � � � Cook ‐ Levin Theorem: is NP ‐ complete 4/22/2020 CS332 ‐ Theory of Computation 3
4/22/2020 CS332 ‐ Theory of Computation 4
Some general reduction strategies • Reduction by simple equivalence Ex. 𝐽𝑂𝐸𝐹𝑄𝐹𝑂𝐸𝐹𝑂𝑈 � 𝑇𝐹𝑈 � � 𝑊𝐹𝑆𝑈𝐹𝑌 � 𝐷𝑃𝑊𝐹𝑆 and 𝑊𝐹𝑆𝑈𝐹𝑌 � 𝐷𝑃𝑊𝐹𝑆 � � 𝐽𝑂𝐸𝐹𝑄𝐹𝑂𝐸𝐹𝑂𝑈 � 𝑇𝐹𝑈 • Reduction from special case to general case Ex. 𝑊𝐹𝑆𝑈𝐹𝑌 � 𝐷𝑃𝑊𝐹𝑆 � � 𝑇𝐹𝑈 � 𝐷𝑃𝑊𝐹𝑆 • Gadget reductions Ex. 3 𝑇𝐵𝑈 � � 𝐽𝑂𝐸𝐹𝑄𝐹𝑂𝐸𝐹𝑂𝑈 � 𝑇𝐹𝑈 4/22/2020 CS332 ‐ Theory of Computation 5
Independent Set An independent set in an undirected graph 𝐻 is a set of vertices that includes at most one endpoint of every edge. 𝐽𝑂𝐸𝐹𝑄𝐹𝑂𝐸𝐹𝑂𝑈 � 𝑇𝐹𝑈 � 𝐻 , 𝑙 𝐻 is an undirected graph containing an independent set with � 𝑙 vertices � • Is there an independent set of size 6? • Yes. independent set • Is there an independent set of size 7? • No. 4/22/2020 CS332 ‐ Theory of Computation 6
Independent Set is NP ‐ complete 1) 2) Reduce � Proof. “On input 𝜒 , where 𝜒 is a 3CNF formula, 1. Construct graph 𝐻 from 𝜒 • 𝐻 contains 3 vertices for each clause, one for each literal. • Connect 3 literals in a clause in a triangle. • Connect literal to each of its negations. Output 𝐻 , 𝑙 , where 𝑙 is the number of clauses in 𝜒 . ” 2. 4/22/2020 CS332 ‐ Theory of Computation 7
Example of the reduction 𝜒 � 𝑦 � ∨ 𝑦 � ∨ 𝑦 � ∧ 𝑦 � ∨ 𝑦 � ∨ 𝑦 � ∧ 𝑦 � ∨ 𝑦 � ∨ 𝑦 � 4/22/2020 CS332 ‐ Theory of Computation 8
Proof of correctness for reduction Let 𝑙 = # clauses and 𝑚 = # literals in 𝜒 Claim: 𝜒 is satisfiable iff 𝐻 has an ind. set of size 𝑙 ⟹ Given a satisfying assignment, select one literal from each triangle. This is an ind. set of size 𝑙 ⟸ Let 𝑇 be an ind. set of size 𝑙 • 𝑇 must contain exactly one vertex in each triangle • Set these literals to true, and set all other variables in an arbitrary way • Truth assignment is consistent and all clauses satisfied Runtime: 𝑃�𝑙 � 𝑚 � � which is polynomial in input size 4/22/2020 CS332 ‐ Theory of Computation 9
Space Complexity 4/22/2020 CS332 ‐ Theory of Computation 10
Complexity measures we’ve studied so far • Deterministic time TIME • Nondeterministic time NTIME • Classes P, NP Many other resources of interest: Space (memory), randomness, parallel runtime / #processors, quantum entanglement, interaction, communication, … 4/22/2020 CS332 ‐ Theory of Computation 11
Space analysis Space complexity of a TM (algorithm) = maximum number of tape cell it uses on a worst ‐ case input Formally: Let . A TM runs in space if on ∗ , every input halts on using at most cells For nondeterministic machines: Let . An NTM ∗ , runs in space if on every input halts on using at most cells on every computational branch 4/22/2020 CS332 ‐ Theory of Computation 12
Space complexity classes Let A language if there exists a basic single ‐ tape (deterministic) TM that 1) Decides , and 2) Runs in space A language if there exists a single ‐ tape nondeterministic TM that 1) Decides , and 2) Runs in space 4/22/2020 CS332 ‐ Theory of Computation 13
Example: Space complexity of SAT Theorem: Proof: The following deterministic TM decides using linear space On input where is a Boolean formula: 1. For each truth assignment to the variables � of : � 2. Evaluate on � � 3. If any evaluation , accept. Else, reject. 4/22/2020 CS332 ‐ Theory of Computation 14
Example: NFA analysis ∗ Theorem: Let ��� Then . ��� Proof: The following NTM decides ��� in linear space On input where is an NTM: 1. Place a marker on the start state of . Repeat � times where is the # of states of : 2. 3. Nondeterministically select . 4. Adjust the markers to simulate all ways for to read 5. Accept if at any point none of the markers are on an accept state. Else, reject. 4/22/2020 CS332 ‐ Theory of Computation 15
Example 0,1 ε 0 3 1 2 1 4/22/2020 CS332 ‐ Theory of Computation 16
Space vs. Time 4/22/2020 CS332 ‐ Theory of Computation 17
Space vs. Time How about the opposite direction? Can low ‐ space algorithms be simulated by low ‐ time algorithms? 4/22/2020 CS332 ‐ Theory of Computation 18
Reminder: Configurations ∗ A configuration is a string where and • Tape contents = (followed by blanks ) • Current state = • Tape head on first symbol of Example: � Start configuration: � Accepting configuration: = ������ Rejecting configuration: = ������ 4/22/2020 CS332 ‐ Theory of Computation 19
Reminder: Configurations Consider a TM with • states • tape alphabet • space How many configurations are possible when this TM is run on � an input Observation: If a TM enters the same configuration twice when run on input it loops forever Corollary: A TM running in space also runs in time � � � 4/22/2020 CS332 ‐ Theory of Computation 20
Savitch’s Theorem 4/22/2020 CS332 ‐ Theory of Computation 21
Savitch’s Theorem: Deterministic vs. Nondeterministic Space Theorem: Let be a function with . Then � 4/22/2020 CS332 ‐ Theory of Computation 22
Recommend
More recommend