Computational Models - Lecture...

64
Computational Models - Lecture 11 1 Handout Mode Iftach Haitner and Yishay Mansour. Tel Aviv University. May 7/9, 2012 1 Based on frames by Benny Chor, Tel Aviv University, modifying frames by Maurice Herlihy, Brown University. Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 1 / 64

Transcript of Computational Models - Lecture...

Page 1: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Computational Models - Lecture 11 1

Handout Mode

Iftach Haitner and Yishay Mansour.

Tel Aviv University.

May 7/9, 2012

1Based on frames by Benny Chor, Tel Aviv University, modifying frames byMaurice Herlihy, Brown University.

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 1 / 64

Page 2: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Talk Outline

Reminder – deterministic and nondeterministic time classes

Additional NP languages

The class co-NP

P Verses NP

NP-completeness

Satisfiability

Reductions

Sipser’s book, 7.4–7.5

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 2 / 64

Page 3: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Reminder – Deterministic Time

Definition 1 (deterministic Time)

A deterministic TM M runs in time t , where t : N 7→ N, if for every inputw , the number of steps that M(w) uses is at most t(|w |).

Definition 2 ( DTIME)

For t : N 7→ N, letDTIME(t) = {L ⊆ Σ∗ : L is decided by an O(t)-time single tape TM}

The bound on the running time is required to hold also for input not inthe language (i.e., L).

Definition 3 ( P)

P =⋃

c≥0 DTIME(nc)

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 3 / 64

Page 4: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Reminder – NonDeterministic Time

Definition 4 (nondeterministic Time)

A non-deterministic TM N runs in time t , where t : N 7→ N, if for everyinput w , the maximum number of steps that N(w) uses on any branchof its computation tree, is at most t(|w |).

Notice that also non-accepting branches must reject within therequired time.

Definition 5 ( NTIME)

For t 7→ N 7→ N let NTIME(t) ={L ⊆ Σ∗ : L is decided by an O(t)-time single tape NTM}

Definition 6 ( NP)

NP =⋃

c≥0 NTIME(nc)

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 4 / 64

Page 5: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Reminder – NonDeterministic Time, cont.

Definition 7 (verifier)

A verifier for a language L, is an algorithm V withL = {w : V accepts 〈w , c〉 for some string c}.

Theorem 8A language is in NP iff it has a polynomial time verifier.

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 5 / 64

Page 6: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Section 1

Additional NP Languages

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 6 / 64

Page 7: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

CLIQUE

A clique in a graph is a subgraph where every two nodes areconnected by an edge.A k-clique is a clique of size k .

Question 9What is the largest k-clique in the figure?

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 7 / 64

Page 8: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

CLIQUE cont.

CLIQUE = {〈G, k〉 : G is an undirected graph with a k-clique}

Theorem 10CLIQUE ∈ NP

Proof’s idea: The clique is the certificate.

Algorithm 11 ( V)

On input (〈G, k〉, c)Accept if c is a k-clique subgraph of G;Otherwise Reject.

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 8 / 64

Page 9: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

SUBSET-SUM

A collection of non-negative integers x1, . . . , xk

A target number t

Question: does some subcollection add up to t?

Example 12

{4,11,16,21,27},25) ∈ SUBSET-SUM because 4 + 21 = 25.

{4,11,16,21,27},26) /∈ SUBSET-SUM (why?)

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 9 / 64

Page 10: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

SUBSET-SUM cont.

