• ¿Documento equivocado? Cámbialo gratis
  • Escrito por estudiantes que aprobaron
  • Inmediatamente disponible después del pago
  • Leer en línea o como PDF
Vender
¿Dónde estudias?
Tu idioma
Document preview thumbnail
Vista previa 5 fuera de 20 páginas
Examen

COS3701 Assignment 3 |Theoretical Computer Science III | 2026

Document preview thumbnail
Vista previa 5 fuera de 20 páginas

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.

Vista previa del contenido

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

Libro relacionado
 image
Editorial: 2020 ISBN: 9781000154603 Edición: Desconocido

Información del documento

Subido en
9 de mayo de 2026
Número de páginas
20
Escrito en
2025/2026
Tipo
Examen
Contiene
Preguntas y respuestas
$3.91

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
BeeNotes
4.1
(40)
Vendido
352
Seguidores
0
Artículos
1012
Última venta
1 semana hace

Reseñas de compradores verificados




Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes