CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong NP-complete.

Slides:



Advertisements
Similar presentations
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
Advertisements

Theory of Computing Lecture 18 MAS 714 Hartmut Klauck.
Polynomial-time reductions We have seen several reductions:
NP-Completeness: Reductions
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
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.
Complexity 11-1 Complexity Andrei Bulatov NP-Completeness.
Computability and Complexity 14-1 Computability and Complexity Andrei Bulatov Cook’s Theorem.
NP-completeness Sipser 7.4 (pages 271 – 283). CS 311 Mount Holyoke College 2 The classes P and NP NP = ∪ k NTIME(n k ) P = ∪ k TIME(n k )
NP-completeness Sipser 7.4 (pages 271 – 283). CS 311 Fall The classes P and NP NP = ∪ k NTIME(n k ) P = ∪ k TIME(n k )
CS21 Decidability and Tractability
February 23, 2015CS21 Lecture 201 CS21 Decidability and Tractability Lecture 20 February 23, 2015.
Computability and Complexity 15-1 Computability and Complexity Andrei Bulatov NP-Completeness.
Graphs 4/16/2017 8:41 PM NP-Completeness.
NP and NP-completeness
1 Polynomial Time Reductions Polynomial Computable function : For any computes in polynomial time.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 23 Instructor: Paul Beame.
NP-Completeness (2) NP-Completeness Graphs 4/17/2017 6:25 AM x x x x x
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 24 Instructor: Paul Beame.
Clique Cover Cook’s Theorem 3SAT and Independent Set
February 20, 2015CS21 Lecture 191 CS21 Decidability and Tractability Lecture 19 February 20, 2015.
February 18, 2015CS21 Lecture 181 CS21 Decidability and Tractability Lecture 18 February 18, 2015.
Lecture 22 More NPC problems
Theory of Computation, Feodor F. Dragan, Kent State University 1 NP-Completeness P: is the set of decision problems (or languages) that are solvable in.
Computational Complexity Theory Lecture 2: Reductions, NP-completeness, Cook-Levin theorem Indian Institute of Science.
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.
EMIS 8373: Integer Programming NP-Complete Problems updated 21 April 2009.
CSC401 – Analysis of Algorithms Chapter 13 NP-Completeness Objectives: Introduce the definitions of P and NP problems Introduce the definitions of NP-hard.
Additional NP-complete problems
1 P P := the class of decision problems (languages) decided by a Turing machine so that for some polynomial p and all x, the machine terminates after at.
NP-Complete Problems. Running Time v.s. Input Size Concern with problems whose complexity may be described by exponential functions. Tractable problems.
CS 3343: Analysis of Algorithms Lecture 25: P and NP Some slides courtesy of Carola Wenk.
NP-completeness Section 7.4 Giorgi Japaridze Theory of Computability.
CSCI 3130: Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong The Cook-Levin.
CSE 589 Part V One of the symptoms of an approaching nervous breakdown is the belief that one’s work is terribly important. Bertrand Russell.
CS6045: Advanced Algorithms NP Completeness. NP-Completeness Some problems are intractable: as they grow large, we are unable to solve them in reasonable.
CSE 6311 – Spring 2009 ADVANCED COMPUTATIONAL MODELS AND ALGORITHMS Lecture Notes – Feb. 3, 2009 Instructor: Dr. Gautam Das notes by Walter Wilson.
Chapter 11 Introduction to Computational Complexity Copyright © 2011 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1.
CSC 413/513: Intro to Algorithms
COMPLEXITY. Satisfiability(SAT) problem Conjunctive normal form(CNF): Let S be a Boolean expression in CNF. That is, S is the product(and) of several.
NP-complete Languages
CSCI 2670 Introduction to Theory of Computing December 2, 2004.
CSCI 2670 Introduction to Theory of Computing December 7, 2005.
CSE 421 Algorithms Richard Anderson Lecture 27 NP-Completeness Proofs.
Given this 3-SAT problem: (x1 or x2 or x3) AND (¬x1 or ¬x2 or ¬x2) AND (¬x3 or ¬x1 or x2) 1. Draw the graph that you would use if you want to solve this.
Complexity ©D.Moshkovitz 1 Our First NP-Complete Problem The Cook-Levin theorem A B C.
COMPLEXITY. Satisfiability(SAT) problem Conjunctive normal form(CNF): Let S be a Boolean expression in CNF. That is, S is the product(and) of several.
Computability Examples. Reducibility. NP completeness. Homework: Find other examples of NP complete problems.
 2005 SDU Lecture15 P,NP,NP-complete.  2005 SDU 2 The PATH problem PATH = { | G is a directed graph that has a directed path from s to t} s t
