P, NP, NP-completeness 2 Reductions 1 Thu, July 7 th 1.

Slides:



Advertisements
Similar presentations
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
Advertisements

Lecture 21 NP-complete problems
The Theory of NP-Completeness
1 NP-Complete Problems. 2 We discuss some hard problems:  how hard? (computational complexity)  what makes them hard?  any solutions? Definitions 
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
Graphs 4/16/2017 8:41 PM NP-Completeness.
The Theory of NP-Completeness
Analysis of Algorithms CS 477/677
NP-Completeness (2) NP-Completeness Graphs 4/17/2017 6:25 AM x x x x x
CSE 421 Algorithms Richard Anderson Lecture 27 NP Completeness.
Chapter 11 Limitations of Algorithm Power Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Toward NP-Completeness: Introduction Almost all the algorithms we studies so far were bounded by some polynomial in the size of the input, so we call them.
P, NP, and NP-Complete Suzan Köknar-Tezel.
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
Programming & Data Structures
Introduction to Intractability P, NP, NP-completeness How To Approach Intractable Problems Monday, August 3 rd 1.
The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial.
1 The Theory of NP-Completeness 2012/11/6 P: the class of problems which can be solved by a deterministic polynomial algorithm. NP : the class of decision.
Nattee Niparnan. Easy & Hard Problem What is “difficulty” of problem? Difficult for computer scientist to derive algorithm for the problem? Difficult.
Complexity Classes (Ch. 34) The class P: class of problems that can be solved in time that is polynomial in the size of the input, n. if input size is.
Tonga Institute of Higher Education Design and Analysis of Algorithms IT 254 Lecture 8: Complexity Theory.
Lecture 22 More NPC problems
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
Week 10Complexity of Algorithms1 Hard Computational Problems Some computational problems are hard Despite a numerous attempts we do not know any efficient.
CSE 024: Design & Analysis of Algorithms Chapter 9: NP Completeness Sedgewick Chp:40 David Luebke’s Course Notes / University of Virginia, Computer Science.
CSC401 – Analysis of Algorithms Chapter 13 NP-Completeness Objectives: Introduce the definitions of P and NP problems Introduce the definitions of NP-hard.
1 The Theory of NP-Completeness 2 Cook ’ s Theorem (1971) Prof. Cook Toronto U. Receiving Turing Award (1982) Discussing difficult problems: worst case.
Unit 9: Coping with NP-Completeness
1 Chapter 34: NP-Completeness. 2 About this Tutorial What is NP ? How to check if a problem is in NP ? Cook-Levin Theorem Showing one of the most difficult.
NP-COMPLETE PROBLEMS. Admin  Two more assignments…  No office hours on tomorrow.
NP-Complete problems.
Design and Analysis of Algorithms - Chapter 101 Our old list of problems b Sorting b Searching b Shortest paths in a graph b Minimum spanning tree b Primality.
NP-Completeness (Nondeterministic Polynomial Completeness) Sushanth Sivaram Vallath & Z. Joseph.
CS 3343: Analysis of Algorithms Lecture 25: P and NP Some slides courtesy of Carola Wenk.
CS6045: Advanced Algorithms NP Completeness. NP-Completeness Some problems are intractable: as they grow large, we are unable to solve them in reasonable.
NP Completeness Piyush Kumar. Today Reductions Proving Lower Bounds revisited Decision and Optimization Problems SAT and 3-SAT P Vs NP Dealing with NP-Complete.
CSC 413/513: Intro to Algorithms
NP-Completeness Note. Some illustrations are taken from (KT) Kleinberg and Tardos. Algorithm Design (DPV)Dasgupta, Papadimitriou, and Vazirani. Algorithms.
1 Ch 10 - NP-completeness Tractable and intractable problems Decision/Optimization problems Deterministic/NonDeterministic algorithms Classes P and NP.
CSE 421 Algorithms Richard Anderson Lecture 27 NP-Completeness Proofs.
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
COSC 3101A - Design and Analysis of Algorithms 14 NP-Completeness.
1 The Theory of NP-Completeness 2 Review: Finding lower bound by problem transformation Problem X reduces to problem Y (X  Y ) iff X can be solved by.
CSE 332: NP Completeness, Part II Richard Anderson Spring 2016.
TU/e Algorithms (2IL15) – Lecture 10 1 NP-Completeness, II.
ICS 353: Design and Analysis of Algorithms NP-Complete Problems King Fahd University of Petroleum & Minerals Information & Computer Science Department.
The Theory of NP-Completeness
NP Completeness Continued: Reductions
Chapter 10 NP-Complete Problems.
Richard Anderson Lecture 26 NP-Completeness
Advanced Algorithms Analysis and Design
NP-Completeness (2) NP-Completeness Graphs 7/23/ :02 PM x x x x
Richard Anderson Lecture 26 NP-Completeness
Hard Problems Introduction to NP
NP-Completeness Yin Tat Lee
Intro to Theory of Computation
ICS 353: Design and Analysis of Algorithms
Richard Anderson Lecture 25 NP-Completeness
Richard Anderson Lecture 28 NP-Completeness
Chapter 34: NP-Completeness
Richard Anderson Lecture 30 NP-Completeness
Chapter 11 Limitations of Algorithm Power
CS 3343: Analysis of Algorithms
NP-Completeness Yin Tat Lee
P, NP and NP-Complete Problems
The Theory of NP-Completeness
CSE 589 Applied Algorithms Spring 1999
P, NP and NP-Complete Problems
Our old list of problems
RAIK 283 Data Structures & Algorithms
Presentation transcript:

