Download presentation

Presentation is loading. Please wait.

Published byPhoenix Andrus Modified over 3 years ago

1
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011

2
Definition: A language B is NP-complete if: 1. B NP 2. Every A in NP is poly-time reducible to B (i.e. B is NP-hard) HARDEST PROBLEMS IN NP 2. A is NP-complete and A · P B If B is NP-Complete and P NP, then There is no fast algorithm for B. Theorem: A language B is NP-complete if:

3
3SAT P DSAT, NAESAT, 2CSP… We will use 3SAT to prove other problems are NP-Complete or NP-Hard. Examples include 3SAT P CLIQUE 3SAT P 0/1-ILP 3SAT P HAMPATH 3SAT P 3COLOR 3SAT P GRADUATION 3SAT P VERTEX-COVER

4
2SAT 2SAT = { | is in 2cnf and is satisfiable} Theorem. 2SAT P! Idea: a 2SAT clause (x y) is equivalent to (¬x y) and (¬y x). If there is a chain (x z 1 ) (z 1 z 2 ) … (z k ¬x) and (¬xy 1 ) (y 1 y 2 ) … (y j x) then: x ¬x If not, the formula is consistent, so satisfiable. e.g. (x x) (¬x y) (¬y ¬x)

5
def is_satisfiable_2cnf(F): V = Ø, E = Ø, G = (V,E) for l literals(F): V = V {l, ¬l} for (x y) clauses(F): E = E {(¬x,y), (¬y,x)} for x vars(F): if has_path(G,x,¬x) and has_path(G,¬x,x): return False return True (xx)(xx̅)(x̅x) x x x x x x

6
REDUCTION STRATEGIES A reduction by restriction shows that the source problem is a special case of the target problem. For example, 3SAT P CNF-SAT because every satisfiable 3CNF is also a satisfiable CNF. Example. Prove 3SAT P 4SAT by restriction. A 3CNF can be converted to an equivalent 4CNF by repeating one literal in each clause.

7
COLORING b a e c db ac d b a e c d a bd COLOR = { G,k | G is k-colorable } 3COLOR = { G | G is 3-colorable} Prove that 3COLOR P COLOR

8
HAMILTONIAN PATHS b a e c d f h i g HAMPATH = { G,s,t | G has a hamiltonian path from s to t }

9
Prove that HAMPATH P HAMCYCLE. Let HAMCYCLE = { G | G has a simple directed cycle of length n} Let HAMILTONIAN = { G | s,t such that G has a hamiltonian path from s to t } Prove that HAMPATH P HAMILTONIAN Let LPATH = { G,s,t,k | G has a simple path from s to t of length at least k } Prove that HAMPATH P LPATH

10
VERTEX COVER b a e c d b a e c d VERTEX-COVER = { G,k | G has a vertex cover of size at most k }

11
INDEPENDENT SET b a e c d b a e c d INDSET = { G,k | G has an independent set of size at least k } Prove that VERTEX-COVER P INDSET.

12
SUBSET SUM SUBSET-SUM = { y 1,…, y n,t | S {1,…,n}. Σ j S y j =t } Which of the following are in SUBSET-SUM? 1,3,5,7, 10 19,11,27,4, 13 19,11,27,4, 61 YES NO YES

13
KNAPSACK = { (w 1,v 1 )…,(w n,v n ),W, V | S {1…n} so that Σ i S w i W and Σ i S v i V} 15 lbs $500 ½ lb $15 3 lbs $2000 1lb, $20 50 ×

14
Theorem. SUBSET-SUM P KNAPSACK Proof. A subset sum instance is a knapsack where the weights are equal to the values: Let ƒ(y 1,…,y n,t) = y 1,y 1 )…(y n,y n ),t,t Then S. Σ i S y i = t iff S. Σ i S y i t and Σ i S y i t, so y 1 …y n,t SUBSET-SUM iff ƒ(y 1 …y n,t) KNAPSACK

15
Theorem. VERTEX-COVER P SET-COVER SET-COVER = { S 1,…,S n,k | i,S i U and i[1…k] so that S i[1] S i[2] … S i[k] = U } Which of the following are in SET-COVER? {1}, {1,2}, {2}, {3}, 2 {1,4}, {1,2}, {1,3}, {4}, 2 Proof. A vertex cover instance is just a set cover instance where every node is a set of edges. YES NO {1}, {2}, {1,2}, 2 YES

16
REDUCTION STRATEGIES A reduction from A to B by local replacement shows how to translate between units of A and units of B. Example. vertex cover units are vertices and edges; set cover units are elements and sets. Example. CIRCUIT-SAT units are gates, CNFSAT units are clauses, 3SAT units are 3-literal clauses.

17
SATISFYING CONSTRAINTS A 2csp is a list of constraints on pairs of variables Each constraint C(x,y) is a list of values for (x,y). An assignment satisfies a constraint if (x,y) C(x,y). An assignment satisfies a 2csp if it satisfies all constraints. e.g. Scheduling a project; seating at a wedding… 2CSP = { C | C is a satisfiable 2csp } Theorem. 2CSP is NP-Complete.

18
Proof. 1. 2CSP NP. Given an assignment to the variables we can check that all constraints are satisfied in linear time. 2. 3SAT P 2CSP. Idea: the main difference is that a 2csp constraint should have only two variables. Add variables to the 2csp that represent pairs of variables in the 3cnf, and constraints to enforce consistency with the 3cnf variables.

