Presentation is loading. Please wait.

Presentation is loading. Please wait.

INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.

Similar presentations


Presentation on theme: "INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011."— Presentation transcript:

1 INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011

2 QUIZ 5 The language L ∈ TIME(t(n)) if: L can be decided by a TM in time O(t(n)) The language L ∈ NP if: L can be decided by a NTM in time O(n c ) L has a polynomial time verifier SAT is the language: { ϕ | ϕ is a satisfiable boolean formula}

3 QUIZ 5 Give a satisfying assignment to x 1 = 0, x 2 = 0 Asymptotic upper bounds for: (a) 14n 1.7 + 2n (ln n) 1/2 = O(n 1.7 ) (b) 4 (log ₂ n)/3 + 6n(n/3) 1/2 = O(n 3/2 )

4

5 TIME COMPLEXITY Definition: Let M be a TM that halts on all inputs. The running time or time-complexity of M is the function f : N  N, where f(n) is the maximum number of steps that M uses on any input of length n. Definition: TIME(t(n)) = { L | L is a language decided by a O(t(n)) time Turing Machine }

6 P = TIME(n c )  c  N IMPORTANT COMPLEXITY CLASSES Problems in P can be efficiently solved. Problems in NP can be efficiently verified. NP = NTIME(n c )  c  N L ∈ P iff there is an n c -time TM that decides L. L ∈ NP iff there is an n c -time NTM that decides L iff there is an n c -time “verifier” for L

7 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 Theorem: if B is NP-Complete and B ∈ P, then NP=P. Corollary: if B is NP-Complete and P  NP, then there is no fast algorithm for B. Theorem: if A is NP-Hard and A ≤ P B, then B is NP-Hard.

8 P NP B C HARDEST PROBLEMS IN NP

9 Theorem (Cook-Levin): 3SAT is NP-complete Proof: (1) 3SAT  NP (2) Every language A in NP is polynomial time reducible to 3SAT Our proof of (2) has three steps. (a) CIRCUIT-SAT is NP-Hard (b) CIRCUIT-SAT ≤ P CNF-SAT (c) CNF-SAT ≤ P 3SAT Corollary: 3SAT  P if and only if P = NP

10 A CIRCUIT … is a collection of (boolean) gates and inputs connected by wires. ⋁ ∧ ¬ ∧ x0x0 x1x1 x2x2 … is satisfiable if some setting of inputs makes it output 1. … has arbitrary fan-in and fan-out CIRCUIT-SAT = { 〈 C 〉 | C is a satisfiable circuit } ∧

11 Given TM M and time bound t, we create a circuit that takes n input bits and runs up to t steps of M. The circuit will have t “rows”, where the i th row represents the configuration of M after i steps: q00q0010101 0q11q110101 0q10q10101 0q01q0101 01q00q001 010q11q11 010q1q1 010qaqa t t a “tableau”

12 q0q0 EXAMPLE q0q0 q1q1 qaqa 0 → 0, R 0 → □, R 1 → 1, R 1 → □, R □ → □, L q1q1 qaqa 01  q0q0 q1q1 qaqa 01  q0q0 q1q1 qaqa 01  q0q0 q1q1 qaqa 01  q0q0 ∧ ∧ ⋁ q1q1 ∧ ∧ ⋁ ∧ ⋁ qaqa 0 ∧ ⋁ ⋁ ∙ ∧ 1 ∧ ⋁ ⋁ ∙ ∧  ∧ ⋁ ⋁ ∙ ∧ ∧ ∧

13 CNF-SAT = {  |  is a satisfiable CNF formula } Theorem. CIRCUIT-SAT ≤ P CNF-SAT. Proof. Given a circuit C, we will output a CNF formula  that is satisfiable iff C is. x1x1 x2x2 ∧⋁ ∧⋁ ⋁ (x 1 ∧ x 2 ) (x 1 ⋁ x 2 ) ((x 1 ∧ x 2 ) ⋁ (x 1 ⋁ x 2 )) ((x 1 ∧ x 2 ) ∧ (x 1 ⋁ x 2 )) ((x 1 ∧ x 2 ) ⋁ (x 1 ⋁ x 2 )) ⋁ ((x 1 ∧ x 2 ) ∧ (x 1 ⋁ x 2 ))