P, NP, NP-completeness 2 Reductions 1 Thu, July 7 th 1

Formalizing Tractability: Class P 2  Given a computational (decision) problem C  P: C is ∈ P (polynomial-time solvable) if ∃ an algorithm solving C with O(n k ) run-time, for some constant k.  where n is the input length in bits  k is some constant, say, 1, 2, 5, 1M, etc.  Ex poly-times: O(n), O(nlog(n)), O(n 3 ), O(n )  Ex: Every problem we saw so far (except 0-1 knapsack)

Fact: Some Problems Seem Intractable Ex: TSP 3 TSP: Traveling Salesman Problem Input: Complete graph G(V, E) with non-negative edge costs Output: ∃ a tour with cost ≤ k [i.e., cycle visiting each v once]? D C B A

Making a Case For TSP’s Intractability 4  (So far) We have not been able to argue for TSP’s intractability in an absolute sense. Idea From Early 1970s: Instead show “relative” intractability (i.e. show TSP is as hard as bunch of other problems C.)

Reductions: Showing C 2 is as hard as C 1 5 What does it mean for problem C 2 to be as hard as C 1 ? Definition: C 1 reduces to C 2, (C 1 ≤ p C 2 ), if given a poly- time algorithm for C 2, we can solve C 1 in poly-time. If C 1 reduces to C 2 => C 2 is “as hard as” C 1 Poly-time Alg for C 2 Π 1 ∈ C 1 Poly-time C 1 -> C 2 Converter Poly-time C 1 -> C 2 Converter Π 2 ∈ C 2 Solution to Π 2 Poly-time C 2 Solution -> C 1 Solution Converter Poly-time C 2 Solution -> C 1 Solution Converter Solution to Π 1

C = NP: Brute-force Solvable Problems Option 2: Let C be all brute-force solvable problems Definition (NP or brute-force solvable problems): A problem C ∈ NP if: 1.Correct solutions have polynomial length. 2.Claimed solutions are verifiable in poly-time. Q: Why do these 2 imply that C is exp-time solvable? There are 2 poly(n) possible solutions. Just verify & see if one is a solution: O(poly(n)2 poly(n) ) Dfn: EXP-Time = 2 poly(n) for some polynomial

Example NP problems  Every problem we have seen in CS 341.  Every problem in P.  (Most-likely) Every problem you will ever see in practice.  Ex: Decision version of TSP: ∃ T of size ≤ k? 1.Each tour T is a cycle of size n, so poly-length. 2.We can verify length of T in poly-time: just sum each edge in T. Warning: NP does not stand for: Not Polynomial It stands for: Non-deterministic Polynomial

