11.07.2015 Views

NP-Complete problems NP-Complete problems - Ace

NP-Complete problems NP-Complete problems - Ace

NP-Complete problems NP-Complete problems - Ace

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

✬✩<strong>NP</strong>-<strong>Complete</strong> <strong>problems</strong><strong>NP</strong>-complete <strong>problems</strong> (<strong>NP</strong>C):• A subset of <strong>NP</strong>.• If any <strong>NP</strong>-complete problem can be solved in polynomialtime, then every problem in <strong>NP</strong> has a polynomial timesolution.<strong>NP</strong>-complete languages are the “hardest” languages in <strong>NP</strong>.Formal definition of <strong>NP</strong>-complete languages is based on theconcept of polynomial time reducibility.CS404/504✫Design and Analysis of Algorithms: Lecture 26Computer Science1✪


✬✩From P to <strong>NP</strong>C• Examples of <strong>problems</strong> that belong to P:1. Find the shortest path between two vertices in a directedgraph.2. Does a directed graph have an Euler tour. i.e. a cyclethat visits all edges once?3. Is a Boolean formula in 2-conjunctive normal formsatisfiable?CS404/504✫Design and Analysis of Algorithms: Lecture 26Computer Science2✪


✬✩From P to <strong>NP</strong>C• However, their slight variants are in <strong>NP</strong>C:1. Find the longest path between two vertices in a directedgraph.2. Does a directed graph have a Hamiltonian cycle: a cyclethat visits all vertices once?3. Is a Boolean formula in 3-conjunctive normal formsatisfiable?CS404/504✫Design and Analysis of Algorithms: Lecture 26Computer Science3✪


✬✩Polynomial Time ReducibilityDefinition: A decision problem A is polynomial-time reducibleto a decision problem B (written A ≤ p B) if:• There exists a polynomial-time algorithm F that transformsany instance α of A into some instance β = F(α) of B,• The answer of A for α is “yes” iff the answer of B for β is“yes”.CS404/504✫Design and Analysis of Algorithms: Lecture 26Computer Science4✪


✬✩Polynomial reductionsCS404/504✫Design and Analysis of Algorithms: Lecture 26Computer Science5✪


✬✩A Formal Language framework: ReducibilityEvery decision problem has a corresponding language = themaximal set of input strings that produce “yes” answers.Let L A ,L B ⊆ {0,1} ∗ be the languages corresponding to the twodecision <strong>problems</strong> A and B, respectively.Definition: L A is polynomial-time reducible to L B (writtenL A ≤ p L B ) if:• there exists a poly-time computable functionf: {0,1} ∗ → {0,1} ∗• such that for all α ∈ {0,1} ∗α ∈ L A if and only if f(α) ∈ L B .CS404/504✫Design and Analysis of Algorithms: Lecture 26Computer Science6✪


✬✩Implication of A ≤ p B• f is called a reduction function and the poly-timealgorithm F that computes f is called a reductionalgorithm.• We can use B to solve A:– Providing an answer to whether f(α) ∈ L B directlyprovides the answer to whether α ∈ L A . Hence:• Solving A is no “harder” than solving B.CS404/504✫Design and Analysis of Algorithms: Lecture 26Computer Science7✪


✬✩Implication of A ≤ p BLemma 34.3 If L 1 ≤ p L 2 and L 2 ∈ P, then L 1 ∈ P.• Proof:– Let A 2 be a poly-time algorithm that decides L 2 .– Let F be a poly-time reduction algorithm that does thereduction.– We construct a poly-time algorithm A 1 that decides L 1 .CS404/504✫Design and Analysis of Algorithms: Lecture 26Computer Science8✪


✬✩<strong>NP</strong>-hard and <strong>NP</strong>-<strong>Complete</strong>• Definition: L is <strong>NP</strong>-hard if ∀ L’ ∈ <strong>NP</strong>, L’ ≤ p L.• Definition: L is <strong>NP</strong>-<strong>Complete</strong> if:1) L ∈ <strong>NP</strong>.2) L ∈ <strong>NP</strong>-hard.A very likely possibility:CS404/504✫Design and Analysis of Algorithms: Lecture 26Computer Science9✪


✬✩Circuit Satisfiability problemCS404/504✫Design and Analysis of Algorithms: Lecture 26Computer Science10✪


✬✩CKT-SAT problemDecision problem• Is there an assignment to the input that makes the circuitevaluate to TRUE?CKT-SAT = {〈CKT〉: CKT has a satisfying assignment}.• What is the running time of a brute force algorithm?CS404/504✫Design and Analysis of Algorithms: Lecture 26Computer Science11✪


