Geschreven door studenten die geslaagd zijn Direct beschikbaar na je betaling Online lezen of als PDF Verkeerd document? Gratis ruilen 4,6 TrustPilot
logo-home
Tentamen (uitwerkingen)

COS3701 Assignment 3 |Theoretical Computer Science III | 2026

Beoordeling
-
Verkocht
-
Pagina's
20
Cijfer
A+
Geüpload op
09-05-2026
Geschreven in
2025/2026

This assignment has been carefully put together to give you more than just answers; it walks you through the reasoning behind each one, so you actually understand the material rather than just memorising it. Every solution has been verified for accuracy, with academic references that hold up to scrutiny. Whether you're working through it the night before a submission or using it to reinforce your understanding over time, it's built to be genuinely useful. The explanations are clear without being condescending, and the structure follows what examiners actually look for not just what sounds impressive. If you put in the effort to engage with it properly, distinction-level results are well within reach.

Meer zien Lees minder
Instelling
Vak

Voorbeeld van de inhoud

UNIVERSITY OF SOUTH AFRICA
School of Computing


⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄⋄


COS3701: Theoretical Computer Science III

Assignment 3 — Semester 1, 2026

⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄⋄




COS3701
Module Code:
Theoretical Computer Science III
Module Name:
Assignment 3
Assignment:
2026
Due Date:
50
Total Marks:




Submitted in partial fulfilment of the requirements for COS3701 — UNISA 2026

,UNISA | COS3701 Assignment 3 – 2026



Question 1: Union of Context-Free Grammars using Theorem 36


Question (Restated)


Let L1 be the grammar generating (a + b)∗ . Let L2 be the grammar generating (aa)∗ b(a +
b)∗ . First provide the grammars generating L1 and L2 respectively. Then apply the applicable
theorem from Chapter 17 (Theorem 36) to determine L1 + L2 .


Step 1: Grammar for L1 = (a + b)∗


The language L1 is the set of all strings over {a, b}, including the empty string ε.

Grammar G1 :



G1 : S1 → aS1 | bS1 | ε


This grammar allows S1 to produce any sequence of a’s and b’s (in any order), followed by ε
to terminate. Therefore G1 generates (a + b)∗ .


Step 2: Grammar for L2 = (aa)∗ b(a + b)∗


The language L2 consists of strings that begin with zero or more occurrences of aa, followed
by exactly one b, followed by any string over {a, b}.

We build this grammar in parts.

Part A – generating (aa)∗ :
A → aaA | ε


Part B – generating (a + b)∗ :

We reuse the same structure as S1 above:


B → aB | bB | ε



Combined grammar G2 :




Page 2 of 20

,UNISA | COS3701 Assignment 3 – 2026




G2 : S2 → AbB

A → aaA | ε

B → aB | bB | ε


Reading this: S2 expands to AbB. The non-terminal A produces zero or more pairs aa, then
the literal b appears in the middle, and B produces any string over {a, b} to the right. There-
fore G2 generates (aa)∗ b(a + b)∗ .


Step 3: Applying Theorem 36 (Union of Context-Free Languages)


⋆ Key Distinction
Theorem 36 (Union): If L1 is generated by grammar G1 = (V1 , Σ, P1 , S1 ) and L2 is
generated by grammar G2 = (V2 , Σ, P2 , S2 ), where V1 ∩V2 = ∅, then L1 +L2 is generated
by the grammar G obtained by adding a new start symbol S and the two productions
S → S1 | S2 , combining all productions of G1 and G2 .


Therefore, the grammar G for L1 + L2 is constructed as follows.

We first ensure variable sets are disjoint. Renaming G2 ’s variables as needed (they are already
disjoint since we used different names), we introduce a new start symbol S and add the pro-
duction S → S1 | S2 .

Grammar G for L1 + L2 :



S → S1 | S2

S1 → aS1 | bS1 | ε

S2 → AbB

A → aaA | ε

B → aB | bB | ε


Explanation of each production:




Page 3 of 20

,UNISA | COS3701 Assignment 3 – 2026


• S → S1 – the derivation follows G1 , producing any word in (a + b)∗ .
• S → S2 – the derivation follows G2 , producing any word in (aa)∗ b(a + b)∗ .
• The final language is L(G) = L1 ∪ L2 = (a + b)∗ ∪ (aa)∗ b(a + b)∗ .

✓ Implementation Insight
Since L1 = (a + b)∗ already contains every string over {a, b}, the union L1 ∪ L2 is simply
(a + b)∗ itself. However, the formal exercise of applying Theorem 36 and construct-
ing the combined grammar is the required demonstration. The grammar above is the
correct formal answer.




Page 4 of 20

, UNISA | COS3701 Assignment 3 – 2026



Question 2: Applying Theorem 42 – Does the Grammar Generate Any Words?


Question (Restated)


Use the Theorem 42 algorithm to determine whether the following grammar generates any
words.



S → XS

X →YX

Y →YY

Y → XX

X→a


Background: Theorem 42 Algorithm


⋆ Key Distinction
Theorem 42 provides an algorithm to determine whether a context-free grammar
(CFG) generates any word at all. The algorithm identifies all productive non-terminals,
i.e., those that can eventually derive at least one terminal string. A grammar generates
a non-empty language if and only if its start symbol is productive.
Algorithm (iterative):

1. Mark any non-terminal A as productive if it has a production A → w where w con-
tains only terminals (or ε).
2. Repeat: mark any non-terminal A as productive if it has a production A → α
where every symbol in α is either a terminal or an already-marked productive non-
terminal.
3. Stop when no new non-terminals can be marked.
4. The grammar generates a word if and only if the start symbol is marked produc-
tive.




Page 5 of 20

Gekoppeld boek

Geschreven voor

Instelling
Vak

Documentinformatie

Geüpload op
9 mei 2026
Aantal pagina's
20
Geschreven in
2025/2026
Type
Tentamen (uitwerkingen)
Bevat
Vragen en antwoorden

Onderwerpen

$3.91
Krijg toegang tot het volledige document:

Verkeerd document? Gratis ruilen Binnen 14 dagen na aankoop en voor het downloaden kun je een ander document kiezen. Je kunt het bedrag gewoon opnieuw besteden.
Geschreven door studenten die geslaagd zijn
Direct beschikbaar na je betaling
Online lezen of als PDF

Maak kennis met de verkoper

Seller avatar
De reputatie van een verkoper is gebaseerd op het aantal documenten dat iemand tegen betaling verkocht heeft en de beoordelingen die voor die items ontvangen zijn. Er zijn drie niveau’s te onderscheiden: brons, zilver en goud. Hoe beter de reputatie, hoe meer de kwaliteit van zijn of haar werk te vertrouwen is.
BeeNotes teachmetutor
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
313
Lid sinds
11 maanden
Aantal volgers
0
Documenten
861
Laatst verkocht
6 dagen geleden
BeeNotes

BeeNotes: Buzzing Brilliance for Your Studies Discover BeeNotes, where hard-working lecture notes fuel your academic success. Our clear, concise study materials simplify complex topics and help you ace exams. Join the hive and unlock your potential with BeeNotes today!

4.1

39 beoordelingen

5
23
4
4
3
8
2
1
1
3

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Bezig met je bronvermelding?

Maak nauwkeurige citaten in APA, MLA en Harvard met onze gratis bronnengenerator.

Bezig met je bronvermelding?

Veelgestelde vragen