Presentation is loading. Please wait.

Presentation is loading. Please wait.

NP-complete problems The Chinese University of Hong Kong Fall 2008

Similar presentations


Presentation on theme: "NP-complete problems The Chinese University of Hong Kong Fall 2008"— Presentation transcript:

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

2 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’ L (IS) L’ (CLIQUE) x (G, k) R y (G’, k’) x ∈ L y ∈ L’ (G has IS of size k) (G’ has clique of size k’)

3 The Cook-Levin Theorem
Every L ∈ NP reduces to SAT SAT = {f: f is a satisfiable Boolean formula} f = (x1∨x2 ) ∧ (x2 ∨x3 ∨x4) ∧ (x1) f = (x1∨x2 ) ∧ (x1) ∧ (x2) is satisfiable is not satisfiable x1 = T x2 = F x3 = T x4 = T

4 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 NP SAT is NP-hard P

5 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 SAT NP If SAT ∈ P, then P = NP P

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

7 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 S w M q0 w1 w2 S-th configuration symbol at time T T Since M is nondeterministic, there may be many possible tableaus qacc

8 Proof of Cook-Levin Theorem
S n = length of input w q0 w1 w2 height of tableau is p(n) for some polynomial p T u width is at most p(n) k possible tableau symbols qacc true, if the (T, S) cell of tableau contains u 1 ≤ S ≤ p(n) xT, S, u = 1 ≤ T ≤ p(n) false, if not 1 ≤ u ≤ k

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

10 Proof of Cook-Levin Theorem
true, if the (T, S) cell of tableau contains u 1 ≤ S ≤ p(n) xT, S, u = 1 ≤ T ≤ p(n) false, if not 1 ≤ u ≤ k We want to construct (in time poly(n)) a formula f : true, if the xs represent a valid accepting tableau f(x1, 1, 1, ..., xp(n), p(n), k) = false, if not

11 Proof of Cook-Levin Theorem
S f = fcell ∧ f0 ∧ fmove ∧ facc q0 w1 w2 T fcell: “Every cell contains exactly one symbol” u f0: “The first row is q0w1w2...wk☐...☐” qacc fmove: “The moves between rows follow the transitions of M” facc: “qacc appears somewhere in the last row”

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

13 Proof of Cook-Levin Theorem
Desired meaning Implementation: f0: “The first row is q0w1w2...wk☐...☐” facc: “qacc appears somewhere in the last row” f0 = x1, 1, q0 ∧ x1, 1, w1 ∧ x1, 1, w2 ∧ ... ∧ x1, p(n),☐ facc = xp(n), 1, qacc ∨ xp(n), 2, qacc ∨ ... ∨ xp(n), p(n), qacc

14 Valid and invalid windows
… 6q3t0u0 … … 0k6t0q0 …0 … 6t3t0u0 … … 0t6t0u0 …0 invalid window valid window … 6c3a0t0 … … 0c6a0p0 …0 … 6t3q3u0 … … 0t6a0q7 …0 valid if d(q3, u) = (q7, a, R) invalid window … 6t3t0u0 … … 0t6t0q3 …0 … 6c3a0t0 … … 0b6a0t0 …0 valid window valid window

15 Proof of Cook-Levin Theorem
Desired meaning Implementation: q0 a a b b q3 a b fmove: “The moves between rows follow transitions of M” b c q7 b fmove 2, 2 qacc fmove = fmove 1, 1 ∧ ... ∧ fmove p(n)-3, p(n)-3 fmove T, S = (xT, S, a1 ∧ xT, S+1, a2 ∧ xT, S+2, a3 ∧ xT+1, S, a4 ∧ xT+1, S+1, a5 ∧ xT+2, S+1, a6) over all valid windows a1 a2 a3 a4 a5 a6

16 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 CLIQUE IS SAT VC NP

17 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: CLIQUE VC IS 3SAT SAT

18 3SAT SAT = {f: f is a satisfiable Boolean formula}
3SAT = {f: f is a satisfiable Boolean formula in conjunctive normal form with at most 3 distinct literals per clause} (x2∨(x1∧x2 ))∧(x1∧(x1∨x2 )) literal: xi or xi gates CNF: AND of ORs of literals (conjunctive normal form) (x1∨x2 ) ∧ (x2 ∨x3 ∨x4) ∧ (x1) literals clause 3CNF: CNF with ≤3 lit/clause

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

20 Reducing SAT to 3SAT Example: f = (x2∨(x1∧x2 ))∧(x1∧(x1∨x2 )) x4 x5 x7
AND OR NOT x2 x1 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) We give extra variables to every gate (“wire”)

21 Reducing SAT to 3SAT Step 1: Add variable xn+j for each gate Gj in f
Boolean formula f R 3CNF formula f’ Step 1: Add variable xn+j for each gate Gj in f Step 2: Write 3CNF fj for each gate Gj, j = {1, ..., t} Step 3: Output requires that output of f is true f’ = fn+1 ∧ fn+2 ∧ ... ∧ ft ∧ xn+t

22 Reducing SAT to 3SAT Boolean formula f R 3CNF formula f’ f’ is satisfiable f is satisfiable 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

23 Independent set Theorem IS is NP-hard
IS = {(G, k): G is a graph with an independent set of k vertices} Theorem IS is NP-hard CLIQUE VC An independent set is a subset of vertices so that no pair is connected 1 2 IS 3SAT {1, 2}, {1, 3}, {4} are independent sets SAT 3 4

24 Reducing 3SAT to IS Proof: We describe a reduction from 3SAT to IS
3SAT = {f: f is a satisfiable Boolean formula in 3CNF} IS = {(G, k): G is a graph with an independent set of k vertices} 3CNF formula f R (G, k) G has an independent set of size k f is satisfiable

25 Reducing 3SAT to IS Example: f = (x1∨x2 ) ∧ (x2 ∨x3 ∨x4) ∧ (x1) etc.
TTT all interconnected TTF TT x1 TFT T TF TFF FTT F FT etc. FTF FF FFT FFF Put an edge for every inconsistency

26 Reducing 3SAT to IS Example: f = (x1∨x2 ) ∧ (x2 ∨x3 ∨x4) ∧ (x1)
satisfying assignment of f IS of size 3 in G x1x2 TTT TTF TT TFT x1 TF TFF T x1 = T x2 = F x3 = T x4 = T FTT any IS of size 3 in G satisfying assignment of f FF FFT G FFF edges = inconsistencies

27 Reducing 3SAT to IS 3CNF formula f R (G, k) G has a vertex for every clause Ci of f and every satisfying assignment of Ci G has an edge between any two vertices that represent inconsistent assignments k is the number of clauses in f

28 Reducing 3SAT to IS 3CNF formula f R (G, k) f is satisfiable G has an IS of size k Every satisfying assignment of f gives an independent set of size k in G Conversely, from every IS of size k in G we can “extract” a consistent and satisfying assignment of f

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

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

31 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

32 Reducing IS to VC R (G, k) (G’, k’) Set G’ = G, k’ = n – k (n = number of vertices) by previous Claim. G has an IS of size k G’ has a VC of size k’

33 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


Download ppt "NP-complete problems The Chinese University of Hong Kong Fall 2008"

Similar presentations


Ads by Google