COS3701
Assignment 2
(COMPLETE
ANSWERS) 2025
NO PLAGIARISM
[Pick the date]
[Type the company name]
, Exam (elaborations)
COS3701 Assignment 2 (COMPLETE
ANSWERS) 2025
Course
Theoretical Computer Science III (COS3701)
Institution
University Of South Africa (Unisa)
Book
Theoretical Computer Science
COS3701 Assignment 2 (COMPLETE ANSWERS) 2025 - DUE 2025; 100%
TRUSTED Complete, trusted solutions and explanations. Ensure your success
with us..
Question 1 10 Find CFGs for all words that do not have the substring aba
over the alphabet Σ = {a b}.
To define a Context-Free Grammar (CFG) that generates all words over the alphabet Σ = {a,
b} that do NOT contain the substring "aba", we need to carefully avoid introducing this
specific sequence.
✅ Step-by-step plan:
We define a grammar that ensures “aba” never appears. We do this by keeping track of what
has come so far — especially if an "a" has appeared and might be followed by "b", which might
then be followed by "a" (and thus form “aba”).
✅ Variables (non-terminals):
Let’s define the states (non-terminals) as follows:
S: Start symbol, represents strings that have not yet started forming "aba".
A: Represents strings that have just seen an "a".
AB: Represents strings that have just seen "ab" — we must not allow another "a" after
this.
Assignment 2
(COMPLETE
ANSWERS) 2025
NO PLAGIARISM
[Pick the date]
[Type the company name]
, Exam (elaborations)
COS3701 Assignment 2 (COMPLETE
ANSWERS) 2025
Course
Theoretical Computer Science III (COS3701)
Institution
University Of South Africa (Unisa)
Book
Theoretical Computer Science
COS3701 Assignment 2 (COMPLETE ANSWERS) 2025 - DUE 2025; 100%
TRUSTED Complete, trusted solutions and explanations. Ensure your success
with us..
Question 1 10 Find CFGs for all words that do not have the substring aba
over the alphabet Σ = {a b}.
To define a Context-Free Grammar (CFG) that generates all words over the alphabet Σ = {a,
b} that do NOT contain the substring "aba", we need to carefully avoid introducing this
specific sequence.
✅ Step-by-step plan:
We define a grammar that ensures “aba” never appears. We do this by keeping track of what
has come so far — especially if an "a" has appeared and might be followed by "b", which might
then be followed by "a" (and thus form “aba”).
✅ Variables (non-terminals):
Let’s define the states (non-terminals) as follows:
S: Start symbol, represents strings that have not yet started forming "aba".
A: Represents strings that have just seen an "a".
AB: Represents strings that have just seen "ab" — we must not allow another "a" after
this.