Definition: Completeness 8 Let C be a set of problems. Ci ∈ CCi ∈ C If ∀ C k ∈ C, C k ≤ p C i, then C i is C -complete. (i.e. C i is as hard as every other problem in C ) (i.e. C i is the hardest problem in C ) Goal: Argue TSP is NP-complete

What is an NP-complete Problem? 9 NP C1C1 C1C1 C*: NP- complete C3C3 C3C3 C4C4 C4C4 C5C5 C5C5 C6C6 C6C6 CkCk CkCk C2C2 C2C2 C* is as hard as any NP problem!

Solving an NP-complete Problem 10 NP C1C1 C1C1 C*: NP- complete C3C3 C3C3 C4C4 C4C4 C5C5 C5C5 C6C6 C6C6 CkCk CkCk C2C2 C2C2 If we can solve C* efficiently, we can solve every single NP problem (basically all problems in practice)!!!

Two Ways to Argue C* is NP-Complete (1) Just argue every NP problem reduces to C* NP C1C1 C1C1 C* C3C3 C3C3 C4C4 C4C4 C5C5 C5C5 CkCk CkCk C6C6 C6C6 C2C2 C2C2 Done for SAT (& CIRCUIT-SAT) in 1970 by Cook & Levin

Leonid Levin 12  Soviet-American computer scientist  Current at Boston University

Two Ways to Argue C* is NP-Complete (2) Argue an NP-complete C** reduces to C* NP C1C1 C1C1 C* C3C3 C3C3 C4C4 C4C4 C5C5 C5C5 CkCk CkCk C6C6 C6C6 C** Done since 1971 for 1000s of problems C2C2 C2C2 B/c reductions are transitive => All NP problems reduce to C*

History of NP-completeness 14 NP C2C2 C2C2 SAT C3C3 C3C3 C4C4 C4C4 C5C5 C5C5 CkCk CkCk C6C6 C6C6 C1C1 C1C1 K1K1 K1K1 K2K2 K2K2 … … K 20 K : Cook-Levin1972: Karp

History of NP-completeness 15 NP C2C2 C2C2 SAT C3C3 C3C3 C4C4 C4C4 C5C5 C5C5 CkCk CkCk C6C6 C6C6 C1C1 C1C1 K1K1 K1K1 K2K2 K2K2 … … K 20 K 21 NP-complete Since 1972

Method 1: Ex: CIRCUIT-SAT 16 Input: A circuit C of AND, OR, and NOT gates n inputs x 1, x 2, …, x n Output: Is C satisfiable, are there 0/1 values to x i that make C output 1? AND OR AND OR ANDNOTOR NOTAND NOT AND OR NOT AND OR AND x1x1 x2x2 x3x3 x4x4 x5x5

17 Method 1: Ex: CIRCUIT-SAT Idea for proving every NP problem C* reduces to CIRCUIT-SAT: Every NP problem by dfn has a poly-time verifier algorithm A. A takes poly-size inputs and runs poly-time. Represent the state of the machine at each time-step of A by a sub-circuit. Merge the sub-circuits into a circuit Z. (All poly-time operations) And argue that C* returns YES iff circuit Z has a satisfiable input.

Method 2: “Intractability” Argument for TSP 18 Show that TSP is NP-complete => i.e. TSP is as hard as any other NP problem By showing that another known NP-complete problem reduces to it.

Why is TSP NP-complete? 19 HAM-CYCLE Problem: Input: Undirected Graph G(V, E) Output: YES if G contains a Hamiltonian cycle/NO o.w Dfn: A Ham. Cycle is a simple cycle that contain each vertex of the graph once. Fact: Hamiltonian Cycle is NP-complete. SAT≤ p 3-SAT≤ p CLIQUE≤ p VERTEX-COVER≤ p HAM-CYCLE

Hamiltonian Cycle Example (1) 20 F CB A D E G

Hamiltonian Cycle Example 21 F CB A D E G Answer: YES.

Hamiltonian Cycle Example 22 F C B A E

Hamiltonian Cycle Example 23 F C B A E Answer: NO. Any complete cycle has to visit A twice

