Assignment 2 2025
Unique #:
Due Date: 2025
Detailed solutions, explanations, workings
and references.
+27 81 278 3372
, QUESTION 1
CFG Rules
S → aA | bS | ε
A → aA | bAB | ε
AB → aDead | bS
CFG for all strings not containing "aba":
1. S → aA | bS | ε
2. A → aA | bAB | ε
3. AB → bS
Explanation:
S: Starting point. From here, you can generate:
o aA if an "a" is read
o bS if a "b" is read
o ε (empty string is allowed)
A: Seen an "a", must be careful not to follow with "ba"
AB: Seen "ab", avoid completing with "a" (which would make "aba")
We avoid generating "aba" by not allowing AB → a... (that rule is excluded).
Examples of valid strings:
"", "a", "b", "aa", "ab", "ba", "bb", "aab", "abb", "bab"
Examples of strings NOT generated:
"aba", "aaba", "baba", "ababa"
QUESTION 2
Varsity Cube 2025 +27 81 278 3372