Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Document preview thumbnail
Preview 3 out of 28 pages
Exam (elaborations)

COS3701 Assignment 2 (COMPLETE ANSWERS) 2025

Document preview thumbnail
Preview 3 out of 28 pages

COS3701 Assignment 2 (COMPLETE ANSWERS) 2025

Content preview

[TYPE THE COMPANY NAME]




COS3701 Assignment 2
(COMPLETE ANSWERS)
2025
NO PLAGIARISM

[Pick the date]




[Type the abstract of the document here. The abstract is typically a short summary of the contents of
the document. Type the abstract of the document here. The abstract is typically a short summary of
the contents of the document.]

,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}.

Solution: We want to find a Context-Free Grammar (CFG) for the language
L={w∈{a,b}∗∣w does not have the substring aba}.

Let's break down the possible structures of words that do not contain "aba".

A word that does not contain "aba" can be thought of as a sequence of blocks, where no block is
"aba" and no combination of blocks forms "aba".

Consider the states we can be in when building a string that avoids "aba":

1. Initial state (S): We haven't seen any part of "aba" or have just completed a safe
sequence.
2. Seen 'a' (A): We have just seen an 'a', which could be the start of "aba".
3. Seen 'ab' (AB): We have just seen 'ab', which could be the start of "aba".

Let's define the productions based on these states.

Let S be the start symbol. Let A be a non-terminal representing the state where the last character
read was 'a' (and we haven't formed "aba"). Let B be a non-terminal representing the state where
the last characters read were 'ab' (and we haven't formed "aba").

From the start symbol S:

 We can have an empty string: S→ϵ

,  We can start with 'b': S→bS (we are still in a "safe" state after 'b')
 We can start with 'a': S→aA (we've seen 'a', now in state A)

From state A (last character was 'a'):

 If we see 'a' again: A→aA (we still have 'a' as the last character, no "aba" formed)
 If we see 'b': A→bB (we've seen 'ab', now in state B)
 We can end the string here: A→ϵ (the string ends with 'a', no "aba")

From state B (last characters were 'ab'):

 If we see 'a': This would form "aba", which is not allowed. So, B cannot directly
transition to a state that accepts 'a'. However, this is where it gets tricky for CFGs. A CFG
cannot "reject" a character in the same way a DFA does. Instead, the grammar simply
won't have a production for that sequence.
 If we see 'b': B→bS (we've seen 'abb', which is safe, and we effectively reset to a "safe"
state S because the last 'b' doesn't start "aba")
 We can end the string here: B→ϵ (the string ends with 'ab', no "aba")

Let's refine this approach. Instead of thinking about states in a DFA-like manner, let's consider
the structure of strings that avoid "aba".

A string avoiding "aba" can be:

1. Any string not ending in 'a' or 'ab' that avoids "aba".
2. A string ending in 'a' that avoids "aba".
3. A string ending in 'ab' that avoids "aba".

Let S be the start symbol. Consider the blocks that are "safe": 'b', 'a'. If we see 'ab', the next
character must not be 'a'.

Let's try a different approach, based on the idea that any string that does not contain 'aba' can be
formed by:

 Only 'b's: b∗
 Only 'a's: a∗
 Combinations that avoid 'aba'.

A common technique is to consider what happens if we don't see the forbidden substring.

Let's define non-terminals based on the suffix we've built so far that could be a prefix of 'aba'.

S: Generates all words that do not have 'aba'. S→bS S→aA S→ϵ

Connected book
 image
Mario Coppo, Elena Lodi Theoretical Computer Science
Publisher: 2005 ISBN: 9783540291060 Edition: Unknown

Document information

Uploaded on
July 2, 2025
Number of pages
28
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers
$2.70

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
tabithamwendwa73
3.5
(68)
Sold
413
Followers
82
Items
1162
Last sold
1 month ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions