NP Completeness COMP 455 – 002, Spring 2019

NP Completeness COMP 455 – 002, Spring 2019

NP Completeness COMP 455 – 002, Spring 2019 Jim Anderson (modified by Nathan Otterness) 1 Time Complexity (Revisited) A problem is a yes/no question. Example: The clique problem: Given a graph 퐺 and integer 푘, does 퐺 contain a 푘-clique? ❖(A 풌-clique is a fully-connected group of 푘 nodes.) 퐺, 푘 is an instance of this problem (for some specific graph 퐺). A problem is decidable if an algorithm exists that will take any instance of this problem and always produce the correct yes/no answer. We will only be concerned with decidable problems when An algorithm is a TM that always halts. discussing NP completeness. Jim Anderson (modified by Nathan Otterness) 2 Another Example Problem Consider this undirected graph: 푣1 Let 푘 = 3. We can encode an instance of the 푣2 clique problem as a string 푤: 푣4 푤 = 3 1,2 1,4 2,3 2,4 3,4 3,5 4,5 푣3 푣5 The language corresponding to the clique problem could be stated as follows: 퐿 = {all strings 푘 푖1, 푖2 … 푖푚, 푗푚 | the corresponding graph has a 푘-clique}. If 푀 is a TM that solves the clique problem, then 퐿 푀 = 퐿. Jim Anderson (modified by Nathan Otterness) 3 Additional Constraints on Encoding Many different ways exist to encode problems. For these problems, the choice of encoding matters! The standard encoding for these problems is binary or something “polynomially related” to binary. ❖ For example, decimal is OK. Unary is not OK. There are two reasons for this: With unary encodings, polynomial-time solutions exist to some NP-complete problems. This is because time complexity is measured based on input length! Using artificially long inputs is “cheating”. Real computers use binary encodings. Jim Anderson (modified by Nathan Otterness) 4 Two Basic Complexity Classes (There are lots of other classes—we’re just focusing on these two for now.) P-Time: Any language 퐿 accepted in polynomial time by some deterministic TM. NP-Time: Any language 퐿 accepted in polynomial time by some nondeterministic TM. ❖ Recall that the time complexity of a NDTM is based on the smallest number of moves needed to accept a string of a given length. We usually abbreviate P-Time as “P” and NP-Time as “NP.” Jim Anderson (modified by Nathan Otterness) 5 The Relationship Between P and NP P NP Every DTM is also a NDTM, so P is in NP. It’s not known whether 푃 = 푁푃 or 푃 ⊂ 푁푃. Jim Anderson (modified by Nathan Otterness) 6 P vs. NP The P = NP question is the most important open question in theoretical computer science. Here’s why: Lots of interesting problems are in NP. Problems in P have “efficient” solutions. (Meaning deterministic, polynomial-time solutions.) For many important problems in NP (e.g. yes/no counterparts to optimization problems or graph problems) we haven’t found “efficient” solutions despite decades of research. ❖ The suggests that 푃 ≠ 푁푃. ❖ But, if 푃 = 푁푃, then these problems do have “efficient” solutions. Jim Anderson (modified by Nathan Otterness) 7 Hard and Complete Problems We want to identify the “hardest” problems in NP. If the “hard” problems have deterministic polynomial- time solutions, then so do all problems in NP. This reduces the P=NP question to that of whether one of these “hard” problems is in P. Jim Anderson (modified by Nathan Otterness) 8 In other words, we Hard and Complete Problems want a DTM that converts instances of one problem to What do we specifically mean by “hard” and instances of another “complete”? We need some more definitions: in polynomial time. 퐿 is polynomially transformable to 퐿′ if there exists a polynomial-time-bounded DTM 푀 that can convert each string 푤 in the alphabet of 퐿 into a string 푤′ in the alphabet of 퐿′ such that 푤 ∈ 퐿 if and only if 푤′ ∈ 퐿′. Let 퐶 be a class of languages. 퐿 is hard for 푪 if every language in 퐶 is polynomially transformable to 퐿. 퐿 is complete for 푪 if 퐿 is in 퐶 and hard for 퐶. Jim Anderson (modified by Nathan Otterness) 9 NP-Complete Problems Using the previous definitions, 퐿 is NP-complete if it is in NP and NP-hard. Note: Showing that 퐿 is in NP is usually straightforward: show that a NDTM can accept 퐿 by “guessing” an answer and then verifying the guess is correct in polynomial time. Our goal is to first identify some NP-complete problems. Jim Anderson (modified by Nathan Otterness) 10 NP-Complete Problems Given the unlikelihood of P=NP, if a language 퐿 is NP- complete, then 퐿 is probably an intractable problem. ❖Note: “NP-complete” is not (currently) synonymous with “exponential time.” We can show P=NP if we’re able to find a single NP- Complete problem that’s in P. Nobody’s been able to do so, but it hasn’t been proven impossible yet, either. Jim Anderson (modified by Nathan Otterness) 11 “Guess-and-Verify” Example Let a NDTM accept strings of the form 10푖110푖2 … 10푖푘 such that there is some 퐼 ⊆ 1, … , 푘 for which This technically isn’t a σ푗∈퐼 푖푗 = σ푗∉퐼 푖푗. “legal” encoding (it (This is called the partition problem.) encodes 푖푛 using a unary # of 0s). We’re Here’s how our NDTM can work: just using it here to The TM has three tapes, the input is on tape 1. simplify the example. The TM scans the input and copies each group of 0s to either tape 2 or tape 3, the choice being nondeterministic. The TM accepts if an equal number of 0s were copied to both tapes after scanning the entire input string. Jim Anderson (modified by Nathan Otterness) 12 Proving a Problem is NP-Complete There are two ways to show 퐿 is NP complete: Prove it from scratch (very difficult!) Use reduction: I. Show that 퐿 is in NP (i.e. design a “guess-and- verify” polynomial-time NDTM for 퐿), and II. Show that a known NP-complete problem can be polynomially transformed to 퐿. So, if we want to use reduction, we first need a known NP-complete problem. Jim Anderson (modified by Nathan Otterness) 13 Cook’s Theorem The satisfiability problem is the following: given a Boolean expression 퐸, is it possible to assign values to the variables in such a way that makes 퐸 true? Example: 푥 ∨ 푦 ∧ 푧 is satisfiable. 푥 ∨ 푦 ∧ 푥ҧ ∧ 푦ത is not satisfiable. Cook’s Theorem: The satisfiability problem is NP- complete. The proof is too long to cover in this class, so we will need to take it on faith. Jim Anderson (modified by Nathan Otterness) 14 Variations on Satisfiability A conjunct is a group of A literal is either 푥 or ¬푥, where 푥 is a Boolean literals or clauses that variable. are “and”-ed together. A Boolean expression is in conjunctive normal form (CNF) if it is a conjunct of “clauses” of literals: ❖Example: 푎 ∨ 푏 ∧ 푐 ∧ ¬푎 ∨ 푏 ∨ ¬푐 k-CNF: A conjunct of clauses containing 푘 literals. A clause is a group k-satisfiability: Satisfiability for expressions in k- of literals that are CNF. “or”-d together. Jim Anderson (modified by Nathan Otterness) 15 Variations on Satisfiability We will show the following: Satisfiability We won’t cover this in class (see Section 10.3.3 of the book for details). Satisfiability for expressions in These are easier to CNF use in subsequent We will cover this reductions. polynomial transformation. 3-satisifiability Jim Anderson (modified by Nathan Otterness) 16 3-Sat The satisfiability problem for CNF expressions with exactly three literals per clause is called 3- satisifiability (“3-Sat”). ❖Example: Is 푎 ∨ 푏 ∨ 푐 ∧ ¬푐 ∨ 푑 ∨ 푒 satisfiable? Jim Anderson (modified by Nathan Otterness) 17 3-Sat Theorem 10.15: 3-satisfiability is NP-complete. Proof: We must do two things: Show 3-Sat is in NP. ❖ This is easy: just nondeterministically generate an assignment for each variable, then, in polynomial time verify that each clause evaluates to true. This is called a reduction Show 3-Sat is NP-hard. from CNF-Sat. ❖ To do this we will show that if we can solve 3-Sat efficiently, then we can solve CNF-Sat efficiently. Jim Anderson (modified by Nathan Otterness) 18 Reducing from CNF-Sat to 3-Sat Our goal is to take a Boolean expression in CNF and, in polynomial time, generate a new expression in 3-CNF that is satisfiable if and only if the original CNF expression is satisfiable. We want to show that if a polynomial time solution to 3-CNF exists, then the following algorithm would be possible: 1. Convert a CNF-Sat problem to a 3-Sat problem in polynomial time. 2. Use the polynomial-time 3-Sat algorithm to determine if the converted expression is satisfiable. Jim Anderson (modified by Nathan Otterness) 19 Reducing from CNF-Sat to 3-Sat Converting from CNF-Sat to 3-Sat: We can convert each clause containing 푛 literals 푥1 … 푥푛 to a conjunct of 푛 − 2 new clauses, each of which contain exactly three literals. ❖This requires adding 푛 − 3 new literals 푦1 … 푦푛−3 per clause. Example: 푥1 ∨ 푥2 ∨ ⋯ ∨ 푥푛 becomes: 푥1 ∨ 푥2 ∨ 푦1 ∧ 푦1 ∨ 푥3 ∨ 푦2 ∧ 푦2 ∨ 푥4 ∨ 푦3 ∧ ⋯ ∧ 푦푛−4 ∨ 푥푛−2 ∨ 푦푛−3 ∧ 푦푛−3 ∨ 푥푛−1 ∨ 푥푛 Jim Anderson (modified by Nathan Otterness) 20 Reducing from CNF-Sat to 3-Sat We want to show that the old expression is satisfiable if and only if the new expression is satisfiable. Old: 푥 ∨ 푥 ∨ ⋯ ∨ 푥 First: The old expression is satisfiable ⇒ the new 1 2 푛 expression is satisfiable.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    38 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us