TU/e Algorithms (2IL15) – Lecture 10 1 NP-Completeness, II.
NP-Completeness (2) NP-Completeness Graphs 4/13/2018 5:22 AM x x x x x
NP and NP-completeness
Richard Anderson Lecture 26 NP-Completeness
NP-Completeness (2) NP-Completeness Graphs 7/23/ :02 PM x x x x
NP-Completeness (2) NP-Completeness Graphs 7/23/ :02 PM x x x x
Richard Anderson Lecture 26 NP-Completeness
NP-Completeness (36.4-5) P: yes and no in pt NP: yes in pt NPH  NPC
NP-complete problems The Chinese University of Hong Kong Fall 2008
NP-Completeness Yin Tat Lee
CS21 Decidability and Tractability
NP-Completeness (2) NP-Completeness Graphs 11/23/2018 2:12 PM x x x x
NP-Complete Problems.
NP-completeness The Chinese University of Hong Kong Fall 2008
NP-Completeness Yin Tat Lee
More on NP-completeness
More NP-complete problems
Lecture 23 NP-Hard Problems
Presentation transcript:

CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong NP-complete problems Fall 2009

Polynomial-time reductions Language L polynomial-time reduces to L’ if there exists a polynomial-time computable map R that takes an instance x of L into instance y of L’ s.t. x ∈ L if and only if y ∈ L’ LL’(CLIQUE)(IS) xy (G, k) (G’, k’) x ∈ Lx ∈ L y ∈ L’y ∈ L’ (G has clique of size k)(G’ has IS of size k’) R

The Cook-Levin Theorem Every L ∈ NP reduces to SAT SAT = {f: f is a satisfiable Boolean formula } (x 1 ∨ x 2 ) ∧ (x 2 ∨ x 3 ∨ x 4 ) ∧ (x 1 ) f = is satisfiable x 1 = T x 2 = F x 3 = T x 4 = T (x 1 ∨ x 2 ) ∧ (x 1 ) ∧ (x 2 ) f = is not satisfiable

NP-hardness Language L is NP -hard if every L’ in NP reduces to L Intuitively, NP -hard means “harder than all of NP ” The Cook-Levin Theorem says SAT is NP -hard P SAT NP

NP-complete L is NP -complete if L is NP -hard and L ∈ NP Intuitively, NP -complete means “hardest in NP ” Recall that SAT ∈ NP, so SAT is NP -complete If SAT ∈ P, then P = NP P SAT NP

Proof of Cook-Levin Theorem To prove it, we have to describe a reduction R : Every L ∈ NP reduces to SAT w Boolean formula f w ∈ Lw ∈ L f is satisfiable R

Proof of Cook-Levin Theorem All we know about L : It has a poly-time NTM M –Let’s look at computation tableau of M on input w M w w1w1 q0q0 q acc … S- th configuration symbol at time T S T Since M is nondeterministic, there may be many possible tableaus # … # # # #

Proof of Cook-Levin Theorem S T n = length of input w height of tableau is p(n) for some polynomial p width is at most p(n) k possible tableau symbols x T, S, u = true,if the (T, S) cell of tableau contains u if not false, u 1 ≤ S ≤ p(n) 1 ≤ T ≤ p(n) 1 ≤ u ≤ k w1w1 q0q0 … ## q acc … # # #

