,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.
To tackle these questions systematically:
Question 1: Context-Free Grammar (CFG) for words
without substring "aba"
To construct a CFG for all words over the alphabet
Σ = {a, b} that do not contain the substring "aba",
we can approach it by breaking down the problem:
1.Define the CFG components:
o Let's denote the CFG as G=(V,Σ,R,S)G = (V,
\Sigma, R, S)G=(V,Σ,R,S).
, o VVV is the set of variables (non-terminal
symbols).
o Σ={a,b}\Sigma = \{a, b\}Σ={a,b} is the
alphabet.
o RRR is the set of rules (productions).
o SSS is the start symbol.
2.Eliminate "aba" from any derivation:
o We need to ensure that no derivation step
introduces "aba".
3.Construct the CFG rules:
o Start with the basic productions that
generate strings of aaa and bbb.
o Introduce rules that avoid the formation of
"aba".
Here's a simplified outline of how the CFG might
look:
Start symbol: SSS
Productions:
o S→ϵ ∣ aS ∣ bS ∣ XS \rightarrow \epsilon \ | \
aS \ | \ bS \ | \ XS→ϵ ∣ aS ∣ bS ∣ X
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.
To tackle these questions systematically:
Question 1: Context-Free Grammar (CFG) for words
without substring "aba"
To construct a CFG for all words over the alphabet
Σ = {a, b} that do not contain the substring "aba",
we can approach it by breaking down the problem:
1.Define the CFG components:
o Let's denote the CFG as G=(V,Σ,R,S)G = (V,
\Sigma, R, S)G=(V,Σ,R,S).
, o VVV is the set of variables (non-terminal
symbols).
o Σ={a,b}\Sigma = \{a, b\}Σ={a,b} is the
alphabet.
o RRR is the set of rules (productions).
o SSS is the start symbol.
2.Eliminate "aba" from any derivation:
o We need to ensure that no derivation step
introduces "aba".
3.Construct the CFG rules:
o Start with the basic productions that
generate strings of aaa and bbb.
o Introduce rules that avoid the formation of
"aba".
Here's a simplified outline of how the CFG might
look:
Start symbol: SSS
Productions:
o S→ϵ ∣ aS ∣ bS ∣ XS \rightarrow \epsilon \ | \
aS \ | \ bS \ | \ XS→ϵ ∣ aS ∣ bS ∣ X