SUBSET-SUM = {〈S = {x1, . . . , xk}, t〉 : ∃{y1, . . . , y`} ⊆S :

∑`j=1 yj = t}

Collections are sets: repetitions not allowed.

Theorem 13SUBSET-SUM ∈ NP

Proof’s idea: The subset is the certificate.

Algorithm 14 ( V)

On input (〈S = {x1, . . . , xk}, t〉, c):Accept if the following holds (otherwise Reject):

1 c is a collection of numbers summing to t .2 c is a subset of S

Theorem 15There is a pseudo-polynomial algorithm for SUBSET-SUM

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 10 / 64

Page 11: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Graph characterization of SUBSET-SUM

Definition 16For 〈S = {x1, . . . , xk}, t〉, let G(S, t) = (V ,E)

V = V0 ·⋃

V1 . . . ·⋃

Vk , where Vi = {vi ,0, . . . , vi ,t}

E = E1 ·⋃. . . ·

⋃Ek , where

Ei = {(vi−1,j , vi ,j), (vi−1,j , vi ,j+xi) : j ∈ {0, . . . , t}}

Claim 17vi ,j is reachable from v0,0 in G(S, t), iff〈{x1, . . . , xi}, j〉 ∈ SUBSET-SUM.

Proof?

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 11 / 64

Page 12: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Pseudo-polynomial algorithm for SUBSET-SUM

Algorithm 18

Input 〈S, t〉

Return TRUE iff vk ,t is reachable from v0,0 in G(S, t).

Correctness

Size of G(S, t) is O(|S| · t), and therefore the resulting algorithmfor SUBSET-SUM runs in time poly(|S| · t).

Not poly(log2 t) but poly(t) (i.e., pseudo-polynomial)

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 12 / 64

Page 13: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Independent Set

An independent set in a graph is a set of vertexes, no two of which arelinked by an edge.

A k-IS is an independent set of size k .

Question 19What is the largest k-IS in the figure?

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 13 / 64

Page 14: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

IND-SET cont.

IND-SET = {〈G, k〉 : G contains an independent set of size k}

Theorem 20IND-SET ∈ NP

Proof’s idea: The independent set is the certificate.

Algorithm 21 ( V)

On input (〈G, k〉, c)Accept if c is a k-IS of G (no edges between nodes in c, and |c| = k);Otherwise Reject.

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 14 / 64

Page 15: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

KNAPSACK

A collection of non-negative integers x1, . . . , xk (size)

A collection of non-negative integers y1, . . . , yk (benefit)

A capacity B

A target number t

Question: does some S ⊂ [1, k ] has∑

i∈S xi ≤ B and∑

i∈S yi ≥ t?

Example 22

({4,11,16,21,27}, {7,3,9,5,35},B = 20, t = 16) ∈ KNAPSACKbecause S = {1,3}.

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 15 / 64

Page 16: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

KNAPSACK cont.

Theorem 23KNAPSACK ∈ NP

Proof’s idea: The subset is the certificate.

Algorithm 24 ( V)

On input (〈{x1, . . . , xk}, {y1, . . . , yk},B, t〉, c):Accept if the following holds (otherwise Reject):

1∑

i∈c xi ≤ B2

∑i∈c yi ≥ t .

3 c is a subset of [1, . . . , k ]

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 16 / 64

Page 17: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Pseudo-polynomial algorithm for KNAPSACK

Theorem 25There is a pseudo-polynomial algorithm for KNAPSACK

Running time O(k · t)

Not poly(log2 t) but poly(t) (i.e., pseudo-polynomial)

Algorithm 26 (KNAPSACK)

A(0,0) = 0 and A(0,p) = ∞ for p 6= 0.For i = 1 to k DOFor p = 0 to t DOA(i ,p) = min{A(i − 1,p), xi + A(i − 1,p − yi)}ENDTest t ≤ max{p|A(k ,p) ≤ B}.

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 17 / 64

Page 18: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Section 2

The Class coNP

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 18 / 64

Page 19: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

The Class co-NP

CLIQUE and SUBSET-SUM seem not to be members of NP .

It is harder to efficiently verify that something does not exist than toefficiently verify that something does exist..

Definition 27 ( co-NP)

co-NP = {L : L ∈ NP}.

So far, no one knows if co-NP is distinct from NP.

Claim 28P ⊆ co-NP .

Proof?

L ∈ P =⇒ L ∈ P =⇒ L ∈ NP =⇒ L ∈ co-NP

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 19 / 64

Page 20: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Section 3

P vs. NP

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 20 / 64

Page 21: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

P Vs. NP

NP

P P=NP

The question P?= NP is one of the great unsolved mysteries in

contemporary mathematics.

Most computer scientists believe the two classes are not equal

Most bogus proofs show them equal (why?)

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 21 / 64

Page 22: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Observations

If P differs from NP , then the distinction between P and NP \ P ismeaningful and important.

languages in P are tractable

languages in NP \ P are intractable

Until we can prove that P 6= NP, there is no hope of proving that aspecific language lies in NP \ P .

Nevertheless, we can prove statements of the form

If A ∈ NP \ P then B ∈ NP \ P.

If co-NP 6= NP then P 6= NP .

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 22 / 64

Page 23: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Section 4

NP Completeness

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 23 / 64

Page 24: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

NP Completeness

P

NP

NP-complete

The class of NP-complete languages are“hardest” languages in NP

“least likely” to be in P

If any NP-complete L ∈ P, then NP = P .Such languages, “carry on their backs” the burden of all of NP.

Question 29Are there NP-complete languages?

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 24 / 64

Page 25: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Polynomial-Time Computable Functions

Definition 30 (poly-time computable functions)

A function f : Σ∗ 7→ Σ∗ is polynomial-time computable, if there is apoly-time deterministic TM that

starts with input w , and

halts with f (w) on tape.

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 25 / 64

Page 26: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Polynomial-Time Reducibility

Definition 31A language A is polynomial time mapping reducible to B, denotedA ≤P B, if exists poly-time computable f such that

w ∈ A ⇐⇒ f (w) ∈ B.

for every w ∈ Σ∗.The function f is called a polynomial-time reduction from A to B.

The mapping f efficiently converts questions about membership in A tomembership in B.

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 26 / 64

Page 27: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Reductions to P

Theorem 32

If A ≤P B and B ∈ P then A ∈ P.

Proof:

Let f the reduction from A to B, computed by TM Mf .On input x , the TM Mf makes at most cf · |x |af steps.Let MB be the poly-time decider for B.On input y , the TM MB makes at most cB · |y |aB steps.

Algorithm 33 (Decider MA for A)

On input x , return MB(f (x))

MA decides ARunning time of MB(x), is at mostcB · (cf · |x |af )aB = (cB · caB

f ) · |x |af ·aB ∈ poly(|x |)Hence, A ∈ P

♣Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 27 / 64

Page 28: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Remarks

Question 34Assume that {0n1n : n ≥ 0} ≤P L. Does it yield that L ∈ P?

L = HTM

If x = 0n1n then f (x) = Mstop

Otherwise f (x) = Mrun.

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 28 / 64

Page 29: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

NP Completeness, Formal Definition

Definition 35 ( NP-complete)

A language B is NP-complete, if

B ∈ NP , and

Every A ∈ NP is poly-time reducible to B (i.e., A ≤P B)

We let NPC denote the class of all NP-complete languages.

Compare to

Definition 36 (RE-Complete)

A language B is RE-complete, if

B ∈ RE , and

Every A ∈ RE is mapping reducible to B.

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 29 / 64

Page 30: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Why NP Completeness?

Theorem 37

If B ∈ NPC and B ∈ P, then P = NP .

Proof: Immediately follows by Thm 32. ♣

To show P = NP (and make an instant fortune, seewww.claymath.org/millennium/P_vs_NP/), suffices to find apolynomial-time algorithm for any NP-complete problem.

Question 38Is NPC empty?

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 30 / 64

Page 31: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

NPC Is Not Empty

ANP = {〈M, x ,1n〉 : M is a TM ∧ ∃c ∈Σ∗ s.t. M(x , c) accepts within n steps}

Theorem 39ANP ∈ NPC

Proof:

Clearly ANP ∈ NP

Let L ∈ NP , let V be a verifier for L and let p ∈ poly be a bound onthe running time of V (i.e., V(w , ·) halts within p(|w |) steps, forevery w ∈ Σ∗)).