Observation: TSP vs Hamiltonian Cycle 24 D C B A TSP is simply asking for the minimum weight HC. (or TSP-Decision is asking if a HC with weight < k exists?

HAM-CYCLE ≤ p TSP 25 Efficient Alg A for TSP Π 1 ∈ HC Efficient HC-TSP Converter Π 2 ∈ TSP Solution to TSP Efficient TSP-HC Solution Converter Efficient TSP-HC Solution Converter Solution to HC Need to show the two converters

HAM-CYCLE ≤ p TSP 26 Let G(V, E) be the input to HAM-CYCLE HC-TSP Converter: Let G*(V, E*) be a complete graph with edge weights: w((u, v)) = 0 if (u, v) ∈ E w((u,v)) = 1 if (u, v) ∉ E TSP-HC Solution Converter: ∃ a Hamiltonian Cycle in G ⇔ ∃ a TSP Tour with weight 0 Runtime: O(n 2 ) Runtime: O(1)

Proof of Claim 27 => If ∃ a Hamiltonian Cycle C in G, then since each edge of C has weight 0 in E*, then C is a tour in G* with weight 0 <= If ∃ a tour T with weight 0 in G*, then all of its edges must be of weight 0, and hence from E, so T is a hamiltonian cycle in G Q.E.D Therefore, if we can solve TSP efficiently, we can solve HAM-CYCLE efficiently.

Completing TSP’s NP-completeness Proof 28 If we can solve TSP efficiently, we can solve HAM- CYCLE efficiently (by just transforming the input G to G* in poly-time & transforming the solution of TSP to HC in poly-time) since HAM-CYCLE is NP-complete  we can solve every single NP problem efficiently  TSP is NP-complete Q.E.D

Does P = NP? 29 We know P ⊆ NP. Two possibilities: NP P P=NP Is every problem, whose solutions are efficiently verifiable, is also efficiently solvable? We don’t know. But most people believe P ≠ NP.

Why Do People Believe P ≠ NP? 30 1.There are 1000s of NP-complete problems and for none of them is there a poly-time algorithm. 2.Counter to General Human Experience 3.Also some weird mathematical consequences, such as polynomial hierarchy collapsing, and others… But We Simply Don’t Know (Yet)!

How could we resolve P vs NP? 31 NP P P=NP Prove an NP-complete problem is solvable in poly time. Prove an NP-complete problem is NOT solvable in poly time. We don’t know which world we live in.

Your Problem is NP-complete. Now What? 32  Option 1: Focus to special-case inputs.  Ex: Independent Set is NP-complete.  Focusing on line graphs, had a O(n) DP alg.  Option 2: Find an approximate answer.  Will show a very simple algorithm for 0-1 Knapsack.  Option 3: Be exponential time but better than brute- force search.  0-1 Knapscak O(nW) runtime DP algorihm.  Option 4: Heuristics: fast algorithms that are not always correct (or even approximate)  Option 5: Mix some of these options

Overview of the next 2 Lectures 33 Indep. Set 3-(CNF)SAT SAT Vertex Cover CLIQUE Hamiltonian Cycle TSP Subset Sum 0/1 Knapscak

SAT: The First NP-Complete Problem 34 Input: A boolean formula φ consisting of: n boolean variables x 1, x 2, …, x n m boolean connectives: ∧ (AND), ∨ (OR), ¬ (NOT), (iff), → (implication), … (can be others) and parantheses Output: Is φ satisfiable? I.e., are there true/false values to x i that make φ true?

Example SAT Formulas 35 φ = (x 1 → x 2 ) ∧ ¬x 2 Q: Is this satisfiable? A: Yes x1x1 x2x2 (x 1 → x 2 ) ∧ ¬x

Example SAT Formulas 36 φ = (x 1 → x 2 ) ∧ ¬x 2 Q: Is this satisfiable? A: Yes x1x1 x2x2 (x 1 → x 2 ) ∧ ¬x

Example SAT Formulas 37 φ = (x 1 → ¬x 2 ) ∧ ¬x 2 Q: Is this satisfiable? A: Yes x1x1 x2x2 (x 1 → ¬x 2 ) ∧ ¬x

Example SAT Formula 38 φ = (x 1 → ¬x 2 ) ∧ ¬x 2 Q: Is this satisfiable? A: Yes x1x1 x2x2 (x 1 → ¬x 2 ) ∧ ¬x

Example SAT Formula 39 φ = ((x 1 ∧ x 2 ∧ x 3 ) (¬x 1 ∧ x 3 )) x1x1 x2x2 x3x3 φ Q: Is this satisfiable? A: No

Recall 2 Criteria For NP-Completeness 40 1.C* has to be in NP. 2.Every other NP problem has to reduce to C*.

Criterion 1: Why is SAT in NP? 41 Can verify a solution X* = (x 1 = 0/1, …., x n = 0/1) is linear time! Just check if X* makes φ true!

Criterion 2: Why does every NP problem reduce to SAT? 42 Method 1: Cook-Levin Theorem Won’t show in class Method 2: Or can show CIRCUIT-SAT, which is NP- complete reduces to SAT

3-CNFSAT 43 Input: A boolean formula φ consisting of: n boolean variables x 1, x 2, …, x n m boolean connectives: ∧ (AND), ∨ (OR), ¬ (NOT) and parantheses s.t. (1) each clause has 3 distinct literals; AND (2) φ is in Conjunctive Normal Form Output: Is φ satisfiable?

Conjunctive Normal Form 44 φ = (x 1 ∨ ¬x 3 ∨ x 7 ) ∧ (x 2 ∨ ¬x 3 ∨ x 5 ) ∧ (¬x 1 ∨ x 2 ∨ ¬x 7 ) ∧ … Clauses φ is in CNF: if (1) each clause is an OR of literals or their negations & (2) φ is an AND of clauses φ is in 3-CNF: if (1) φ is in CNF & (2) clauses have 3 distinct literals x i are literals

Criterion 1: Why is 3-CNFSAT in NP? 45 Can verify a solution X* = (x 1 = 0/1, …., x n = 0/1) is linear time! Just check if X* makes φ true! Specifically check if X* makes each clause true!

Criterion 2: SAT ≤ p 3-CNFSAT 46 Efficient Alg A for 3-CNFSAT Efficient Alg A for 3-CNFSAT Π 1 ∈ SAT Efficient SAT- 3-CNFSAT Converter Π 2 ∈ 3-SAT Solution to 3-CNFSAT Efficient 3-CNFSAT-SAT Solution Converter Efficient 3-CNFSAT-SAT Solution Converter Solution to SAT Need to show the two converters

SAT ≤ p 3-CNFSAT Converter 47 Say φ = ((x 1 → x 2 ) ∨ ¬((¬x 1 ↔ x 3 ) ∨ x 4 ))) ∧ ¬ x 2 Goal: In poly-time convert φ to an equivalent 3CNF formula φ```

Parse Tree: ((x 1 → x 2 ) ∨ ¬((¬x 1 ↔ x 3 ) ∨ x 4 ))) ∧ ¬x 2 48 ∧ ∧ ¬x 2 (x 1 → x 2 ) ∨ ¬((¬x 1 ↔ x 3 ) ∨ x 4 )

Parse Tree: ((x 1 → x 2 ) ∨ ¬((¬x 1 ↔ x 3 ) ∨ x 4 ))) ∧ ¬x 2 49 ∧ ∧ ¬x 2 ∨ ∨ x 1 → x 2 ¬((¬ x 1 ↔ x 3 ) ∨ x 4 )

Parse Tree: ((x 1 → x 2 ) ∨ ¬((¬x 1 ↔ x 3 ) ∨ x 4 ))) ∧ ¬x 2 50 ∧ ∧ ¬x 2 ∨ ∨ → → x1x1 x2x2 ¬((¬ x 1 ↔ x 3 ) ∨ x 4 )

Parse Tree: ((x 1 → x 2 ) ∨ ¬((¬x 1 ↔ x 3 ) ∨ x 4 ))) ∧ ¬x 2 51 ∧ ∧ ¬x 2 ∨ ∨ ¬ ¬ → → x1x1 x2x2 (¬ x 1 ↔ x 3 ) ∨ x 4

Parse Tree: ((x 1 → x 2 ) ∨ ¬((¬x 1 ↔ x 3 ) ∨ x 4 ))) ∧ ¬x 2 52 ∧ ∧ ¬x 2 ∨ ∨ ¬ ¬ → → ∨ ∨ x1x1 x2x2 ¬x1↔x3¬x1↔x3 x4x4

Parse Tree: ((x 1 → x 2 ) ∨ ¬((¬x 1 ↔ x 3 ) ∨ x 4 ))) ∧ ¬x 2 53 ∧ ∧ ¬x 2 ∨ ∨ ¬ ¬ → → ∨ ∨ ↔ ↔ x1x1 x2x2 ¬x1¬x1 x3x3 x4x4

Parse Tree: ((x 1 → x 2 ) ∨ ¬((¬x 1 ↔ x 3 ) ∨ x 4 ))) ∧ ¬x 2 54 ∧ ∧ ¬x 2 ∨ ∨ ¬ ¬ → → ∨ ∨ ↔ ↔ x1x1 x2x2 ¬x1¬x1 x3x3 x4x4 Call the entire formula variable y 1

Parse Tree: ((x 1 → x 2 ) ∨ ¬((¬x 1 ↔ x 3 ) ∨ x 4 ))) ∧ ¬x 2 55 ∧ ∧ ¬x 2 ∨ ∨ ¬ ¬ → → ∨ ∨ ↔ ↔ x1x1 x2x2 ¬x1¬x1 x3x3 x4x4 Call this subformula variable y 2 y1y1

Parse Tree: ((x 1 → x 2 ) ∨ ¬((¬x 1 ↔ x 3 ) ∨ x 4 ))) ∧ ¬x 2 56 ∧ ∧ ¬x 2 ∨ ∨ ¬ ¬ → → ∨ ∨ ↔ ↔ x1x1 x2x2 ¬x1¬x1 x3x3 x4x4 Call this subformula variable y 3 y1y1 y2y2

Parse Tree: ((x 1 → x 2 ) ∨ ¬((¬x 1 ↔ x 3 ) ∨ x 4 ))) ∧ ¬x 2 57 ∧ ∧ ¬x 2 ∨ ∨ ¬ ¬ → → ∨ ∨ ↔ ↔ x1x1 x2x2 ¬x1¬x1 x3x3 x4x4 Call this subformula variable y 3 y1y1 y2y2 y3y3

Parse Tree: ((x 1 → x 2 ) ∨ ¬((¬x 1 ↔ x 3 ) ∨ x 4 ))) ∧ ¬x 2 58 ∧ ∧ ¬x 2 ∨ ∨ ¬ ¬ → → ∨ ∨ ↔ ↔ x1x1 x2x2 ¬x1¬x1 x3x3 x4x4 so and so forth y1y1 y2y2 y3y3 y4y4 y5y5 y6y6

Parse Tree: ((x 1 → x 2 ) ∨ ¬((¬x 1 ↔ x 3 ) ∨ x 4 ))) ∧ ¬x 2 59 ∧ ∧ ¬x 2 ∨ ∨ ¬ ¬ → → ∨ ∨ ↔ ↔ x1x1 x2x2 ¬x1¬x1 x3x3 x4x4 Then: y 1 is true iff y 2 ∧ ¬x 2 is true y1y1 y2y2 y3y3 y4y4 y5y5 y6y6

Parse Tree: ((x 1 → x 2 ) ∨ ¬((¬x 1 ↔ x 3 ) ∨ x 4 ))) ∧ ¬x 2 60 ∧ ∧ ¬x 2 ∨ ∨ ¬ ¬ → → ∨ ∨ ↔ ↔ x1x1 x2x2 ¬x1¬x1 x3x3 x4x4 In other words: y 1 ↔ (y 2 ∧ ¬x 2 ) y 2 ↔ (y 3 ∨ y 4 ) y 3 ↔ (x 1 → x 2 ) y 4 ↔ ¬y 5 y 5 ↔ y 6 ∨ x 4 y 6 ↔ ¬x 1 ↔ x 3 y1y1 y2y2 y3y3 y4y4 y5y5 y6y6

Parse Tree: ((x 1 → x 2 ) ∨ ¬((¬x 1 ↔ x 3 ) ∨ x 4 ))) ∧ ¬x 2 61 ∧ ∧ ¬x 2 ∨ ∨ ¬ ¬ → → ∨ ∨ ↔ ↔ x1x1 x2x2 ¬x1¬x1 x3x3 x4x4 φ` = y 1 ∧ (y 1 ↔ (y 2 ∧ ¬x 2 )) ∧ (y 2 ↔ (y 3 ∨ y 4 )) ∧ (y 3 ↔ (x 1 → x 2 )) ∧ (y 4 ↔ ¬y 5 ) ∧ (y 5 ↔ y 6 ∨ x 4 ) ∧ (y 6 ↔ ¬x 1 ↔ x 3 ) y1y1 y2y2 y3y3 y4y4 y5y5 y6y6