14 x1x1 x2x2 ∧⋁ ∧⋁ ⋁ For every gate in the circuit C, we introduce a new variable g i and force g i to satisfy the gate. g 1 = (x 1 ∧ x 2 ) g 2 = (x 1 ⋁ x 2 ) g 3 = (g 1 ∧ g 2 ) g 4 = (g 1 ⋁ g 2 ) g 5 = (g 3 ⋁ g 4 ) g 1 → (x 1 ∧ x 2 ) (x 1 ∧ x 2 ) → g 1 g 2 → (x 1 ⋁ x 2 ) (x 1 ⋁ x 2 ) → g 2 g 3 → (g 1 ∧ g 2 ) (g 1 ∧ g 2 ) → g 3 g 4 → (g 1 ⋁ g 2 ) (g 1 ⋁ g 2 ) → g 4 g 5 → (g 3 ⋁ g 4 ) (g 3 ⋁ g 4 ) → g 5 g5g5

15 We can convert to CNF using the fact that (p → q) is equivalent to (¬p ⋁ q) so: g → ( ℓ 1 ⋁ ℓ 2 … ⋁ ℓ n ) ≡ (¬g ⋁ ℓ 1 ⋁ ℓ 2 … ⋁ ℓ n ) ( ℓ 1 ∧ ℓ 2 … ∧ ℓ n ) → g ≡ (¬ ℓ 1 ⋁ ¬ ℓ 2 … ⋁ ¬ ℓ n ⋁ g) g → ( ℓ 1 ∧ ℓ 2 … ∧ ℓ n ) ≡ (¬g ⋁ ℓ 1 ) ∧ (¬g ⋁ ℓ 2 ) … ∧ (¬g ⋁ ℓ n ) ( ℓ 1 ⋁ ℓ 2 … ⋁ ℓ n ) → g ≡ (¬ ℓ 1 ⋁ g) ∧ (¬ ℓ 2 ⋁ g) … ∧ (¬ ℓ n ⋁ g) The final output  is the CNF with all the clauses produced from gates in this way, plus the clause (g i ), where g i corresponds to C’s output gate.

16 If C has k inputs, m gates, n wires, how long is  ? O(m+n+k) How long to compute  ? O(m+n+k) Suppose an assignment to x 1 …x k and g 1 …g m satisfies . Then C outputs 1 on input x 1 …x k. Suppose C(x 1 …x k )=1. Then setting each g i to the value of the corresponding gate satisfies .

17 Theorem. CNF-SAT ≤ P 3SAT. Proof. We show how to create an equivalent 3cnf for any cnf formula. A cnf formula  is not in 3cnf iff there is a clause C with less than 3 literals or more than 3 literals. if C = (ℓ i ), replace C with (ℓ i ⋁ ℓ I ⋁ ℓ i ) if C = (ℓ I ⋁ ℓ j ), replace C with (ℓ i ⋁ ℓ I ⋁ ℓ j )

18 We can reduce the number of literals in any clause by one if we introduce a new variable and clause: ( ℓ 1 ⋁ ℓ 2 … ⋁ ℓ n ) ≡ (z ⋁ ℓ 3 … ⋁ ℓ n ) ∧ (z → ( ℓ 1 ⋁ ℓ 2 )) ≡ (z ⋁ ℓ 3 … ⋁ ℓ n ) ∧ (¬z ⋁ ℓ 1 ⋁ ℓ 2 )) if we satisfy the first clause by setting z=1, then to satisfy the second, we must set ( ℓ 1 ⋁ ℓ 2 )=1. Repeat until every clause has three literals.

19 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 (¬x→y 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)

20 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 (x₁∨x₂)∧(x₂∨x̅₃)∧(x̅₁∨x₃) x₁x₁ x₁x₁ x₃x₃ x₃x₃ x₂x₂ x₂x₂

21 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

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

23 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

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

25 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

26 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 }

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

28 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

29 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 ×

30 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

31 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


Download ppt "INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011."

Similar presentations


Ads by Google