Define f (x) = 〈V, x ,1p(|x|)〉.

Clearly f is poly-time computable and x ∈ L ⇐⇒ f (x) ∈ ANP.

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 31 / 64

Page 32: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Finding Additional NP-complete Languages

Theorem 40Assume that

1 B ∈ NP

2 A ∈ NPC and A ≤P B

then B ∈ NPC.

Proof: Home exercise . . .♣

We would like to find L ∈ NPC that is “natural" and “easy" to reduce to.

The most useful such language is the language of satisfied formulas.

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 32 / 64

Page 33: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Section 5

Satisfiability

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 33 / 64

Page 34: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Boolean Variables

A Boolean variable assumes valuesI TRUE (written 1), and FALSE (written 0).

Boolean operations:I and: ∧I or: ∨I not: ¬

Examples:

0 ∧ 1 = 0

0 ∨ 1 = 1

0 = 1

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 34 / 64

Page 35: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Boolean Formulas and SATA Boolean formula is an expression involving Boolean variables andoperations.

φ = (x ∧ y) ∨ (x ∧ z)

Definition 41 (satisfiable formula)

A formula is satisfiable, if some assignment of 0s and 1s to thevariables makes the formula evaluate to 1.

The formula φ = (x ∧ y) ∨ (x ∧ z) is satisfiable by the assignment

