meljun cortes -- automata theory lecture - 23

Upload: meljun-cortes-mbampa

Post on 04-Apr-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/31/2019 MELJUN CORTES -- AUTOMATA THEORY LECTURE - 23

    1/33

    CSC 3130: Automata theory and formal languages

    Andrej Bogdanov

    http://www.cse.cuhk.edu.hk/~andrejb/csc3130

    NP-complete problems

    Fall 2008

  • 7/31/2019 MELJUN CORTES -- AUTOMATA THEORY LECTURE - 23

    2/33

    Polynomial-time reductions

    Language Lpolynomial-time reduces to Lif

    there exists a polynomial-time computable

    map R that takes an instancexofL intoinstanceyofLs.t.

    x L if and only if y L

    L L(IS) (CLIQUE)

    x y(G, k) (G, k)

    x L y L(G has IS of size k) (Ghas clique of size k)

    R

  • 7/31/2019 MELJUN CORTES -- AUTOMATA THEORY LECTURE - 23

    3/33

    The Cook-Levin Theorem

    Every L NP reduces to SAT

    SAT= {f: fis a satisfiable Boolean formula}

    (x1x2 ) (x2x3x4) (x1)f=

    is satisfiable

    x1 = Tx2 = Fx3 = Tx4 = T

    (x1x2 ) (x1) (x2)f=

    is not satisfiable

  • 7/31/2019 MELJUN CORTES -- AUTOMATA THEORY LECTURE - 23

    4/33

    NP-hardness

    Language L is NP-hard if every Lin NPreduces to L

    Intuitively, NP-hard means harder than allof NP

    The Cook-Levin Theorem says

    SAT is NP-hard

    P

    SAT

    NP

  • 7/31/2019 MELJUN CORTES -- AUTOMATA THEORY LECTURE - 23

    5/33

    NP-complete

    L is NP-complete ifL is NP-hard and L NP

    Intuitively, NP-complete means hardest inNP

    Recall that SAT NP, so SAT is NP-complete

    If SAT P, then P = NP

    P

    SAT

    NP

  • 7/31/2019 MELJUN CORTES -- AUTOMATA THEORY LECTURE - 23

    6/33

    Proof of Cook-Levin Theorem

    To prove it, we have to describe areduction R:

    Every L NP reduces to SAT

    w Boolean formula f

    w L fis satisfiable

    R

  • 7/31/2019 MELJUN CORTES -- AUTOMATA THEORY LECTURE - 23

    7/33

    Proof of Cook-Levin Theorem

    All we know about L: It has a poly-time NTMM

    Lets look at computation tableau ofM on inputw

    M w w1 w2q0

    qacc

    S-th configurationsymbol at time T

    S

    T

    Since M is nondeterministic,there may be many possibletableaus

  • 7/31/2019 MELJUN CORTES -- AUTOMATA THEORY LECTURE - 23

    8/33

    Proof of Cook-Levin Theorem

    w1 w2q0

    qacc

    S

    T

    n = length of input w

    height of tableau is p(n) for some polynomialp

    width is at most p(n)

    kpossible tableau symbols

    xT, S, u =true,if the (T, S) cell of

    tableau contains u

    if notfalse,

    u

    1 S p(n)

    1 Tp(n)

    1 u k

  • 7/31/2019 MELJUN CORTES -- AUTOMATA THEORY LECTURE - 23

    9/33

    Proof of Cook-Levin Theorem

    We will design a formula fsuch that:

    w Boolean formula f

    w L fis satisfiable

    R

    variables off:

    assignment toxT, S, u

    way to fill up the tableau

    satisfying assignment accepting computation tableau

    fis satisfiable

    xT, S, u

    M accepts w

  • 7/31/2019 MELJUN CORTES -- AUTOMATA THEORY LECTURE - 23

    10/33

    Proof of Cook-Levin Theorem

    We want to construct (in time poly(n)) aformula f:

    xT, S, u =true,if the (T, S) cell of

    tableau contains u

    if notfalse,

    1 S p(n)1 Tp(n)

    1 u k

    f(x1, 1, 1, ...,xp(n),p(n), k) =

    true,if thexs represent a validaccepting tableau

    if notfalse,

  • 7/31/2019 MELJUN CORTES -- AUTOMATA THEORY LECTURE - 23

    11/33

    Proof of Cook-Levin Theorem

    w1 w2q0

    qacc

    S

    T

    u

    f= fcell f0 fmove facc

    fcell:Every cell contains

    exactly one symbol

    The first row isq0w1w2...wk...

    f0:

    fmove:The moves between rowsfollow the transitions ofM

    facc: qacc appears somewhere in the last

    row

  • 7/31/2019 MELJUN CORTES -- AUTOMATA THEORY LECTURE - 23

    12/33

    Proof of Cook-Levin Theorem

    Desired meaning

    Implementation:

    fcell: Every cell contains exactly onesymbol

    fcell = fcell1, 1 ... fcellp(n),p(n)where

    fcellT, S = (xT, S, 1 ... xT, S, k)

    (xT, S, 1xT, S, 2)

    (xT, S, 1xT, S, 3)

    ...( xT, S, k-1xT, S, k)

    at least one symbol

    no two symbols

    or: Exactly one ofxS, T, 1 ... xS, T, kis true

  • 7/31/2019 MELJUN CORTES -- AUTOMATA THEORY LECTURE - 23

    13/33

    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, q0x1, 1, w1x1, 1, w2 ... x1,p(n),

    facc =xp(n), 1, qaccxp(n), 2, qacc ... xp(n),p(n), qacc

  • 7/31/2019 MELJUN CORTES -- AUTOMATA THEORY LECTURE - 23

    14/33

    Valid and invalid windows

    6c3a0t0

    0c6a0p0

    0

    6t3t0u0

    0t6t0u0

    0

    valid window

    invalid window

    6t3t0u0

    0t6t0q3

    0

    valid window

    6t3q3u0

    0t6a0q7

    0

    valid if(q3, u) = (q7, a, R)

    6q3t0u0

    0k6t0q0

    0

    invalid window

    6c3a0t0

    0b6a0t0

    0

    valid window

  • 7/31/2019 MELJUN CORTES -- AUTOMATA THEORY LECTURE - 23

    15/33

    Proof of Cook-Levin Theorem

    Desired meaning

    Implementation:

    fmove:The moves betweenrowsfollow transitions of

    M

    a aq0

    qacc

    fmove = fmove1, 1 ... fmovep(n)-3,p(n)-3

    b

    q3b a b

    b q7c b

    fmove2, 2

    fmoveT, S =over all

    (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)

    valid windows

    a1a2a3a4a5a6

  • 7/31/2019 MELJUN CORTES -- AUTOMATA THEORY LECTURE - 23

    16/33

    Other NP-complete problems

    CLIQUE = {(G, k): G is a graph with a clique ofkvertices}IS = {(G, k): G is a graph with an independent set ofkvertices}

    VC = {(G, k): G is a graph with a vertex cover ofkvertices}

    CLIQUE, IS and VC are NP-complete

    SAT

    NP

    CLIQUE IS VC

  • 7/31/2019 MELJUN CORTES -- AUTOMATA THEORY LECTURE - 23

    17/33

    Proving NP-hardness

    To show L is NP-hard, it is enough toreduce from some Lwe already know isNP-hard

    For now we can take L= SAT

    To show L is NP-complete,we also need to argue that

    L is in NPThis is usually the easy part

    roadmap:

    SAT

    3SAT

    IS

    CLIQUE VC

  • 7/31/2019 MELJUN CORTES -- AUTOMATA THEORY LECTURE - 23

    18/33

    3SAT

    SAT= {f: fis a satisfiable Boolean formula}3SAT= {f: fis a satisfiable Boolean formula in

    conjunctive normal form withat most 3 distinct literals per clause}

    CNF: AND of ORs of literals

    literal:xi orxi

    (conjunctive normal form)

    3CNF: CNF with 3 lit/clause

    (x1x2 ) (x2x3x4) (x1)clauseliterals

    (x2(x1x2 ))(x1(x1x2 ))gates

  • 7/31/2019 MELJUN CORTES -- AUTOMATA THEORY LECTURE - 23

    19/33

    NP-hardness of 3SAT

    Theorem

    Proof: We describe a reduction R from SAT

    Boolean formula f 3CNF formula f

    fis satisfiable

    R

    fis satisfiable

    3SAT is NP-hard

  • 7/31/2019 MELJUN CORTES -- AUTOMATA THEORY LECTURE - 23

    20/33

    Reducing SAT to 3SAT

    Example: f=(x2(x1x2 ))(x1(x1x2 ))

    e give extra variables to every gate (wire)

    x3

    x6 x7

    x8 x9

    x4 x5

    x10AND

    OR NOT

    AND

    NOT OR

    AND

    NOT

    x2 x1 x2 x1 x1x2

    x7 =x4x5x4x5x7T 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

    (x4x5x7)(x4x5x7)

    (x4x5x7)

    (x4x5x7)

    (x4x5x7)(x4x5x7)(x4x5x7)(x4x5x7)

  • 7/31/2019 MELJUN CORTES -- AUTOMATA THEORY LECTURE - 23

    21/33

    Reducing SAT to 3SAT

    Step 1: Add variablexn+j for each gate Gj inf

    Step 2: Write 3CNF fj for each gate Gj,j ={1, ..., t}

    Step 3: Output

    Boolean formula f 3CNF formula fR

    f= fn+1 fn+2 ... ftxn+t

    requires thatoutput offis true

  • 7/31/2019 MELJUN CORTES -- AUTOMATA THEORY LECTURE - 23

    22/33

    Reducing SAT to 3SAT

    Every satisfying assignment offextendsuniquely to a satisfying assignment off

    Conversely, every satisfying assignment offmust contain a satisfying assignment off

    Boolean formula f 3CNF formula fR

    fis satisfiablefis satisfiable

  • 7/31/2019 MELJUN CORTES -- AUTOMATA THEORY LECTURE - 23

    23/33

    Independent set

    Theorem

    IS = {(G, k): G is a graph with an independentset ofkvertices}

    1 2

    3 4

    An independent setis a subset ofvertices so that nopair is connected

    {1, 2}, {1, 3}, {4} areindependent sets

    IS is NP-hard

    SAT

    3SAT

    IS

    CLIQUE VC

  • 7/31/2019 MELJUN CORTES -- AUTOMATA THEORY LECTURE - 23

    24/33

    Reducing 3SAT to IS

    Proof: We describe a reduction from 3SATto IS

    3SAT= {f: fis a satisfiable Boolean formula in 3CNF}

    IS = {(G, k): G is a graph with an independent set ofkvertices}

    3CNF formula f (G, k)

    G has an independentset of size k

    R

    fis satisfiable

  • 7/31/2019 MELJUN CORTES -- AUTOMATA THEORY LECTURE - 23

    25/33

    Reducing 3SAT to IS

    Example: f=(x1x2 ) (x2x3x4) (x1)

    TT

    TF

    FT

    FF

    TTT

    TTF

    TFT

    TFF

    FTT

    FTF

    FFTFFF

    T

    F

    Put an edge for every inconsistency

    all interconnected

    x2x3x4x1x2

    x1

    etc.

  • 7/31/2019 MELJUN CORTES -- AUTOMATA THEORY LECTURE - 23

    26/33

    Reducing 3SAT to IS

    Example: f=(x1x2 ) (x2x3x4) (x1)

    TT

    TF

    FF

    TTT

    TTF

    TFT

    TFF

    FTT

    FFTFFF

    T

    x2x3x4x1x2

    x1

    G

    satisfying assignment off

    IS of size 3 in G

    x1 = Tx2 = Fx3 = Tx4 = T

    edges = inconsistencies

    any IS of size 3 in G

    satisfying assignment off

  • 7/31/2019 MELJUN CORTES -- AUTOMATA THEORY LECTURE - 23

    27/33

    Reducing 3SAT to IS

    G has a vertex for every clause Ci offandevery satisfying assignment ofCi

    G has an edge between any two verticesthat represent inconsistent assignments

    kis the number of clauses in f

    3CNF formula f (G, k)R

  • 7/31/2019 MELJUN CORTES -- AUTOMATA THEORY LECTURE - 23

    28/33

    Reducing 3SAT to IS

    Every satisfying assignment offgives anindependent set of size kin G

    Conversely, from every IS of size kin G wecan extract a consistent and satisfyingassignment off

    3CNF formula f (G, k)

    G has an IS of size k

    R

    fis satisfiable

  • 7/31/2019 MELJUN CORTES -- AUTOMATA THEORY LECTURE - 23

    29/33

    Vertex cover

    SAT

    3SAT

    IS

    CLIQUE VC

    Theorem

    VC is NP-hard

    A vertex cover is aset of vertices thattouches (covers) alledges

    {2, 4}, {3, 4}, {1, 2, 3}are vertex covers

    1 2

    3 4

    VC = {(G, k): G is a graph with a vertex cover of size k}

  • 7/31/2019 MELJUN CORTES -- AUTOMATA THEORY LECTURE - 23

    30/33

    Reducing IS to VC

    Proof: We describe a reduction from IS toVC

    Example

    (G, k)

    Ghas a VC of size k

    R(G, k)

    G has an IS of size k

    1 2

    3 4

    , {1}, {2}, {3},{4},{1, 3}, {2, 3}

    {2, 4}, {3, 4},{1, 2, 3}, {1, 2,4},{1, 3, 4}, {2, 3,4},

    {1, 2, 3, 4}

    independent setsvertex covers

  • 7/31/2019 MELJUN CORTES -- AUTOMATA THEORY LECTURE - 23

    31/33

    Reducing IS to VC

    Claim

    Proof

    S is an independent set ofG if andonly ifS is a vertex cover ofG

    S is an independent set ofG

    no edge has both endpoints in S

    every edge has an endpoint in S

    S is a vertex cover ofG

  • 7/31/2019 MELJUN CORTES -- AUTOMATA THEORY LECTURE - 23

    32/33

    Reducing IS to VC

    Set G = G, k= n k(n = number of

    vertices)

    by previous Claim.

    (G, k)R(G, k)

    Ghas a VC of size kG has an IS of size k

    The ubiquity of NP complete

  • 7/31/2019 MELJUN CORTES -- AUTOMATA THEORY LECTURE - 23

    33/33

    The ubiquity of NP-completeproblems

    We saw a few examples of NP-completeproblems, but there are many more

    A surprising fact of life is that most CSproblems are either in P or NP-complete

    A 1979 book by Garey and Johnson

    lists 100+ NP-complete problems