Getting closer to 3CNF 62 φ` = y 1 ∧ (y 1 ↔ (y 2 ∧ ¬x 2 )) ∧ (y 2 ↔ (y 3 ∨ y 4 )) ∧ (y 3 ↔ (x 1 → x 2 )) ∧ (y 4 ↔ ¬y 5 ) ∧ (y 5 ↔ y 6 ∨ x 4 ) ∧ (y 6 ↔ ¬x 1 ↔ x 3 ) φ = ((x 1 → x 2 ) ∨ ¬((¬x 1 ↔ x 3 ) ∨ x 4 ))) ∧ ¬x 2  Progress so far: 1.φ=φ` 2.φ` is the AND of clauses that contain ≤ 3 distinct literals  But clauses: 1.contain bool connectives other than ∨, ∧, ¬. 2.don’t contain exactly 3 literals

Turning Arbitrary Connectives to CNF 63 φ` = y 1 ∧ (y 1 ↔ (y 2 ∧ ¬x 2 )) ∧ (y 2 ↔ (y 3 ∨ y 4 )) ∧ (y 3 ↔ (x 1 → x 2 )) ∧ (y 4 ↔ ¬y 5 ) ∧ (y 5 ↔ y 6 ∨ x 4 ) ∧ (y 6 ↔ ¬x 1 ↔ x 3 ) y1y1 y2y2 x2x2 (y 1 ↔ (y 2 ∧ ¬x 2 )) F=(y 1 ↔ (y 2 ∧ ¬x 2 )) Q: When is F false? G=[(¬y 1 ∧ y 2 ∧ ¬x 2 ) ∨ (y 1 ∧ ¬y 2 ∧ ¬x 2 ) ∨ (y 1 ∧ ¬y 2 ∧ x 2 ) ∨ (y 1 ∧ y 2 ∧ x 2 )]