Proof of Cook-Levin Theorem We will design a formula f such that: w Boolean formula f w ∈ Lw ∈ L f is satisfiable R variables of f : assignment to x T, S, u way to fill up the tableau satisfying assignment accepting computation tableau f is satisfiable x T, S, u M accepts w

Proof of Cook-Levin Theorem We want to construct (in time poly(n) ) a formula f : x T, S, u = true,if the (T, S) cell of tableau contains u if not false, 1 ≤ S ≤ p(n) 1 ≤ T ≤ p(n) 1 ≤ u ≤ k f(x 1, 1, 1,..., x p(n), p(n), k ) = true,if the x s represent a valid accepting tableau if not false, Symbols in computation tableau come from some alphabet {a 1,...,a k }

Proof of Cook-Levin Theorem f = f cell ∧ f 0 ∧ f move ∧ f acc f cell : “Every cell contains exactly one symbol” “The first row is #q 0 w 1 w 2...w k ☐... ☐ # ” f0:f0: f move : “The moves between rows follow the transitions of M ” f acc : “ q acc appears somewhere in the last row” S T u w1w1 q0q0 … ## q acc … # # #

Proof of Cook-Levin Theorem Desired meaning Implementation: f cell : “Every cell contains exactly one symbol” f cell = f cell 1, 1 ∧... ∧ f cell p(n), p(n) where f cell T, S = (x T, S, 1 ∨... ∨ x T, S, k ) ∧ (x T, S, 1 ∧ x T, S, 2 ) ∧ (x T, S, 1 ∧ x T, S, 3 ) ∧... ∧ (x T, S, k-1 ∧ x T, S, k ) at least one symbol no two symbols or: “Exactly one of x S, T, 1 ∨... ∨ x S, T, k is true”

Proof of Cook-Levin Theorem Desired meaning Implementation: f0:f0: “The first row is #q 0 w 1 w 2...w k ☐... ☐ # ” f acc : “ q acc appears somewhere in the last row” f 0 = x 1, 1, # ∧ x 1, 1, q0 ∧ x 1, 1, w1 ∧... ∧ x 1, p(n),# f acc = x p(n), 1, qacc ∨ x p(n), 2, qacc ∨... ∨ x p(n), p(n), qacc

Valid and invalid windows … 6 a 3 b 0 x 0 … … 0 a 6 b 0 x 0 … 0 valid windows … 6 # 3 b 0 a 0 … … 0 # 6 b 0 q 5 … 0 … 6 a 3 q 2 a 0 … … 0 q 5 a 6 x 0 … 0 … 6 q 2 a 0 b 0 … … 0 a 6 b 0 q 2 … 0 invalid windows … 6 a 3 a 0 ☐ 0 … … 0 x 6 a 0 ☐ 0 … 0 q2q2 q5q5 a/xL … 6 a 3 q 2 a 0 … … 0 q 5 a 6 b 0 … 0 … 6 q 2 q 2 a 0 … … 0 q 2 q 2 x 3 … 0 … 6 a 3 q 2 a 0 … … 0 a 6 q 5 x 0 … 0

Proof of Cook-Levin Theorem Desired meaning Implementation: f move : “The moves between rows follow transitions of M ” a q0q0 q acc … f move = f move 1, 1 ∧... ∧ f move p(n)-3, p(n)-3 b q3q3 a b q7q7 cb f move 2, 2 f move T, S = over all (x T, S, a1 ∧ x T, S+1, a2 ∧ x T, S+2, a3 ∧ x T+1, S, a4 ∧ x T+1, S+1, a5 ∧ x T+2, S+1, a6 ) ∨ valid windows a1a2a3 a4a5a6 # # # ## #

Other NP- complete problems CLIQUE = {(G, k): G is a graph with a clique of k vertices } IS = {(G, k): G is a graph with an independent set of k vertices } VC = {(G, k): G is a graph with a vertex cover of k vertices } CLIQUE, IS and VC are NP -complete SAT NP CLIQUEIS VC

