1. Short answers: (a) Define the following terms and concepts: i. - - PowerPoint PPT Presentation

1 short answers a define the following terms and concepts
SMART_READER_LITE
LIVE PREVIEW

1. Short answers: (a) Define the following terms and concepts: i. - - PowerPoint PPT Presentation

2 CS 341 Practice Final 1. Short answers: (a) Define the following terms and concepts: i. Union, intersection, set concatenation, Kleene-star, set CS 341 Practice Final subtraction, complement Answer: Union: S T = { x | x S or x T


slide-1
SLIDE 1

CS 341 Practice Final Marvin K. Nakayama Computer Science Dept., NJIT

CS 341 Practice Final 2

  • 1. Short answers:

(a) Define the following terms and concepts:

  • i. Union, intersection, set concatenation, Kleene-star, set

subtraction, complement Answer: Union: S ∪ T = { x | x ∈ S or x ∈ T} Intersection: S ∩ T = { x | x ∈ S and x ∈ T} Concatenation: S ◦ T = { xy | x ∈ S, y ∈ T} Kleene-star: S∗ = { w1w2 · · · wk | k ≥ 0, wi ∈ S ∀ i = 1, 2, . . . , k} Subtraction: S − T = { x | x ∈ S, x ∈ T} Complement: S = { x ∈ Ω | x ∈ S} = Ω − S, where Ω is the universe of all elements under consideration.

  • ii. A set S is closed under an operation f

Answer: S is closed under f if applying f to members of S always returns a member of S.

CS 341 Practice Final 3

  • iii. Regular language

Answer: A regular language is defined by a DFA.

  • iv. Kleene’s theorem

Answer: A language is regular if and only if it has a regular expression.

  • v. Context-free language

Answer: A CFL is defined by a CFG.

  • vi. Chomsky normal form

Answer: A CFG is in Chomsky normal form if each of its rules has one of 3 forms: A → BC, A → x,

  • r S → ε,

where A, B, C are variables, B and C are not the start variable, x is a terminal, and S is the start variable.

CS 341 Practice Final 4

  • vii. Church-Turing Thesis

Answer: The informal notion of algorithm corresponds exactly to a Turing machine that always halts (i.e., a decider).

  • viii. Turing-decidable language

Answer: A language A that is decided by a Turing machine; i.e., there is a Turing machine M such that

  • M halts and accepts on any input w ∈ A, and
  • M halts and rejects on input input w ∈ A.

Looping cannot happen.

  • ix. Turing-recognizable language

Answer: A language A that is recognized by a Turing machine; i.e., there is a Turing machine M such that

  • M halts and accepts on any input w ∈ A, and
  • M rejects or loops on any input w ∈ A.
slide-2
SLIDE 2

CS 341 Practice Final 5

  • x. co-Turing-recognizable language

Answer: A language whose complement is Turing-recognizable.

  • xi. Countable and uncountable sets

Answer:

  • A set S is countable if it is finite or we can define a

correspondence between S and the positive integers.

  • In other words, we can create a list of all the elements in S and

each specific element will eventually appear in the list.

  • An uncountable set is a set that is not countable.
  • A common approach to prove a set is uncountable is by using a

diagonalization argument.

CS 341 Practice Final 6

  • xii. Language A is mapping reducible to language B, A ≤m B

Answer:

  • Suppose A is a language defined over alphabet Σ1,

and B is a language defined over alphabet Σ2.

  • Then A ≤m B means there is a computable function

f : Σ∗

1 → Σ∗ 2 such that w ∈ A if and only if f(w) ∈ B.

Σ∗

1

Σ∗

2

A B f f w ∈ A ⇐ ⇒ f(w) ∈ B YES instance for problem A ⇐ ⇒ YES instance for problem B

CS 341 Practice Final 7

  • xiii. Function f(n) is O(g(n))

Answer: There exist constants c and n0 such that |f(n)| ≤ c · g(n) for all n ≥ n0.

  • xiv. Classes P and NP

Answer:

  • P is the class of languages that can be decided by a

deterministic Turing machine in polynomial time.

  • NP is the class of languages that can be verified in

(deterministic) polynomial time.

  • Equivalently, NP is the class of languages that can be decided by

a nondeterministic Turing machine in polynomial time.

CS 341 Practice Final 8

  • xv. Language A is polynomial-time mapping reducible to language B,

A ≤P B. Answer:

  • Suppose A is a language defined over alphabet Σ1,

and B is a language defined over alphabet Σ2.

  • Then A ≤P B means ∃ polynomial-time computable function

f : Σ∗

1 → Σ∗ 2 such that w ∈ A if and only if f(w) ∈ B.

slide-3
SLIDE 3

CS 341 Practice Final 9

  • xvi. NP-complete

Answer: Language B is NP-Complete if B ∈ NP, and for every language A ∈ NP, we have A ≤P B. A1 A2 A3 A4 A5 B

NP

C Typical approach for proving language C is NP-Complete:

  • first show C ∈ NP
  • then show a known NP-Complete language B satisfies B ≤P C.
  • xvii. NP-hard

Answer: Lang B is NP-hard if A ≤P B for every lang A ∈ NP.

CS 341 Practice Final 10

(b) Give the transition functions δ of a DFA, NFA, PDA, Turing machine and nondeterministic Turing machine. Answer:

  • DFA, δ : Q × Σ → Q,

where Q is the set of states and Σ is the alphabet. q1 q2 q3 a b b a a, b

  • NFA, δ : Q × Σε → P(Q),

where Σε = Σ ∪ {ε} and P(Q) is the power set of Q q1 q2 q3 q4 0, 1 1 0, ε 1 0, 1

CS 341 Practice Final 11

  • PDA, δ : Q × Σε × Γε → P(Q × Γε),

where Γ is the stack alphabet and Γε = Γ ∪ {ε}.

qi qj read, pop → push a, b → c

Stack

  • d

b Before

  • d

c After

  • Turing machine, δ : Q × Γ → Q × Γ × {L, R},

where Γ is the tape alphabet, L means move tape head one cell left, and R means move tape head one cell right. q s a → b, L read → write, move Tape a b a a

  • Before

a b b a

  • After

CS 341 Practice Final 12

  • Nondeterministic Turing machine,

δ : Q × Γ → P(Q × Γ × {L, R}) qi qj qk qℓ c → a, L c → c, R c → d, R c → a, L Multiple choices when in state qi and read c from tape: δ(qi, c) = { (qj, a, L), (qk, c, R), (qℓ, a, L), (qℓ, d, R) }

slide-4
SLIDE 4

CS 341 Practice Final 13

(c) Explain the “P vs. NP” problem. Answer:

  • P is the class of languages that can be solved in polynomial time.
  • NP is the class of languages that can be verified in (deterministic)

polynomial time.

  • We know that P ⊆ NP, but it is currently unknown

if P = NP or P = NP.

CS 341 Practice Final 14

  • 2. Recall that ATM = { M, w | M is a TM that accepts string w }.

(a) Prove that ATM is undecidable. You may not cite any theorems or corollaries in your proof. Overview of Proof:

  • Suppose ATM is decided by some TM H, taking input M, w.

H − → M, w

✟✟✟✟ ✯ ❍❍❍❍ ❥

accept, if M, w ∈ ATM reject, if M, w ∈ ATM

  • Define another TM D using H as a subroutine.

H D − → M, M

✟✟✟✟ ✯ ❍❍❍❍ ❥

accept reject − → M

✟✟✟✟✟✟✟✟ ✟ ✯ ❍❍❍❍❍❍❍❍ ❍ ❥

accept reject

  • What happens when we run D with input D ?

D accepts D iff D doesn’t accept D, which is impossible.

CS 341 Practice Final 15

Detailed Proof:

  • Suppose there exists a TM H that decides ATM.
  • Consider language

L = { M | M is a TM that does not accept M }.

  • Now construct a TM D for L using TM H as a subroutine:

D = “On input M, where M is a TM:

  • 1. Run H on input M, M.
  • 2. If H accepts, reject. If H rejects, accept.”
  • If we run TM D on input D, then D accepts D if and only if

D doesn’t accept D.

  • Since this is impossible, TM H must not exist.

CS 341 Practice Final 16

(b) Show that ATM is Turing-recognizable. Answer: The universal TM U recognizes ATM, where U is defined as follows: U = “On input M, w, where M is a TM and w is a string:

  • 1. Run M on w.
  • 2. If M accepts w, accept; if M rejects w, reject.”

Note that U only recognizes ATM and does not decide ATM since when we run M on w, there is the possibility that M neither accepts nor rejects w but rather loops on w.

slide-5
SLIDE 5

CS 341 Practice Final 17

  • 3. Each of the languages below in parts (a), (b), (c), (d) is of one of the

following types: Type REG. It is regular. Type CFL. It is context-free, but not regular. Type DEC. It is Turing-decidable, but not context-free. For each of the following languages, specify which type it is. Also, follow these instructions:

  • If a language L is of Type REG, give a regular expression and a DFA

for L.

  • If a language L is of Type CFL, give a context-free grammar and a

PDA for L. Also, prove that L is not regular.

  • If a language L is of Type DEC, give a description of a Turing

machine that decides L. Also, prove that L is not context-free.

CS 341 Practice Final 18

(a) A = { w ∈ Σ∗ | w = reverse(w) and the length of w is divisible by 4 }, where Σ = {0, 1}. Answer: A is of type CFL. A CFG for A has rules S → 00S00 | 01S10 | 10S01 | 11S11 | ε. A PDA for A is as follows:

q1 q2 q3 q4 q5 q6 ε, ε → $ 0, ε → 0 1, ε → 1 0, ε → 0 1, ε → 1 ε, ε → ε 0, 0 → ε 1, 1 → ε 0, 0 → ε 1, 1 → ε ε, $ → ε

We now prove that A is not regular by contradiction.

  • Suppose that A is regular. Let p ≥ 1 be the pumping length of

the pumping lemma (Theorem 1.I).

  • Consider string s = 0p 12p 0p ∈ A, and note that

|s| = 4p > p, so conclusions of pumping lemma must hold.

  • Thus, can split s = xyz satisfying (1) xyiz ∈ A for all i ≥ 0,

(2) |y| > 0, and (3) |xy| ≤ p.

CS 341 Practice Final 19

  • Since all of the first p symbols of s are 0s, (3) implies that x and

y must only consist of 0s. Also, z must consist of the rest of the 0s at the beginning, followed by 12p0p.

  • Hence, we can write x = 0j, y = 0k, z = 0m 12p 0p, where

j + k + m = p since s = 0p12p0p = xyz = 0j 0k 0m 12p 0p.

  • Moreover, (2) implies that k > 0.
  • Finally, (1) states that xyyz must belong to A. However,

xyyz = 0j 0k 0k 0m 12p 0p = 0p+k 12p 0p since j + k + m = p.

  • But, k > 0 implies reverse(xyyz) = xyyz, which means

xyyz ∈ A, which contradicts (1).

  • Therefore, A is a nonregular language.

CS 341 Practice Final 20

(b) B = { bnanbn | n ≥ 0 }. Answer: B is of type DEC. Below is a description of a Turing machine that decides B. M = “On input string w ∈ {a, b}∗: 1. Scan input to check if it’s in b∗a∗b∗; reject if not. 2. Return tape head to left-hand end of tape. 3. Repeat following until no more b’s left on tape. 4. Replace the leftmost b with x. 5. Scan right until a occurs. If no a’s, reject. 6. Replace the leftmost a with x. 7. Scan right until b occurs. If no b’s, reject. 8. Replace the leftmost b (after the a’s) with x. 9. Return tape head to left end of tape; go to stage 3. 10. If tape contains any a’s, reject. Else, accept.” We now prove that B is not context-free by contradiction.

slide-6
SLIDE 6

CS 341 Practice Final 21

  • Suppose that B is context-free.
  • Let p be pumping length of CFL pumping lemma (Theorem 2.D).
  • Consider string s = bpapbp ∈ B. Note that |s| = 3p > p, so the

pumping lemma will hold.

  • Thus, can split s = bpapbp = uvxyz = satisfying uvixyiz ∈ B

for all i ≥ 0, |vy| ≥ 1, and |vxy| ≤ p.

  • We now consider all of the possible choices for v and y:

Suppose strings v and y are uniform (e.g., v = bj for some j ≥ 0, and y = ak for some k ≥ 0). Then |vy| ≥ 1 implies that v = ε or y = ε (or both), so uv2xy2z won’t have the correct number of b’s at the beginning, a’s in the middle, and b’s at the end. Hence, uv2xy2z ∈ B. Now suppose strings v and y are not both uniform. Then uv2xy2z won’t have form b · · · ba · · · ab · · · b, so uv2xy2z ∈ B.

  • Every case gives contradiction, so B is not a CFL.

CS 341 Practice Final 22

(c) C = { w ∈ Σ∗ | na(w) mod 4 = 1 }, where Σ = {a, b} and na(w) is the number of a’s in string w. For example, na(babaabb) = 3. Also, 3 mod 4 = 3, and 9 mod 4 = 1. Answer: C is of type REG. A regular expression for C is (b∗ab∗ab∗ab∗ab∗)∗b∗ab∗, and a DFA for C is below:

q1 q2 q3 q3 a b a b a b a b

CS 341 Practice Final 23

(d) D = { bnanbkck | n ≥ 0, k ≥ 0 }. [Hint: Recall that the class of context-free languages is closed under concatenation.] Answer: D is of type CFL. A CFG for D is S → XY X → bXa | ε Y → bY c | ε A PDA for D is below:

q1 q2 q3 q4 q5 q6 ε, ε → $ ε, ε → ε b, ε → b a, b → ε ε, $ → $ b, ε → b ε, ε → ε c, b → ε ε, $ → ε

Important: q3 to q4 pops and pushes

to make sure stack is empty.

We now prove that D is not regular by contradiction.

  • Suppose that D is regular. Let p ≥ 1 be pumping length of

pumping lemma (Theorem 1.I).

  • Consider string s = bp ap bp cp ∈ D, and note that

|s| = 4p > p, so conclusions of pumping lemma must hold.

CS 341 Practice Final 24

  • Thus, can split s = xyz satisfying (1) xyiz ∈ D for all i ≥ 0,

(2) |y| > 0, and (3) |xy| ≤ p.

  • Since all of the first p symbols of s are b’s, (3) implies that x and

y must only consist of b’s. Also, z must consist of the rest of the b’s at the beginning, followed by ap bp cp.

  • Hence, we can write x = bj, y = bk, z = bm ap bp cp, where

j + k + m = p since s = bp ap bp cp = xyz = bj bk bm ap bp cp.

  • Moreover, (2) implies that k > 0.
  • Finally, (1) states that xyyz must belong to D, but

xyyz = bj bk bk bm ap bp cp = bp+k ap bp cp since j + k + m = p. Also k > 0, so xyyz ∈ D, which contradicts (1). Therefore, D is a nonregular language.

slide-7
SLIDE 7

CS 341 Practice Final 25

  • 4. Each of the languages below in parts (a), (b), (c), (d) is of one of the

following types: Type DEC. It is Turing-decidable. Type TMR. It is Turing-recognizable, but not decidable. Type NTR. It is not Turing-recognizable. For each of the following languages, specify which type it is. Also, follow these instructions:

  • If a language L is of Type DEC, give a description of a Turing

machine that decides L.

  • If a language L is of Type TMR, give a description of a Turing

machine that recognizes L. Also, prove that L is not decidable.

  • If a language L is of Type NTR, give a proof that it is not

Turing-recognizable.

CS 341 Practice Final 26

In each part below, if you need to prove that the given language L is decideable, undecidable, or not Turing-recognizable, you must give an explicit proof of this; i.e., do not just cite a theorem that establishes this without a proof. However, if in your proof you need to show another language L′ has a particular property for which there is a theorem that establishes this, then you may simply cite the theorem without proof. (a) ATM, where ATM = { M, w | M is a TM that accepts string w }. Answer: ATM is of type NTR, which is just Theorem 4.M. Proof:

  • If ATM were Turing-recognizable, then ATM would be both

Turing-recognizable (see slide 4-25) and co-Turing-recognizable.

  • But then Theorem 4.L would imply that ATM is decidable, which

we know is not true by Theorem 4.I.

  • Hence, ATM is not Turing-recognizable.

CS 341 Practice Final 27

(b) EQTM = { M1, M2 | M1, M2 are TMs with L(M1) = L(M2) }.

[Hint: show ATM ≤m EQTM.]

Answer: EQTM is of type NTR (see Theorem 5.K). We prove this by showing ATM ≤m EQTM and applying Corollary 5.I.

  • Define the reducing function f(M, w) = M1, M2, where

M1 = “reject on all inputs.” M2 = “On input x:

  • 1. Ignore input x, and run M on w.
  • 2. If M accepts w, accept.”
  • L(M1) = ∅.
  • If M accepts w (i.e., M, w ∈ ATM), then L(M2) = Σ∗.

If M doesn’t accept w (i.e., M, w ∈ ATM), then L(M2) = ∅.

  • Thus, M, w ∈ ATM ⇐

⇒ f(M, w) = M1, M2 ∈ EQTM, so ATM ≤m EQTM.

  • But ATM is not TM-recognizable (Corollary 4.M),

so EQTM is not TM-recognizable by Corollary 5.I.

CS 341 Practice Final 28

(c) HALT TM = { M, w | M is a TM that halts on input w }. [Hint: modify the universal TM to show HALT TM is Turing-recognizable.] Answer: HALT TM is of type TMR (see Theorem 5.A). The following Turing machine recognizes HALT TM: T = “On input M, w, where M is a TM and w is a string:

  • 1. Run M on w.
  • 2. If M halts on w, accept.”

We now prove that HALT TM is undecidable, which is Theorem 5.A.

  • Suppose there exists a TM R that decides HALT TM.
  • Then could use R to build a TM S to decide ATM by modifying

universal TM to first use R to see if it’s safe to run M on w.

slide-8
SLIDE 8

CS 341 Practice Final 29

S = “On input M, w, where M is a TM and w is a string:

  • 1. Run R on input M, w.
  • 2. If R rejects, reject.
  • 3. If R accepts, simulate M on input w until it halts.
  • 4. If M accepts, accept; otherwise, reject.”
  • Since TM R is a decider, TM S always halts and is a decider.
  • Thus, deciding ATM is reduced to deciding HALT TM.
  • However, ATM is undecidable (Theorem 4.I), so that must mean

that HALT TM is also undecidable.

CS 341 Practice Final 30

(d) EQDFA = { M1, M2 | M1, M2 are DFAs with L(M1) = L(M2) }. Answer: EQDFA is of type DEC (see Theorem 4.E). The following TM decides EQDFA: M = “On input A, B, where A and B are DFAs:

  • 1. Check if A, B properly encodes 2 DFAs. If not, reject.
  • 2. Construct DFA C such that

L(C) = [L(A) ∩ L(B)] ∪ [L(A) ∩ L(B)] using algorithms for DFA union, intersection and complementation.

  • 3. Run TM that decides EDFA (Theorem 4.D) on C.
  • 4. If C ∈ EDFA, accept; if C ∈ EDFA, reject.”

CS 341 Practice Final 31

  • 5. • Let L1, L2, L3, . . . be an infinite sequence of regular languages,

each of which is defined over a common input alphabet Σ.

  • Let L = ∪∞

k=1Lk be the infinite union of L1, L2, L3, . . ..

  • Is it always the case that L is a regular language?
  • If your answer is YES, give a proof.
  • If your answer is NO, give a counterexample.
  • Explain your answer.
  • Hint: Consider, for each k ≥ 1, the language Lk = {akbk}.

CS 341 Practice Final 32

Answer: The answer is NO.

  • For each k ≥ 1, let Lk = {akbk}, so Lk is a language consisting of

just a single string akbk.

  • Since Lk is finite, it must be a regular language by Theorem 1.F.
  • But L = ∪∞

k=1Lk = { akbk | k ≥ 1 }, which we know is not

regular (see end of Chapter 1).

slide-9
SLIDE 9

CS 341 Practice Final 33

  • 6. Let L1, L2, and L3 be languages defined over the alphabet

Σ = {a, b}, where

  • L1 consists of all possible strings over Σ except the strings

w1, w2, . . . , w100; i.e., start with all possible strings over the alphabet take out 100 particular strings the remaining strings form the language L1;

  • L2 is recognized by an NFA; and
  • L3 is recognized by a PDA.

Prove that (L1 ∩ L2)L3 is a context-free language. [Hint: First show that L1 and L2 are regular. Also, consider L1.]

CS 341 Practice Final 34

Answer:

  • L1 = {w1, w2, . . . , w100}, so |L1| = 100. Thus, L1 is a regular

language since it is finite by Theorem 1.F.

  • Then Theorem 1.H implies that the complement of L1 must be

regular, but the complement of L1 is L1. Thus, L1 is regular.

  • Language L2 has an NFA, so it also has a DFA by Theorem 1.C.

Therefore, L2 is regular.

  • Since L1 and L2 are regular, L1 ∩ L2 must be regular by

Theorem 1.G. Theorem 2.B then implies that L1 ∩ L2 is CFL.

  • Since L3 has a PDA, L3 is CFL by Theorem 2.C.
  • Hence, since L1 ∩ L2 and L3 are both CFLs, their concatenation is

CFL by Theorem 2.F.

CS 341 Practice Final 35

  • 7. Write Y or N in the entries of the table below to indicate which classes
  • f languages are closed under which operations.

Regular Decidable Turing-recognizable Operation languages CFLs languages languages Union Intersection Complementation Answer:

Regular Decidable Turing-recog Op languages CFLs languages languages ∪ Y (Thm 1.A) Y (Thm 2.E) Y (HW 7, prob 2a) Y (HW 7, prob 2b) ∩ Y (Thm 1.G) N (HW 6, prob 2a) Y Y

  • Compl. Y (Thm 1.H) N (HW 6, prob 2b)

Y (swap acc/rej) N (e.g., ATM) CS 341 Practice Final 36

  • 8. Consider the following context-free grammar G in Chomsky normal

form: S → a | Y Z Z → ZY | a Y → b | ZZ | Y Y Use the CYK (dynamic programming) algorithm to fill in the following table to determine if G generates the string babba. Does G generate babba?

slide-10
SLIDE 10

CS 341 Practice Final 37

S → a | Y Z Z → ZY | a Y → b | ZZ | Y Y 1 2 3 4 5 1 Y S S S Y 2 S, Z Z Z Y 3 Y Y S 4 Y S 5 S, Z b a b b a

CS 341 Practice Final 38

  • 9. Recall that

CLIQUE = { G, k | G is an undirected graph with a k-clique }, 3SAT = { φ | φ is a satisfiable 3cnf-function }.

  • Show that CLIQUE is NP-Complete by showing that CLIQUE ∈ NP

and 3SAT ≤P CLIQUE.

  • Be sure to prove your reduction works and that it requires

polynomial time.

  • Also, be sure to provide proofs of these results, and don’t just cite a

theorem.

CS 341 Practice Final 39

Answer: Prove CLIQUE ∈ NP

  • The clique is the certificate c.
  • Here is a verifier for CLIQUE:

V = “On input G, k, c:

  • 1. Test whether c is a set of k different nodes in G.
  • 2. Test whether G contains all edges connecting nodes in c.
  • 3. If both tests pass, accept; otherwise, reject.”
  • If graph G has m nodes, then (when G is encoded as list of nodes

followed by list of edges) Stage 1 takes O(k)O(m) = O(km) time. Stage 2 takes O(k2)O(m2) = O(k2m2) time.

CS 341 Practice Final 40

Prove 3SAT ≤m CLIQUE Proof Idea: Convert instance φ of 3SAT problem with k clauses into instance G, k of clique problem.

  • Suppose φ is a 3cnf-function with k clauses, e.g.,

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

  • Convert φ into a graph G as follows:

Nodes in G are organized into k triples t1, t2, . . . , tk. Triple ti corresponds to the ith clause in φ. Each node in a triple corresponds to a literal within the clause. Add edges between each pair of nodes, except

within same triple between contradictory literals, e.g., x1 and x1

  • Prove φ ∈ 3SAT iff G, k ∈ CLIQUE.
slide-11
SLIDE 11

CS 341 Practice Final 41

3SAT ≤m CLIQUE Example: 3cnf-function with k = 3 clauses and m = 2 variables: φ = (x1 ∨ x1 ∨ x2) ∧ (x1 ∨ x2 ∨ x2) ∧ (x1 ∨ x2 ∨ x2)

Corresponding Graph: Clause 1

x1 x1 x2

Clause 2

x1 x2 x2

Clause 3

x1 x2 x2

CS 341 Practice Final 42

3SAT ≤m CLIQUE

  • 3cnf-formula with k = 3 clauses and m = 2 variables

φ = (x1 ∨ x1 ∨ x2) ∧ (x1 ∨ x2 ∨ x2) ∧ (x1 ∨ x2 ∨ x2) is satisfiable by assignment x1 = 0, x2 = 1.

  • Corresponding graph has k-clique:

Clause 1

x1 x1 x2

Clause 2

x1 x2 x2

Clause 3

x1 x2 x2

CS 341 Practice Final 43

Claim: φ ∈ 3SAT iff G, k ∈ CLIQUE. Proof. Use that G has edges between every pair of nodes except for

  • pairs in same triple
  • contradictory literals.

Also, φ satisfiable iff each clause has ≥ 1 true literal. Claim: The mapping φ → G, k is polynomial-time computable. Proof.

  • Given 3cnf-function φ with

k clauses m variables.

  • Constructed graph G has

3k nodes (# of edges in G) <

3k

2

  • = 3k(3k−1)

2

= O(k2) Size of graph G is polynomial in size of 3cnf-function φ.

CS 341 Practice Final 44

  • 10. Recall that

ILP = { A, b | matrix A and vector b satisfy Ay ≤ b with y an integer vector }.

  • Show that ILP is NP-Complete by showing that ILP ∈ NP and

3SAT ≤P ILP.

  • Be sure to prove your reduction works and that it requires

polynomial time.

  • Also, be sure to provide proofs of these results, and don’t just cite a

theorem.

slide-12
SLIDE 12

CS 341 Practice Final 45

ILP ∈ NP Proof.

  • The certificate c is an integer vector satisfying Ac ≤ b.
  • Here is a verifier for ILP:

V = “On input A, b, c:

  • 1. Test whether c is a vector of all integers.
  • 2. Test whether Ac ≤ b.
  • 3. If both tests pass, accept; otherwise, reject.”
  • If Ay ≤ b has m inequalities and n variables, then

Stage 1 takes O(n) time Stage 2 takes O(mn) time So verifier V runs in O(mn), which is polynomial in size of problem. Now prove ILP is NP-Hard by showing 3SAT ≤P ILP.

CS 341 Practice Final 46

3SAT ≤m ILP

  • Consider 3cnf-formula with m = 4 variables and k = 3 clauses:

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

  • Define integer linear program with

2m = 8 variables y1, y′

1, y2, y′ 2, y3, y′ 3, y4, y′ 4

yi corresponds to xi y′

i corresponds to xi

3 sets of inequalities for each of pair yi, y′

i:

0 ≤ y1 ≤ 1, 0 ≤ y′

1 ≤ 1,

y1 + y′

1 = 1

0 ≤ y2 ≤ 1, 0 ≤ y′

2 ≤ 1,

y2 + y′

2 = 1

0 ≤ y3 ≤ 1, 0 ≤ y′

3 ≤ 1,

y3 + y′

3 = 1

0 ≤ y4 ≤ 1, 0 ≤ y′

4 ≤ 1,

y4 + y′

4 = 1

which guarantee that exactly one of yi and y′

i is 1, and other is 0.

0 ≤ yi ≤ 1 ⇐ ⇒ −yi ≤ 0 & yi ≤ 1 yi + y′

i = 1

⇐ ⇒ yi + y′

i ≤ 1 & yi + y′ i ≥ 1 CS 341 Practice Final 47

3SAT ≤m ILP

  • Recall 3cnf-formula with m = 4 variables and k = 3 clauses:

φ = (x1 ∨ x2 ∨ x3) ∧ (x1 ∨ x2 ∨ x4) ∧ (x2 ∨ x4 ∨ x3) φ satisfiable iff each clause evaluates to 1. A clause evaluates to 1 iff at least one literal in the clause equals 1. For each clause (xi ∨ xj ∨ xℓ), create inequality yi + y′

j + yℓ ≥ 1.

For our example, ILP has inequalities y1 + y2 + y′

3 ≥ 1

y′

1 + y′ 2 + y4 ≥ 1

y′

2 + y′ 4 + y′ 3 ≥ 1

which guarantee that each clause evaluates to 1.

CS 341 Practice Final 48

3SAT ≤m ILP

  • Given 3cnf-formula:

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

  • Constructed ILP:

0 ≤ y1 ≤ 1, 0 ≤ y′

1 ≤ 1,

y1 + y′

1 = 1

0 ≤ y2 ≤ 1, 0 ≤ y′

2 ≤ 1,

y2 + y′

2 = 1

0 ≤ y3 ≤ 1, 0 ≤ y′

3 ≤ 1,

y3 + y′

3 = 1

0 ≤ y4 ≤ 1, 0 ≤ y′

4 ≤ 1,

y4 + y′

4 = 1

y1 + y2 + y′

3 ≥ 1

y′

1 + y′ 2 + y4 ≥ 1

y′

2 + y′ 4 + y′ 3 ≥ 1

  • Note that:

φ satisfiable ⇐ ⇒ constructed ILP has solution (with values of variables ∈ {0, 1})

slide-13
SLIDE 13

CS 341 Practice Final 49

Reducing 3SAT to ILP Takes Polynomial Time

  • Given 3cnf-formula φ with

m variables: x1, x2, . . . , xm k clauses

  • Constructed ILP has

2m variables: y1, y′

1, y2, y′ 2, . . . , ym, y′ m

6m + k inequalities:

3 sets of inequalities for each pair yi, y′

i:

0 ≤ yi ≤ 1, 0 ≤ y′

i ≤ 1,

yi + y′

i = 1,

so total of 6m inequalities of this type.

For each clause in φ, ILP has corresponding inequality, e.g.,

(x1 ∨ x2 ∨ x3) ← → y1 + y2 + y′

3 ≥ 1,

so total of k inequalities of this type.

  • Thus, size of ILP is polynomial in m and k.