You are on page 1of 4

Homework – 5

1. Consider the grammar 𝐺 = (𝑉, Σ, 𝑅, 𝑆), where

a). Which strings of 𝐿(𝐺) can be produced by applying the rules at most 4 times?

b). Same string can be derived in different ways, e.g., 𝑆 ⇒ 𝐴𝐴 ⇒ 𝑎𝐴 ⇒ 𝑎𝑎, 𝑆 ⇒ 𝐴𝐴 ⇒ 𝐴𝑎 ⇒ 𝑎𝑎. Give at least
4 distinct derivations for the string 𝑏𝑎𝑏𝑏𝑎𝑏
c). For any 𝑚, 𝑛, 𝑝 > 0, describe a derivation in 𝐺 of the string 𝑏𝑚 𝑎𝑏𝑛 𝑎𝑏𝑝

2. Consider the grammar 𝐺 = (𝑉, Σ, 𝑅, 𝑆), where


Give a derivation of the string 𝑏𝑎𝑎𝑏𝑏𝑏 in 𝐺.

3. Show that the following languages are context-free by exhibiting contextfree grammars
generating each.
a). {𝑎𝑚 𝑏𝑛 : 𝑚 ≥ 𝑛 ≥ 0}
b). {𝑎𝑚 𝑏𝑛 𝑐 2𝑚+𝑛 : 𝑚, 𝑛 ≥ 0}
a)
S -> aSb | aS | ε
b)
S -> aScc | A
A -> bAc | ε
Homework – 6

4. Consider the pushdown automata 𝑀 = (𝐾, Σ, Γ, Δ, 𝑠, 𝐹), where

a). Trace all possible sequence of transitions of 𝑀 on input 𝑎𝑏𝑎

b). Show that 𝑎𝑏𝑎, 𝑎𝑎, 𝑎𝑏𝑏 ∉ 𝐿(𝑀), but 𝑏𝑎𝑎, 𝑏𝑎𝑏, 𝑏𝑎𝑎𝑎𝑎 ∈ 𝐿(𝑀)
Homework – 7
c). Describe 𝐿(𝑀) in English
5. Use the pumping theorem to show that the following languages are not context-free

a). {𝑤𝑤𝑤: 𝑤 ∈ {𝑎, 𝑏}∗ }

b). {𝑤 ∈ {𝑎, 𝑏, 𝑐}∗ : 𝑤 has equal number of 𝑎′ 𝑠, 𝑏′ 𝑠 𝑎𝑛𝑑 𝑐′𝑠}


We have L = {w (belongsTo) {a, b, c}*, and w has equal number of a's,b's and c's.

Construct another language Lnew = L (intersection) a*b*c*.


We know by properties of context free languages, if L is context free, Lnew is also context free.

Let us assume that L is context free.

Let L_{1} = a^{*}b^{*}c^{*} . Clearly L1 is regular.

But L\cap L_{1} = { a^{i}b^{i}c^{i} / i>=0 } and by the theorem it must be context-free.

But we already showed that { a^{i}b^{i}c^{i} / i>=0 } is not context-free.

So,by contradiction L cannot be a context free language.

But Lnew can be rewritten as = a^n b^n c^n, which is not context free (this proof is known and should
be present in most of the books). So L is also not context free..
6. Decide whether the following language is context-free or not, and state your reason:
a). {𝑎𝑚 𝑏𝑛 𝑐 𝑝 : 𝑚 = 𝑛 𝑜𝑟 𝑛 = 𝑝 𝑜𝑟 𝑚 = 𝑝}
b). {𝑎𝑚 𝑏𝑛 𝑐 𝑝 : 𝑚 ≠ 𝑛 𝑜𝑟 𝑛 ≠ 𝑝 𝑜𝑟 𝑚 ≠ 𝑝}
c). {𝑎𝑚 𝑏𝑛 𝑐 𝑝 : 𝑚 = 𝑛 𝑎𝑛𝑑 𝑛 = 𝑝 𝑎𝑛𝑑 𝑚 = 𝑝}
7. Construct a Pushdown automata that accept each of the followings:
a). The language {𝑎𝑚 𝑏𝑛 : 𝑚 ≤ 𝑛 ≤ 2𝑚}
b). The language {𝑤 ∈ {𝑎, 𝑏}∗ : 𝑤 = 𝑤 𝑅 }
c). The language {𝑤 ∈ {𝑎, 𝑏}∗ : 𝑤 has the same number of 𝑎′ 𝑠 and 𝑏′𝑠}

You might also like