, COS3701 Assignment 2 (COMPLETE
ANSWERS) 2025 – DUE 2025; 100% TRUSTED
Complete, trusted solutions and
explanations.
Question 1 10 Find CFGs for all words that do not
have the substring aba over the alphabet Σ = {a
b}. Question 2 10 Convert the grammar below to
CNF (Hint: Consult the online study material) S aX |
Yb X ZXYZ | a Y b | bY | ᴧ Z a | ᴧ Question 3 15
Build a DPDA that accepts the language L =
{(ab)n(ba)n-2| n > 2}. Question 4 15 Prove that
the language L = {an+1b2n (aa)n b | n > 0} is
non-context free. Use the pumping lemma with
length.
Question 1 [10]
Find a Context-Free Grammar (CFG) for all
words that do not have the substring aba
over Σ = {a, b}.
Solution:
We need a CFG that generates all strings over {a,
b} that do not contain the substring aba.
This is best done using a finite automaton
without aba and converting it to CFG. But here's a
direct approach using memory of last 2 characters.
ANSWERS) 2025 – DUE 2025; 100% TRUSTED
Complete, trusted solutions and
explanations.
Question 1 10 Find CFGs for all words that do not
have the substring aba over the alphabet Σ = {a
b}. Question 2 10 Convert the grammar below to
CNF (Hint: Consult the online study material) S aX |
Yb X ZXYZ | a Y b | bY | ᴧ Z a | ᴧ Question 3 15
Build a DPDA that accepts the language L =
{(ab)n(ba)n-2| n > 2}. Question 4 15 Prove that
the language L = {an+1b2n (aa)n b | n > 0} is
non-context free. Use the pumping lemma with
length.
Question 1 [10]
Find a Context-Free Grammar (CFG) for all
words that do not have the substring aba
over Σ = {a, b}.
Solution:
We need a CFG that generates all strings over {a,
b} that do not contain the substring aba.
This is best done using a finite automaton
without aba and converting it to CFG. But here's a
direct approach using memory of last 2 characters.