meljun cortes automata theory 23

Upload: meljun-cortes-mbampa

Post on 04-Jun-2018

231 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 MELJUN CORTES Automata Theory 23

    1/33

    CSC 3130: Automata theory and formal languages

    NP-complete problems

    Fall 2008ELJUN P. CORTES MBA MPA BSCS ACS

    MELJUN CORTES

  • 8/13/2019 MELJUN CORTES Automata Theory 23

    2/33

    Polynomial-time reductions

    Language Lpolynomial-time reduces to Lif

    there exists a polynomial-time computable map R

    that takes an instance xof Linto instanceyof L

    s.t.xL if and only if yL

    L L(IS) (CLIQUE)

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

    xL yL(Ghas IS of size k) (Ghas clique of size k)

    R

  • 8/13/2019 MELJUN CORTES Automata Theory 23

    3/33

    The Cook-Levin Theorem

    Every LNPreduces to SAT

    SAT= {f:f is a satisfiable Boolean formula}

    (x1x2) (x2x3x4) (x1)f=

    is satisfiable

    x1 = T x2 = Fx3 = T x4 = T

    (x1x2) (x1) (x2)f=

    is not satisfiable

  • 8/13/2019 MELJUN CORTES Automata Theory 23

    4/33

    NP-hardness

    Language Lis NP-hard if every LinNPreducesto L

    Intuitively, NP-hard means harder than all of NP

    The Cook-Levin Theorem says

    SATis

    NP-hard

    P

    SAT

    NP

  • 8/13/2019 MELJUN CORTES Automata Theory 23

    5/33

    NP-complete

    Lis NP-completeif Lis NP-hard and LNP

    Intuitively, NP-complete means hardest in NP

    Recall that SAT NP, so SATis NP-complete

    If SATP, then P = NP

    P

    SAT

    NP

  • 8/13/2019 MELJUN CORTES Automata Theory 23

    6/33

    Proof of Cook-Levin Theorem

    To prove it, we have to describe a reduction R:

    Every LNPreduces to SAT

    w Boolean formulaf

    wL fis satisfiable

    R

  • 8/13/2019 MELJUN CORTES Automata Theory 23

    7/33

    Proof of Cook-Levin Theorem

    All we know about L: It has a poly-time NTMM Lets look at computation tableauofMon input w

    M w w1 w2q0

    qacc

    S-th configuration

    symbol at time T

    S

    T

    SinceMis nondeterministic,there may be many possible

    tableaus

  • 8/13/2019 MELJUN CORTES Automata Theory 23

    8/33

    Proof of Cook-Levin Theorem

    w1 w2q0

    qacc

    S

    T

    n= length of input w

    heightof tableau isp(n)

    for some polynomialp

    widthis at mostp(n)

    k possible tableau symbols

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

    tableau contains u

    if notfalse,

    u

    1 Sp(n)

    1 Tp(n)

    1 u k

  • 8/13/2019 MELJUN CORTES Automata Theory 23

    9/33

    Proof of Cook-Levin Theorem

    We will design a formulafsuch that:

    w Boolean formulaf

    wL fis satisfiable

    R

    variables off :

    assignment to xT, S, u

    way to fill up the tableau

    satisfying assignment accepting computation tableau

    fis satisfiable

    xT, S, u

    Maccepts w

  • 8/13/2019 MELJUN CORTES Automata Theory 23

    10/33

    Proof of Cook-Levin Theorem

    We want to construct (in time poly(n)) a formulaf:

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

    tableau contains u

    if notfalse,

    1 Sp(n)1 Tp(n)

    1 u k

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

    true, if the xs represent a valid

    accepting tableau

    if notfalse,

  • 8/13/2019 MELJUN CORTES Automata Theory 23

    11/33

    Proof of Cook-Levin Theorem

    w1 w2q0

    qacc

    S

    T

    u

    f=fcellf0fmovefacc

    fcell: Every cell contains

    exactly one symbol

    The first row isq0w1w2...wk...

    f0:

    fmove: The moves between rowsfollow the transitions ofM

    facc: qaccappears somewhere in the last row

  • 8/13/2019 MELJUN CORTES Automata Theory 23

    12/33

    Proof of Cook-Levin Theorem

    Desired meaning

    Implementation:

    fcell: Every cell contains exactly one symbol

    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 of xS, T, 1... xS, T, k is true

  • 8/13/2019 MELJUN CORTES Automata Theory 23

    13/33

    Proof of Cook-Levin Theorem

    Desired meaning

    Implementation:

    f0: The first row is q0w1w2...wk...

    facc: qaccappears 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

  • 8/13/2019 MELJUN CORTES Automata Theory 23

    14/33

    Valid and invalid windows

    6c3a0t0

    0c6a0p00

    6t3t0u0 0t6t0u00

    valid window

    invalid window

    6t3t0u0

    0t6t0q3 0

    valid window

    6t3q3u0

    0t6a0q7 0

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

    6q3t0u0 0k6t0q0 0

    invalid window

    6c3a0t0

    0b6a0t00

    valid window

  • 8/13/2019 MELJUN CORTES Automata Theory 23

    15/33

    Proof of Cook-Levin Theorem

    Desired meaning

    Implementation:

    fmove: The moves between rowsfollow transitions ofM

    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, a1xT, S+1, a2xT, S+2, a3xT+1, S, a4xT+1, S+1, a5xT+2, S+1, a6)

    valid windows

    a1 a2 a3

    a4 a5 a6

  • 8/13/2019 MELJUN CORTES Automata Theory 23

    16/33

    Other NP-complete problems

    CLIQUE= {(G, k): Gis a graph with a clique of

    kvertices

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

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

    CLIQUE, ISand VC are NP-complete

    SAT

    NP

    CLIQUE IS VC

  • 8/13/2019 MELJUN CORTES Automata Theory 23

    17/33

    Proving NP-hardness

    To show Lis NP-hard, it is enough to reducefrom some Lwe already know is NP-hard

    For now we can take L= SAT

    To show Lis NP-complete,we also need to argue thatLis in NP

    This is usually the easy part

    roadmap:

    SAT

    3SAT

    IS

    CLIQUE VC

  • 8/13/2019 MELJUN CORTES Automata Theory 23

    18/33

    3SAT

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

    conjunctive normal form withat most 3 distinct literals per clause}

    CNF: AND of ORs of literals

    literal: xior xi

    (conjunctive normal form)

    3CNF: CNF with 3 lit/clause

    (x1x2) (x2x3x4) (x1)clauseliterals

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

    gates

  • 8/13/2019 MELJUN CORTES Automata Theory 23

    19/33

    NP-hardness of 3SAT

    Theorem

    Proof:We describe a reduction Rfrom SAT

    Boolean formulaf 3CNF formulaf

    f is satisfiable

    R

    fis satisfiable

    3SATis NP-hard

  • 8/13/2019 MELJUN CORTES Automata Theory 23

    20/33

    Reducing SATto 3SAT

    Example:f=(x2(x1

    x2))

    (x1

    (x1

    x2))

    We give extra variables to every gate (wire)

    x3

    x6 x7

    x8 x9

    x4 x5

    x10

    AND

    OR NOT

    AND

    NOT OR

    AND

    NOT

    x2 x1 x2 x1 x1x2

    x7= x4x5x4x5 x7T 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)

  • 8/13/2019 MELJUN CORTES Automata Theory 23

    21/33

    Reducing SATto 3SAT

    Step 1: Add variable xn+jfor each gate Gjinf

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

    Step 3: Output

    Boolean formulaf 3CNF formulaf R

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

    requires thatoutput offis true

  • 8/13/2019 MELJUN CORTES Automata Theory 23

    22/33

    Reducing SATto 3SAT

    Every satisfying assignment off extends uniquely

    to a satisfying assignment off

    Conversely, every satisfying assignment off

    must contain a satisfying assignment off

    Boolean formulaf 3CNF formulaf R

    f is satisfiablefis satisfiable

  • 8/13/2019 MELJUN CORTES Automata Theory 23

    23/33

    Independent set

    Theorem

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

    1 2

    3 4

    An independent setis

    a subset of vertices so

    that no pair is

    connected{1, 2}, {1, 3}, {4} are

    independent sets

    ISis NP-hard

    SAT

    3SAT

    IS

    CLIQUE VC

  • 8/13/2019 MELJUN CORTES Automata Theory 23

    24/33

    Reducing 3SATto IS

    Proof: We describe a reduction from 3SATto IS

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

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

    3CNF formulaf (G,k)

    Ghas an independentset of size k

    R

    fis satisfiable

  • 8/13/2019 MELJUN CORTES Automata Theory 23

    25/33

    Reducing 3SATto IS

    Example:f=(x1x2)

    (x2

    x3

    x4)

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

  • 8/13/2019 MELJUN CORTES Automata Theory 23

    26/33

    Reducing 3SATto IS

    Example:f=(x1x2)

    (x2

    x3

    x4)

    (x1)

    TT

    TF

    FF

    TTT

    TTF

    TFT

    TFF

    FTT

    FFTFFF

    T

    x2x3x4x1x2

    x1

    G

    satisfying assignment off

    IS of size 3 in G

    x1 = T x2 = Fx3 = T x4 = T

    edges = inconsistencies

    any IS of size 3 in G

    satisfying assignment off

  • 8/13/2019 MELJUN CORTES Automata Theory 23

    27/33

    Reducing 3SATto IS

    Ghas a vertexfor every clause Cioffand everysatisfying assignment of Ci

    G has an edgebetween any two vertices that

    represent inconsistent assignments

    kis the number of clauses inf

    3CNF formulaf (G,k)R

  • 8/13/2019 MELJUN CORTES Automata Theory 23

    28/33

    Reducing 3SATto IS

    Every satisfying assignment offgives an

    independent set of size kin G

    Conversely, from every IS of size kin Gwe can

    extract a consistent and satisfying assignmentoff

    3CNF formulaf (G,k)

    Ghas an IS of size k

    R

    fis satisfiable

  • 8/13/2019 MELJUN CORTES Automata Theory 23

    29/33

    Vertex cover

    SAT

    3SAT

    IS

    CLIQUE VC

    Theorem

    VCis 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

    1 2

    3 4

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

  • 8/13/2019 MELJUN CORTES Automata Theory 23

    30/33

    Reducing IStoVC

    Proof: We describe a reduction from IStoVC

    Example

    (G,k)

    Ghas a VC of size k

    R(G,k)

    Ghas 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

  • 8/13/2019 MELJUN CORTES Automata Theory 23

    31/33

    Reducing IStoVC

    Claim

    Proof

    Sis an independent set of Gif and only

    ifSis a vertex cover of G

    Sis an independent set of G

    no edge has both endpoints in S

    every edge has an endpoint in S

    Sis a vertex cover of G

  • 8/13/2019 MELJUN CORTES Automata Theory 23

    32/33

    Reducing IStoVC

    Set G = G, k= nk(n= number of vertices)

    by previous Claim.

    (G,k)R(G,k)

    Ghas a VC of size kGhas an IS of size k

  • 8/13/2019 MELJUN CORTES Automata Theory 23

    33/33

    The ubiquity of NP-complete problems

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

    A surprising fact of life is that most CS problems

    are either in Por NP-complete

    A 1979 book by Garey and Johnson

    lists 100+ NP-complete problems