Proving NP -hardness To show L is NP -hard, it is enough to reduce from some L’ we already know is NP -hard –For now we can take L’ = SAT To show L is NP -complete, we also need to argue that L is in NP –This is usually the easy part roadmap: SAT 3SAT IS CLIQUE VC

3SAT SAT = {f: f is a satisfiable Boolean formula } 3SAT = {f: f is a satisfiable Boolean formula in conjunctive normal form with 3 literals per clause } CNF: AND of ORs of literals literal: x i or x i (conjunctive normal form) 3CNF: CNF with 3 literals per clause (x 1 ∨ x 2 ∨ x 2 ) ∧ (x 2 ∨ x 3 ∨ x 4 ) clause literals (x 2 ∨ (x 1 ∧ x 2 )) ∧ (x 1 ∧ (x 1 ∨ x 2 )) gates (repetitions are allowed)

NP-hardness of 3SAT Theorem Proof: We describe a reduction R from SAT Boolean formula f 3CNF formula f’ f’ is satisfiable R f is satisfiable 3SAT is NP -hard

Reducing SAT to 3SAT Example: f = (x 2 ∨ (x 1 ∧ x 2 )) ∧ (x 1 ∧ (x 1 ∨ x 2 )) We give extra variables to every gate (“wire”) x3x3 x6x6 x7x7 x8x8 x9x9 x4x4 x5x5 x 10 AND ORNOT AND NOTOR AND NOT x2x2 x1x1 x2x2 x1x1 x1x1 x2x2 x 7 = x 4 ∧ x 5 x 4 x 5 x 7 T T T T T T F F T F T F T F F T F T T F F T F T F F T F F F F T (x4∨x5∨x7)(x4∨x5∨x7) (x4∨x5∨x7)(x4∨x5∨x7) (x4∨x5∨x7)(x4∨x5∨x7) (x4∨x5∨x7)(x4∨x5∨x7) (x4∨x5∨x7)(x4∨x5∨x7) ∧(x4∨x5∨x7)∧(x4∨x5∨x7) ∧(x4∨x5∨x7)∧(x4∨x5∨x7) ∧(x4∨x5∨x7)∧(x4∨x5∨x7)

Turning gates into 3CNFs AND T T T T T T F F T F T F T F F T F T T F F T F T F F T F F F F T z = y ∧ x xy z xy z (x ∨ y ∨ z) ∧ (x ∨ y ∨ z) ∧ (x ∨ y ∨ z) ∧ (x ∨ y ∨ z) OR T T T T T T F F T F T T T F F F F T T T F T F F F F T F F F F T z = y ∨ x xy z xy z (x ∨ y ∨ z) ∧ (x ∨ y ∨ z) ∧ (x ∨ y ∨ z) ∧ (x ∨ y ∨ z) NOT T T F T F T F T T F F F z = xx z x z (x∨z)∧(x∨z)(x∨z)∧(x∨z) (x∨x∨z)∧(x∨x∨z)(x∨x∨z)∧(x∨x∨z) Gj:Gj: fj:fj:

Reducing SAT to 3SAT Boolean formula f 3CNF formula f’ R f’ = f n+1 ∧ f n+2 ∧... ∧ f t ∧ (x n+t ∨ x n+t ∨ x n+t ) requires that output of f is true On input f, where f is a boolean formula Construct and output the following 3CNF formula f’: R:R: Add variable x n+j for each gate G j in f Write 3CNF f j for each gate G j, j = {1,..., t} Let

Reducing SAT to 3SAT Every satisfying assignment of f extends uniquely to a satisfying assignment of f’ Conversely, every satisfying assignment of f’ must contain a satisfying assignment of f Boolean formula f 3CNF formula f’ R f’ is satisfiable f is satisfiable

Clique Theorem CLIQUE = {(G, k): G is a graph with a clique of k vertices } A clique is a subset of vertices so that all pairs are connected {1, 2, 3}, {1, 4}, {4} are cliques CLIQUE is NP -hard ✓ SAT 3SAT IS CLIQUE VC