Turning Arbitrary Connectives to CNF 64 φ` = y 1 ∧ (y 1 ↔ (y 2 ∧ ¬x 2 )) ∧ (y 2 ↔ (y 3 ∨ y 4 )) ∧ (y 3 ↔ (x 1 → x 2 )) ∧ (y 4 ↔ ¬y 5 ) ∧ (y 5 ↔ y 6 ∨ x 4 ) ∧ (y 6 ↔ ¬x 1 ↔ x 3 ) y1y1 y2y2 x2x2 (y 1 ↔ (y 2 ∧ ¬x 2 )) F=(y 1 ↔ (y 2 ∧ ¬x 2 )) Q: When is F true? ¬G So we can replace F with ¬G

DeMorgan’s Law 65 ¬(a ∨ b) = ¬a ∧ ¬b ¬(a ∧ b) = ¬a ∨ ¬b ¬G = ¬ [(¬y 1 ∧ y 2 ∧ ¬x 2 ) ∨ (y 1 ∧ ¬y 2 ∧ ¬x 2 ) ∨ (y 1 ∧ ¬y 2 ∧ x 2 ) ∨ (y 1 ∧ y 2 ∧ x 2 )] = [¬(¬y 1 ∧ y 2 ∧ ¬x 2 )] ∧ [¬(y 1 ∧ ¬y 2 ∧ ¬x 2 )] ∧ [¬(y 1 ∧ ¬y 2 ∧ x 2 )] ∧ [¬(y 1 ∧ y 2 ∧ x 2 )] = ¬G = [(y 1 ∨ ¬y 2 ∨ x 2 )] ∧ [(¬y 1 ∨ y 2 ∨ x 2 )] ∧ [ (¬y 1 ∨ y 2 ∨ ¬x 2 )] ∧ [(¬y 1 ∨ ¬y 2 ∨ ¬x 2 )]

Turning Arbitrary Connectives to CNF 66 Can replace (y 1 ↔ (y 2 ∧ ¬x 2 )) with [(y 1 ∨ ¬y 2 ∨ x 2 )] ∧ [(¬y 1 ∨ y 2 ∨ x 2 )] ∧ [ (¬y 1 ∨ y 2 ∨ ¬x 2 )] ∧ [(¬y 1 ∨ ¬y 2 ∨ ¬x 2 )], which is in CNF Do this for all clauses and get φ`` φ` = y 1 ∧ (y 1 ↔ (y 2 ∧ ¬x 2 )) ∧ (y 2 ↔ (y 3 ∨ y 4 )) ∧ (y 3 ↔ (x 1 → x 2 )) ∧ (y 4 ↔ ¬y 5 ) ∧ (y 5 ↔ y 6 ∨ x 4 ) ∧ (y 6 ↔ ¬x 1 ↔ x 3 )