19
Map 3cnf ϕ with n variables and m clauses to a 2csp C ϕ with 2n+m variables and 3m+n constraints: for each variable x ϕ : add (v x,v ¬x ) {(0,1),(1,0)} for each clause (x y z) ϕ : add v xy {00,01,10,11} add (v xy,v z ) (00,0) add (v xy,v x ) {(00,0), (01,0), (10,1), (11,1)} add (v xy,v y ) {(00,0), (01,1), (10,0), (11,1)} Claim. C ϕ 2CSP ϕ 3SAT: Proof. A satisfying assignment to ϕ can be mapped to a satisfying assignment to C ϕ by assigning each v x = x and each v xy = 2v x +v y because… An assignment to C ϕ maps to an assignment to ϕ by setting each x = v x, because…

20
GRADUATION A transcript is a set of course numbers a student has taken A major consists of: Pairs: exactly one of which must be taken Lists: at least one course of which must be taken GRADUATION = { T,M | a subset of T satisfies M} For example: T = {1901A, 1902B, 1902A, 2011, 4041A, 4061, 4211} M = [1901A,1901B], [1902A,1902B] (4011,4041A,4041B), (4211,4707), (4061)

21
GRADUATION NP: The subset is a proof that (T,M) GRADUATION. 3SAT P GRADUATION: (x 1 x 2 ¬x 3 ) (¬x 1 x 2 x 2 ) (¬x 2 x 3 x 1 ) T = {101, 102, 201, 202, 301, 302} M = [101, 102], [201, 202], [301, 302] (101,201,302), (101,201,201), (101,202,301)

22
GRADUATION NP: The subset is a proof that (T,M) GRADUATION. 3SAT P GRADUATION: Let = C 1 C 2 … C m have variables x 1 …x k For each x i : add classes i01 and i02 to T. add pair (i01,i02) to M. For each C j, we add a triple to M: if x i is a literal in C j, the triple includes i01. if ¬x i is a literal in C j, the triple includes i02.

23
UHAMPATH A B CD EF No HAM PATH A B CD EF Undirected HAM PATH UHAMPATH = { G,s,t | G is an undirected graph with a Hamiltonian path from s to t}

24
HAMPATH P UHAMPATH A B CD EF A in A mid A out

25
HAMPATH P UHAMPATH A B CD EF

26
f(G,s,t) = (G,s,t) where: For each node u G: add nodes u in, u out, u mid to G. add edges {u in,u mid } and {u mid,u out } to G For each edge (u,v) G, add {u out,v in } to G s = s in, t = t out. If G,s,t HAMPATH, then G,s,t UHAMPATH: (s,u,v,..,t) (s in,s mid,s out,u in,u mid,u out,v in,v mid,v out,…t out )

27
HAMPATH P UHAMPATH If G,s,t UHAMPATH, then G,s,t HAMPATH: Let (s in =v 1,v 2,…,v 3n =t out ) be the undirected path. i=0: Induction: if v 3i = u out, then v 3i+1 =u in, so v 3i+2 =u mid. Claim: for all i0, there exists u G so that: v 3i+1 =u in, v 3i+2 =u mid, v 3i+3 =u out. The directed Hamiltonian path is (u 1, u 2, …, u n ) If v 2 s mid, then no v i =s mid. So v 2 =s mid, v 3 =s out

28
3SAT P SUBSET-SUM We transform a 3-cnf formula into y 1 …y n, t : 3SAT y 1 …y n,t SUBSET-SUM The transformation can be done in time polynomial in the length of

29
(x 1 x 2 x 2 ) (¬x 1 x 2 x 2 ) (x 1 ¬x 2 x 2 ) Each variable and each clause result in two y is. Each y i will have a digit for each clause and variable. C1C1 C2C2 C3C3 y1y1 1101 y2y2 1010 y3y3 10111 y4y4 10100 y5y5 100 y6y6 100 y7y7 10 y8y8 10 y9y9 1 y 10 1 t11333 x1x1 x2x2 x1x1 x2x2 C1C1 C2C2 C3C3

30
3SAT P SUBSET-SUM Let = C 1 C 2 … C m have k variables x 1 …x k. We output y 1 … y 2k + 2m, each a k+m-digit number. for each 1 j k: for each 1 I m: the i th digit of y 2j-1 is 1 if x j C i, else 0 the i th digit of y 2j is 1 if ¬x j C i, else 0. digit j+m of y 2j, y 2j-1 is 1. For each 1 j m: y 2k+2j = y 2k+2j-1 = 10 j-1 Output t = 11..1133..3

Similar presentations

OK

CSC401 – Analysis of Algorithms Chapter 13 NP-Completeness Objectives: Introduce the definitions of P and NP problems Introduce the definitions of NP-hard.

CSC401 – Analysis of Algorithms Chapter 13 NP-Completeness Objectives: Introduce the definitions of P and NP problems Introduce the definitions of NP-hard.

© 2018 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on load bearing structure Ppt on hydroelectric power plant Ppt on service oriented architecture tutorial Ppt on indian defence services Ppt on personality development slides Ppt on op amp circuits schematics Ppt on windows 8 features Ppt on indian parliamentary system Ppt on transformational leadership Ppt on modern methods of rainwater harvesting