quiz3 solutions

3
CS 360 Introduction to the Theory of Computing Quiz 3 Solutions 1. (a) State the Pumping Lemma for context-free languages. Solution. For every context-free language A, there exists a pumping length n 1 such that the following property holds. For every string w A with | w |≥ n, there exist strings u, v, x, y, and z, with w = uvxyz, so that 1. vy = ε, 2. | vxy |≤ n, and 3. uv i xy i z A for every i 0. 1. (b) Use the Pumping Lemma for context-free languages to prove that the language A = 0 n 2 : n 0 is not context-free. Solution. Assume toward contradiction that A is context-free. By the pumping lemma, there exists a pumping length n 1 for A. Let us choose w = 0 n 2 . We have w A and | w | = n 2 n, and therefore there exist strings u, v, x, y, and z with 0 n 2 = w = uvxyz and with the three properties listed above. By the first two properties, we know that vy = 0 k for some number k with 1 k n. By the third property, it holds that uv 2 xy 2 z = 0 n 2 +k A. But now we have a contradiction because 0 n 2 +k A. We know this because 1 k n implies that n 2 + k lies strictly between n 2 and the next perfect square, which is (n + 1) 2 , i.e., n 2 < n 2 + k < n 2 + 2n + 1 =(n + 1) 2 . Having derived a contradiction, we conclude that A is not context-free. 2. Consider the following DFA N: q 0 q 1 q 2 q 3 1 0 1 0 1 0 0, 1 1

Upload: arpita-sengupta

Post on 02-Oct-2014

27 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Quiz3 Solutions

CS 360 Introduction to the Theory of Computing

Quiz 3 Solutions

1. (a) State the Pumping Lemma for context-free languages.

Solution. For every context-free language A, there exists a pumping length n ≥ 1 suchthat the following property holds. For every string w ∈ A with |w| ≥ n, there exist stringsu, v, x, y, and z, with w = uvxyz, so that

1. vy 6= ε,

2. |vxy| ≤ n, and

3. uvixyiz ∈ A for every i ≥ 0.

1. (b) Use the Pumping Lemma for context-free languages to prove that the language

A ={

0n2: n ≥ 0

}

is not context-free.

Solution. Assume toward contradiction that A is context-free. By the pumping lemma,

there exists a pumping length n ≥ 1 for A. Let us choose w = 0n2. We have w ∈ A and

|w| = n2 ≥ n, and therefore there exist strings u, v, x, y, and z with

0n2= w = uvxyz

and with the three properties listed above. By the first two properties, we know thatvy = 0k for some number k with 1 ≤ k ≤ n. By the third property, it holds that

uv2xy2z = 0n2+k ∈ A.

But now we have a contradiction because 0n2+k 6∈ A. We know this because 1 ≤ k ≤ nimplies that n2 + k lies strictly between n2 and the next perfect square, which is (n + 1)2,i.e.,

n2< n2 + k < n2 + 2n + 1 = (n + 1)2.

Having derived a contradiction, we conclude that A is not context-free.

2. Consider the following DFA N:

q0 q1

q2 q3

1

0

1

01

00, 1

1

Page 2: Quiz3 Solutions

Give the state transition diagram of a 1DTM M having exactly 4 states that recognizesthe same language as N (i.e., so that L(M) = L(N)).

Solution. Define M as follows:

q0 q1

q2 q3

1/1 →

0/0 →

1/1 →

0/0 →1/1 →

0/0 →

B/B →

3. Answer true or false to each of the following questions. Then, provide a short (oneor two sentence) justification of your answer: either a sketch or the idea of a proof if thestatement is true, or a counter-example showing that the statement is false.

(a) There exists a language that is decidable by a deterministic Turing machine havingtwo tapes that is not decidable by any deterministic Turing machine having just one tape.

Solution. False. Every two-tape deterministic Turing machine can be simulated by someone-tape deterministic Turing machine.

(b) Let A and B be languages over the alphabet {0, 1}, and assume that neither A nor B isdecidable. Then it follows that AB is infinite.

Solution. True. Every finite language is decidable, and therefore A and B are infinite. Theconcatenation of two infinite languages is infinite, and therefore AB is infinite.

(c) For every language A over the alphabet {0, 1}, it holds that A∗ is context-free.

Solution. False. Consider the language

A ={

10n2: n ≥ 0

}

.

It is easy to prove that A is not context-free using the pumping lemma in a similar wayto question 1 (b). Now consider A∗. If this language were context-free, then we wouldalso have that A∗ ∩ L(10∗) is context-free, as the intersection of a context-free languagewith a regular language is context-free. But A∗ ∩ L(10∗) = A, which we know is notcontext-free. Therefore A∗ is not context-free.

(d) The language {1x1y1 : x, y ∈ {0, 1}∗ and |x | = |y|} is decidable.

Solution. True. This language is context-free, as it is generated by the following CFG:

S → 1A1

A → XAX | 1

X → 0 | 1

Every context-free language is decidable, so the language is decidable.

2

Page 3: Quiz3 Solutions

4. Let Σ = {0, 1}. Give an example of a decidable language B ⊆ Σ∗ such that both B and

B are not context-free. You do not need to prove that your choice for B is decidable, butyou must prove that both B and B are not context-free.

Solution. Let

B ={

0k : k is a perfect square}

∪{

1k : k is not a perfect square}

.

It is clear that this language is decidable.Assume toward contradiction that B is context-free. Then B ∩ L(0∗) is also context-

free, as the intersection of a context-free language with a regular language is context-free.But

B ∩ L(0∗) ={

0k : k is a perfect square}

which we have proved is not context-free in problem 1 (b). Therefore we have a contra-diction, so B is not context-free.

Now assume that B is context-free. Then B ∩ L(1∗) is also context-free. But

B ∩ L(1∗) ={

1k : k is a perfect square}

,

which again we know is not context-free. Therefore we have a contradiction, so B is notcontext-free.

3