x = 0

y = 1

z = 0

The language of satisfied formulas:

SAT = {〈φ〉 : φ is a satisfiable Boolean formula}

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 35 / 64

Page 36: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

SAT ∈ NPC

SAT = {〈φ〉 : φ is satisfiable Boolean formula}

Theorem 42 (Cook-Levin (early 70s))

SAT ∈ NPC.

The “most important" NP-complete language.

It is easy to see that SAT ∈ NP

For the proof of other part wait for next week . . .

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 36 / 64

Page 37: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

The Language 3SATIt is useful to consider a special version of SAT

A literal is a variable or negated variable: x or x .A clause is several literals joined by ∨s: (x1 ∨ x2 ∨ x3)

A Boolean formula is in conjunctive normal form (CNF) if itconsists of clauses, connected with ∧s.For example: (x1 ∨ x2 ∨ x3 ∨ x4) ∧ (x3 ∨ x5 ∨ x6) ∧ (x3 ∨ x6)

Definition 43A Boolean formula is in k-CNF form, if it is a CNF formula, and allclauses have k literals.

Example of 3CNF: (x1 ∨ x2 ∨ x3) ∧ (x3 ∨ x5 ∨ x6) ∧ (x3 ∨ x6 ∨ x4)

The language of satisfied 3CNF formulas:

3SAT = {〈φ〉 : φ is satisfiable 3CNF formula}

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 37 / 64

Page 38: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

3SAT ∈ NPC

It is trivial that 3SAT ≤P SAT

Clearly 3SAT ∈ NP

We later show that SAT ≤P 3SAT, yielding that 3SAT ∈ NPC.

Since 3SAT has more structure than SAT, it is simpler to reduce itto other languages

In the following we prove that several NP languages are NPC, byshowing a reduction from 3SAT to them

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 38 / 64

Page 39: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

1SAT,2SAT ∈ P

Question 44Is 1SAT ∈ P ?

Question 45Is 2SAT ∈ P ?

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 39 / 64

Page 40: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

A Graph characterization for 2CNF

Definition 46For 2CNF formula φ with variables x1, . . . , xk , define G(φ) = (V ,E) as

V = {x1, x1, . . . , xk , xk}

E = {(`, `′), (`′, `) : (` ∨ `′) ∈ φ} (taking x = x).

Claim 47

G(φ) contains path from ` to `′ =⇒ in any satisfying assignment of φwith ` = 1, it holds that `′ = 1.

Proof?

Claim 48

G(φ) contains path from ` to `′ =⇒ G(φ) contains path from `′ to `

