100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Exam (elaborations)

COS3701 Assignment 2 (COMPLETE ANSWERS) 2025

Rating
-
Sold
5
Pages
28
Grade
A+
Uploaded on
02-07-2025
Written in
2024/2025

COS3701 Assignment 2 (COMPLETE ANSWERS) 2025











Whoops! We can’t load your doc right now. Try again or contact support.

Document information

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

Subjects

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→ϵ

Get to know the seller

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 Chamberlain College Nursing
View profile
Follow You need to be logged in order to follow users or courses
Sold
379
Member since
1 year
Number of followers
82
Documents
1032
Last sold
1 month ago
brilliant tutorials

brilliant tutorials Attention all students! Are you struggling with a particular subject or just need some extra support to help you succeed? Look no further than our expert tutorial services! Our experienced tutors provide personalized one-on-one sessions to help you overcome your academic challenges and reach your full potential. Whether you need help with any module, our tutors are here to help. With flexible scheduling and competitive pricing, there\'s no reason to struggle on your own. Invest in your academic success today and book a tutorial session with us

Read more Read less
3,6

64 reviews

5
28
4
14
3
3
2
4
1
15

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

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

Didn't get what you expected? Choose another document

No worries! You can immediately select a different document that better matches what you need.

Pay how you prefer, start learning right away

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

Student with book image

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

Alisha Student

Frequently asked questions