✬✩CKT-SAT is <strong>NP</strong>-complete• Lemma 34.5: CKT-SAT ∈ <strong>NP</strong>.– We can take the number of gates + wires as the size kof the circuit.– We can create a binary encoding 〈CKT〉 that ispolynomial in k.– Certificate = an assignment of boolean values to thewires.– Checking whether the certificate corresponds to asatisfying assigment takes O(k) time.• Lemma 34.6: CKT-SAT ∈ <strong>NP</strong>-hard (pages 1074–1077).CS404/504✫Design and Analysis of Algorithms: Lecture 26Computer Science12✪


✬✩Alternative definition of <strong>NP</strong>-completenessLemma 34.8: If L is a language such that L’ ≤ p L for some L’∈ <strong>NP</strong>C, then L is <strong>NP</strong>-hard. Moreover, if L ∈ <strong>NP</strong>, then L ∈ <strong>NP</strong>C.Proof: Since L’ is <strong>NP</strong>-complete, for all L” ∈ <strong>NP</strong>, we have L”≤ p L’. By supposition, L’ ≤ p L, and thus by transitivity, wehave L” ≤ p L, which shows that L is <strong>NP</strong>-hard. If L ∈ <strong>NP</strong>, thenwe also have L ∈ <strong>NP</strong>C.Transitivity: If L 1 ≤ p L 2 and L 3 ≤ p L 3 , then L 1 ≤ p L 3 (Exercise34.3-2).CS404/504✫Design and Analysis of Algorithms: Lecture 26Computer Science13✪


✬✩L ∈ <strong>NP</strong>C: Generic Proof• Step 1: prove L ∈ <strong>NP</strong>.• Step 2: prove L ∈ <strong>NP</strong>-hard:1. Select a known <strong>NP</strong>-complete language L’.2. Find a reduction algorithm F, s.t. x ∈ L’ ⇔ F(x) ∈ L.3. Prove that the algorithm F runs in poly-time.Up to this point, the only <strong>NP</strong>C problem we know is CKT-SAT.CS404/504✫Design and Analysis of Algorithms: Lecture 26Computer Science14✪


✬✩Another <strong>NP</strong>C problem: SATFormula satisfiability problem (SAT)• A instance of SAT is a Boolean formula φ composed of1) n Boolean variables: x 1 ,x 2 ,...,x n .2) m Boolean connectors: ∧ (AND), ∨ (OR), ¬ (NOT), →(implication), ↔ (if and only if).3) parentheses.• For example: φ = ((x 1 → x 2 )∧(¬x 1 ∨x 2 ∨x 3 )) → (x 1 ∧¬x 2 ).• SAT = {〈φ〉: φ has a satisfying assignment (an assignmentcauses φ to evaluate to 1)}.• For example, x 1 ∨x 2 ∈ SAT, while x 1 ∧¬x 1 /∈ SAT.CS404/504✫Design and Analysis of Algorithms: Lecture 26Computer Science15✪


✬✩SAT is <strong>NP</strong>-<strong>Complete</strong>Proof:• Step 1: SAT ∈ <strong>NP</strong>.Certificate is the “truth assignment”. Algorithm merelyhas to verify, in polynomial time, that the truthassignment produces TRUE.• Step 2: SAT ∈ <strong>NP</strong>-hard.by proving CKT-SAT ≤ p SAT.CS404/504✫Design and Analysis of Algorithms: Lecture 26Computer Science16✪


✬✩SAT: Poly-time reductionThe reduction is as follows:• For each wire x i in the circuit C, the formula φ has avariable x i .• For each gate in C, make a formula involving the variablesof its incident wires that fully describes the behaviour of thegate.– For example, the operation of the output OR gate(figure on the next page) is x 5 ↔ (x 1 ∨x 2 ).• The formula φ produced by the reduction is the AND of thecircuit-output variable with the conjunction of clausesdescribing the operation of each gate.CS404/504✫Design and Analysis of Algorithms: Lecture 26Computer Science17✪


✬✩SAT: Poly-time reduction• For the above circuit C, the formula isφ = x 7 ∧(¬x 1 ↔ x 4 )∧(x 5 ↔ (x 1 ∨x 2 ))∧(x 2 ↔ ¬x 6 )∧(x 7 ↔ (x 4 ∧x 5 ∧x 3 ∧x 6 ))CS404/504✫Design and Analysis of Algorithms: Lecture 26Computer Science18✪


✬✩SAT: Poly-time reduction• Easy to see that C is satisfiable ⇔ φ is satisfiable.• The reduction runs in polynomial time.CS404/504✫Design and Analysis of Algorithms: Lecture 26Computer Science19✪

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!