Getting closer to 3CNF 67 φ`` = y 1 ∧ [(y 1 ∨ ¬y 2 ∨ x 2 )] ∧ [(¬y 1 ∨ y 2 ∨ x 2 )] ∧ [ (¬y 1 ∨ y 2 ∨ ¬x 2 )] ∧ [(¬y 1 ∨ ¬y 2 ∨ ¬x 2 )] … φ = ((x 1 → x 2 ) ∨ ¬((¬x 1 ↔ x 3 ) ∨ x 4 ))) ∧ ¬x 2  Progress so far: 1.φ=φ` 2.φ`` is in CNF with ≤ 3 distinct literals in each clause  But clauses: 1.don’t contain exactly 3 literals

Completing Clauses to 3 Literals 68 φ`` = y 1 ∧ [(y 1 ∨ ¬y 2 ∨ x 2 )] ∧ [(¬y 1 ∨ y 2 ∨ x 2 )] ∧ [ (¬y 1 ∨ y 2 ∨ ¬x 2 )] ∧ [(¬y 1 ∨ ¬y 2 ∨ ¬x 2 )] … φ = ((x 1 → x 2 ) ∨ ¬((¬x 1 ↔ x 3 ) ∨ x 4 ))) ∧ ¬x 2 Add dummy variables p and q with tautologies to complete each clause to exactly 3 literals. Case 1: There is 1 variable in the clause, e.g., y 1 Change y 1 with: H = (y 1 ∨ p ∨ q) ∧ (y 1 ∨ p ∨ ¬q) ∧ (y 1 ∨ ¬p ∨ q) ∧ (y 1 ∨ ¬p ∨ ¬q) Note: H ↔ y 1

Completing Clauses to 3 Literals 69 Case 2: There are 2 variables in clause, e.g., (y 1 ∨ y 2 ) Change (y 1 ∨ y 2 ) with: T = (y 1 ∨ y 2 ∨ p) ∧ (y 1 ∨ y 2 ∨ ¬p) Note: T ↔ y 1 ∨ y 2 We are now done! We have an equivalent φ``` that is in 3CNF.

Runtime of our SAT->3-CNFSAT Converter? 70 φ  φ`: added y i ; so O(m) time φ`  φ``: expanded each clause by ≤ 8 clauses; so O(m) time as well φ``  φ```: (expanded each clause by ≤ 4 clauses; so O(m) time as well. Total Runtime: O(m) Converting the solutions is O(1) time b/c φ =φ```

Conclusion 71 3-CNFSAT is NP-complete!

Overview of the next 2 Lectures 72 Indep. Set Vertex Cover CLIQUE Hamiltonian Cycle TSP Subset Sum 0/1 Knapscak (CNF)-SAT 3-(CNF)SAT