• ¿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 3 fuera de 28 páginas
Examen

Cos3701 Assignment 2 (Complete Answers) 2025

Document preview thumbnail
Vista previa 3 fuera de 28 páginas

COS3701 Assignment 2 (COMPLETE ANSWERS) 2025

Vista previa del contenido

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

Libro relacionado
 image
Mario Coppo, Elena Lodi Theoretical Computer Science
Editorial: 2005 ISBN: 9783540291060 Edición: Desconocido

Información del documento

Subido en
2 de julio de 2025
Número de páginas
28
Escrito en
2024/2025
Tipo
Examen
Contiene
Preguntas y respuestas
$2.70

¿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.
tabithamwendwa73
3.5
(68)
Vendido
413
Seguidores
83
Artículos
1162
Última venta
3 meses hace



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