Reducing 3SAT to CLIQUE Proof: We give a reduction from 3SAT to CLIQUE 3SAT = {f: f is a satisfiable Boolean formula in 3CNF } CLIQUE = {(G, k): G is a graph with a clique of k vertices } 3CNF formula f (G, k) G has a clique of size k R f is satisfiable

Reducing 3SAT to CLIQUE Example: f = (x 1 ∨ x 1 ∨ x 2 ) ∧ (x 1 ∨ x 2 ∨ x 2 ) ∧ (x 1 ∨ x 2 ∨ x 3 ) Put an edge for every consistent pair x1x1 x1x1 x2x2 x1x1 x2x2 x2x2 x1x1 x2x2 x3x3 Put a vertex for every literal

Reducing 3SAT to CLIQUE On input f, where f is a 3CNF formula with m clauses Construct the following graph G: G has 3m vertices, divided into m groups, one for each literal in f 3CNF formula f (G, k) R R:R: If a and b are in different groups and a ≠ b, put an edge (a, b) Output (G, m)

Reducing 3SAT to CLIQUE 3CNF formula f (G, m) G has a clique of size m R f is satisfiable f = (x 1 ∨ x 1 ∨ x 2 ) ∧ (x 1 ∨ x 2 ∨ x 2 ) ∧ (x 1 ∨ x 2 ∨ x 3 ) x1x1 x1x1 x2x2 x1x1 x2x2 x2x2 x1x1 x2x2 x3x3 TTFFFTFFT

Reducing 3SAT to CLIQUE 3CNF formula f (G, m) G has a clique of size m R f is satisfiable f = (x 1 ∨ x 1 ∨ x 2 ) ∧ (x 1 ∨ x 2 ∨ x 2 ) ∧ (x 1 ∨ x 2 ∨ x 3 ) x1x1 x1x1 x2x2 x1x1 x2x2 x2x2 x1x1 x2x2 x3x3 FTTFFTTTF

✓ SAT 3SAT IS CLIQUE VC Reducing 3SAT to CLIQUE Every satisfying assignment of f gives a clique of size m in G Conversely, every clique of size m in G gives a consistent satisfying assignment of f. 3CNF formula f (G, m) G has a clique of size m R f is satisfiable ✓ ✓

Vertex cover ✓ SAT 3SAT IS CLIQUE ✓ ✓ Theorem VC is NP -hard A vertex cover is a set of vertices that touches (covers) all edges {2, 4}, {3, 4}, {1, 2, 3} are vertex covers VC = {(G, k): G is a graph with a vertex cover of size k} VC

Reducing CLIQUE to VC Proof: We describe a reduction from IS to VC Example (G’, k’) G’ has a VC of size k’ R (G, k) G has an IS of size k ∅, {1}, {2}, {3}, {4}, {1, 2}, {1, 3} {2, 4}, {3, 4}, {1, 2, 3}, {1, 2, 4}, {1, 3, 4}, {2, 3, 4}, {1, 2, 3, 4} independent sets vertex covers

Reducing IS to VC Claim Proof S is an independent set of G if and only if S is a vertex cover of G S is an independent set of G no edge has both endpoints in S every edge has an endpoint in S S is a vertex cover of G ∅ {1} {2} {3} {4} {1, 2} {1, 3} {2, 4} {3, 4} {1, 2, 3} {1, 2, 4} {1, 3, 4} {2, 3, 4} {1, 2, 3, 4} IS VC

Reducing IS to VC (G’, k’) R (G, k) G has a VC of size n – kG has an IS of size k On input (G, k), R:R: Output (G, n – k). ✓ SAT 3SAT IS CLIQUE VC ✓ ✓ ✓

The ubiquity of NP-complete problems We saw a few examples of NP-complete problems, but there are many more A surprising fact of life is that most CS problems are either in P or NP- complete A 1979 book by Garey and Johnson lists 100+ NP -complete problems