1 / 33

CSC 3130: Automata theory and formal languages

Fall 2008. The Chinese University of Hong Kong. CSC 3130: Automata theory and formal languages. NP-complete problems. Andrej Bogdanov http://www.cse.cuhk.edu.hk/~andrejb/csc3130. Polynomial-time reductions.

meena
Télécharger la présentation

CSC 3130: Automata theory and formal languages

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Fall 2008 The Chinese University of Hong Kong CSC 3130: Automata theory and formal languages NP-complete problems Andrej Bogdanov http://www.cse.cuhk.edu.hk/~andrejb/csc3130

  2. Polynomial-time reductions • Language Lpolynomial-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) R (G, k) x 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} (x1∨x2 ) ∧ (x2∨x3∨x4) ∧ (x1) (x1∨x2 ) ∧ (x1) ∧ (x2) f = f = is satisfiable is not satisfiable x1 = T x2 = Fx3 = 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 • To prove it, we have to describe a reduction R: Every L∈NP reduces to SAT R w 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 q0 n = length of input w 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 • We will design a formula f such that: R w Boolean formula f f is satisfiable w ∈ L variables of f : xT, S, u assignment to xT, S, u way to fill up the tableau accepting computation tableau satisfying assignment f is satisfiable M accepts w

  10. Proof of Cook-Levin Theorem • We want to construct (in time poly(n)) a formula f : 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 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 = fcell1, 1 ∧ ... ∧ fcellp(n), p(n) where fcellT, 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 invalid window valid if d(q3, u) = (q7, a, R) … 6t3t0u0 … … 0t6t0q3 …0 … 6c3a0t0 … … 0b6a0t0…0 valid window valid window

  15. Proof of Cook-Levin Theorem • Desired meaning • Implementation: q0 b a a q3 b a b fmove: “The moves between rows follow transitions of M” c q7 b b fmove2, 2 … qacc fmove = fmove1, 1 ∧ ... ∧ fmovep(n)-3, p(n)-3 ∨ fmoveT, 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 VC SAT 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 (x1∨x2 ) ∧ (x2∨x3∨x4) ∧ (x1) (conjunctive normal form) clause literals 3CNF: CNF with ≤3 lit/clause

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

  20. Reducing SAT to 3SAT • Example: f = (x2∨(x1∧x2 ))∧(x1∧(x1∨x2 )) x4x5 x7 x7 = x4 ∧ x5 x10 T T T TT T F FT F T FT F F TF T T FF T F TF F T FF F F T AND (x4∨x5∨x7) x8 x9 (x4∨x5∨x7) OR NOT x6 x7 (x4∨x5∨x7) AND AND (x4∨x5∨x7) x4 x5 x3 NOT NOT OR (x4∨x5∨x7) ∧(x4∨x5∨x7) x2 x1 x2 x1 x1 x2 ∧(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 • Step 2: Write 3CNF fj for each gate Gj, j = {1, ..., t} • Step 3: Output R Boolean formula f 3CNF formula f’ requires thatoutput of f is true f’ = fn+1 ∧ fn+2 ∧ ... ∧ ft ∧ xn+t

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

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

  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} R 3CNF formula f (G, k) G has an independentset of size k f is satisfiable

  25. Reducing 3SAT to IS • Example: f = (x1∨x2 ) ∧ (x2∨x3∨x4) ∧ (x1) x2x3x4 x1x2 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) x2x3x4 satisfying assignment of f x1x2 TTT TTF TT IS of size 3 in G TFT x1 TF TFF T x1 = T x2 = Fx3 = T x4 = T FTT any IS of size 3 in G FF FFT G FFF satisfying assignment of f edges = inconsistencies

  27. Reducing 3SAT to IS • 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 R 3CNF formula f (G, k)

  28. Reducing 3SAT to IS • 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 R 3CNF formula f (G, k) f is satisfiable G has an IS of size k

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

  30. Reducing IS to VC • Proof: We describe a reduction from IS to VC • Example R (G, k) (G’, k’) G has an IS of size k G’ has a VC of size k’ 2 1 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} 4 3

  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 • Set G’ = G, k’ = n – k (n = number of vertices)by previous Claim. R (G, k) (G’, k’) 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 Johnsonlists 100+ NP-complete problems

More Related