Proof?

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 40 / 64

Page 41: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

A Graph characterization for 2CNF , cont

Definition 49A variable x in a a 2CNF φ is bad, if there are paths in G(φ) from x tox and from x to x .

Claim 50A 2CNF formula is satisfiable iff it contains no bad variables.

φ has bad =⇒ φ is unsatisfiable. Proof? by Claim 47φ has no bad variables =⇒ φ is satisfiable. Proof?

Algorithm 511 Pick unassigned literal ` ∈ V that has no path from ` to `2 Assign 1 to all literals reachable from `, and 0 to their negations.3 Repeat.

Can there be conflicts?Same iteration? No since φ has no bad variablesDifferent iterations? No by Claim 48.

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 41 / 64

Page 42: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Poly-time algorithm for 2SAT

Algorithm 52 ( TwoSatSolver)

Input: 2CNF φReturn TRUE if there exist no bad variables in φ:

Efficiency?

Correctness?

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 42 / 64

Page 43: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Section 6

Clique

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 43 / 64

Page 44: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

3SAT ≤P CLIQUE

CLIQUE = {〈G, k〉 : G is an undirected graph with a k-clique}

Claim 533SAT ≤P CLIQUE

Since CLIQUE ∈ NP, it follows that CLIQUE ∈ NPCProof’s idea: We’ll construct a poly-time reduction f that maps 3CNFformulae φ to graphs and numbers 〈G, k〉.

The function f will have the property that φ is satisfiable, iff G has aclique of size k .

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 44 / 64

Page 45: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Proving 3SAT ≤P CLIQUE

Let φ be a 3CNF formula with k clauses.On going example:

(x1 ∨ x2 ∨ x3) ∧ (x3 ∨ x5 ∨ x6) ∧ (x3 ∨ x6 ∨ x4)

We define a graph G = G(φ) as follows:

Nodes in G are organized into triples t1, . . . , tk .

Each triple corresponds to a clause of φ

Each node in a triple corresponds to a literal in correspondingclause.

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 45 / 64

Page 46: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Nodes of G

φ = (x1 ∨ x2 ∨ x3) ∧ (x3 ∨ x5 ∨ x6) ∧ (x3 ∨ x6 ∨ x4)

Add a node per literal

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 46 / 64

Page 47: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Edges of G

φ = (x1 ∨ x2 ∨ x3) ∧ (x3 ∨ x5 ∨ x6) ∧ (x3 ∨ x6 ∨ x4)

Add edges between all vertex pairs, exceptwithin same triplebetween contradictory literals (e.g., x3 and x3)

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 47 / 64

Page 48: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

φ ∈ 3SAT =⇒ 〈G, k〉 ∈ CLIQUE

Proof: Suppose φ is satisfiable by an assignment ψ.With respect to ψ:

At least one literal is assigned to 1 in every clause (why?)

Select a 1-literal in every tuple;These literals can be joined by edges (why?)Yielding a k-clique in G. ♣

♣Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 48 / 64

Page 49: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

〈G, k〉 ∈ CLIQUE =⇒ φ ∈ 3SAT

Proof: Suppose G has a k-clique.

No two of the cliques nodes are in the same triple. (why?)G has k vertexes and k clauses, so each triple has exactly oneclique node.Assign 1 to each node in clique;Assignment has no contradictions (why?)Yielding a satisfying assignment to φ.

♣Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 49 / 64

Page 50: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Recap

We’ve constructed a poly-time computable function f .

We saw that f has the property that φ ∈ 3SAT iff f (φ) ∈ CLIQUE.

Therefore, f is a poly-time reduction from 3SAT to CLIQUE

=⇒ 3SAT ≤P CLIQUE. ♣

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 50 / 64

Page 51: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Section 7

Independent Set

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 51 / 64

Page 52: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Independent Set

Definition 54An independent set in a graph is a set of vertexes, no two of which arelinked by an edge.

The language of independent sets:

IND-SET = {〈G, k〉 : G contains an independent set of size k}

Clearly IND-SET ∈ NP. We show that CLIQUE ≤P IND-SET anddeduce that IND-SET ∈ NPC

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 52 / 64

Page 53: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

CLIQUE ≤P IND-SET

Proof:

Definition 55The complement of a graph G = (V ,E) is a graph Gc = (V ,Ec), where

Ec = {(v1, v2) : v1, v2 ∈ V and (v1, v2)6∈E}.

Claim 56If U is an independent set in G, then U is a clique in Gc.

The reduction from CLIQUE to IND-SET simply compute thecomplement of the graph. ♣

Remark 57Same reduction shows that IND-SET ≤P CLIQUE

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 53 / 64

Page 54: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Independent Set 7→ Clique

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 54 / 64

Page 55: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Section 8

Hamiltonian Paths and Cycles

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 55 / 64

Page 56: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Reminder – Hamiltonian Path

A Hamiltonian path in a directed G visits each node exactly once.

HAMPATH = {〈G, s, t〉 : G has Hamiltonian path from s to t}

Theorem 58HAMPATH ∈ NPC.

Not today . . .

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 56 / 64

Page 57: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Hamiltonian Cycle

A Hamiltonian Cycle in a graph is an Hamiltonian path that ends upwhere it starts (i.e., s = t).

HAMCYCLE = {〈G〉 : G has Hamiltonian cycle}

Clearly HAMCYCLE ∈ NP . We will show thatHAMPATH ≤P HAMCYCLE, and deduce that HAMCYCLE ∈ NPC

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 57 / 64

Page 58: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

HAMPATH ≤P HAMCYCLE.

Proof’s idea:

Hey, is the new vertex really needed? Why not just add an edge from tto s?

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 58 / 64

Page 59: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

HAMPATH ≤P HAMCYCLE.

Why the new vertex really needed? Why not just add an edge from t tos?

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 59 / 64

Page 60: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

HAMCYCLE ≤P HAMPATH.

Claim 59HAMCYCLE ≤P HAMPATH.

Left as an easy (recommended) exercise.

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 60 / 64

Page 61: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Section 9

Traveling Salesman

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 61 / 64

Page 62: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Traveling Salesman

Input: set of cities C and set of inter-city distances DGoal: find a an hamiltonian cycle (TS tour) of total distance atmost k

TRAVELING-SALESMAN ={〈C,D, k〉 : (C,D) has a TS tourof total distance ≤ k}

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 62 / 64

Page 63: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

HAMCYCLE ≤P TRAVELING-SALESMAN

Proof: Given a directed graph G = (V ,E), construct travelingsalesman instance.

The cities are identical to the nodes of the original graph, C = V .The distance of going from v1 to v2 is 1 if (v1, v2) ∈ E , and 2otherwise.The bound on the total distance of a tour is k = |V |.

correctness:=⇒ Suppose G has a Hamiltonian cycle.The distance assigned by the reduction to all edges in this cycle is1. Thus in (C,D) there is a traveling salesman tour of total distance|V | = k , namely (C,D, k) ∈ TRAVELING-SALESMAN.⇐= Suppose (C,D) has a traveling salesman tour of total distance|V | = k .Tour cannot contain any edge of distance 2. Therefore it gives aHamiltonian cycle in G.

Efficiency: reduction done in quadratic time (filling up distancesfor all edges of the complete graph).

♣Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 63 / 64

Page 64: Computational Models - Lecture 111tau-cm2013.wdfiles.com/local--files/course-schedule/Blecture11_h.pdf · Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May

Chains of Reductions: NPC ProblemsSAT

IntegerProg 3SAT

Clique

IndepSet

VertexCover

SetCover

3ExactCover

Knapsack

Scheduling

3Color HamPath

HamCircuit

TRAVELING-SALESMAN

Iftach Haitner and Yishay Mansour (TAU) Computational Models Lecture 11 May 7/9, 2012 64 / 64