100% tevredenheidsgarantie Direct beschikbaar na je betaling Lees online óf als PDF Geen vaste maandelijkse kosten 4,6 TrustPilot
logo-home
Tentamen (uitwerkingen)

COS2601 Exam pack 2025(Theoretical Computer Science II)

Beoordeling
-
Verkocht
-
Pagina's
213
Cijfer
A+
Geüpload op
24-01-2025
Geschreven in
2024/2025

COS2601 Exam pack 2025(Theoretical Computer Science II)

Instelling
Vak











Oeps! We kunnen je document nu niet laden. Probeer het nog eens of neem contact op met support.

Geschreven voor

Instelling
Vak

Documentinformatie

Geüpload op
24 januari 2025
Aantal pagina's
213
Geschreven in
2024/2025
Type
Tentamen (uitwerkingen)
Bevat
Vragen en antwoorden

Onderwerpen

Voorbeeld van de inhoud

COS2601 EXAM PACK
2025

QUESTIONS AND
ANSWERS
FOR ASSISTANCE CONTACT
EMAIL:

, lOMoARcPSD|50013335




COS2601 Example exam paper

EXAMPLE EXAMINATION PAPER and SOLUTIONS

QUESTION 1: Languages [10]

(a) Let S = {a, bb, bab, abaab}. For each of the following strings, state whether or not it is a word in
S*:

(i) abbabaabab
(ii) abaabbabbbaabb (2)

(i) No, because there are no concatenations of a, bb, bab and abaab that will yield the word
abbabaabab.

(ii) Yes, concatenations of a, bb, bab and abaab will yield the word: (abaab)(bab)(bb)(aa)(bb).

(b) Give an example of a set S such that S* only contains all possible strings of combinations of a’s
and b’s that have length divisible by three. (4)

There is only one possible set S: S = {aaa, aab, aba, abb, baa, bab, bba, bbb}. All the words in S* are
multiples of three as all the words of S are of length exactly 3.

(c) Give an example of two sets S and T of strings such that
S* = T* but S ⊄ T and T ⊄ S. (4)

We give two possible answers, there are many other possibilities:
S = {Λ, a} and T = {a, aa} or S = {a, b, ab} and T = {a, b, ba}.


QUESTION 2: Regular expressions [10]

(a) Does the regular expression
[b*+ (abb*)* + (aabb*)*]* bbb [b* + (abb*)* + (aabb*)*]*
define the language of all words in which the substring bbb appears at least once, but the
substring aaa does not appear at all? If not, give a counter-example. (5)

It is indeed the case that all words generated by the given regular expression contain the substring bbb.
It is furthermore the case that no word generated by the given regular expression contains the substring
aaa. However, not all such words (i.e. words containing the substring bbb but not the substring aaa) can
be generated by the given regular expression. Some examples are:
babbb
aabbb
bbba.
The answer to this question is thus no, and the words above serve as counterexamples.

(b) Give a regular expression generating the language consisting of all words containing exactly one
occurrence of the substring aa and no occurrence of the substring bb. (5)

The regular expression that we need to give, must make provision for words that start (and end) with
either an a or a b. All occurrences of the letter b (except if it is the last letter of the word) must be
followed by an a. Furthermore, only one a may be followed by another a - in order to ensure only one
occurrence of the substring aa. A possible regular expression is:
(b + Λ)(ab)*aa(ba)*(b + Λ)
This is of course not the only possibility.



1

, lOMoARcPSD|50013335




COS2601 Example exam paper

QUESTION 3: Recursive definitions [10]

A recursive definition for the language ODDAB should be compiled. Consider the alphabet ∑ = {a, b} and
the language ODDAB, where ODDAB consists of all words of odd length that contain the substring ab.
Provide

(i) an appropriate universal set, (1)
(ii) the generator(s) of ODDAB, (2)
(iii) an appropriate function on the universal set, and then (1)
(iv) use these concepts to write down a recursive definition for the language ODDAB. (6)

(i) The set {a, b}* will be suitable because it contains, along with other words, all the words that are
in the language ODDAB.

(ii) The generators should be the smallest words in ODDAB of odd length and should contain the
substring ab. Thus,
aba, aab, abb, bab
will be suitable generators.

(iii) The function CONCAT as defined in the study guide will be suitable.

(iv) We give two possible recursive definitions. Note that all words in ODDAB should have an odd
number of letters. The generators all have an odd number of letters; therefore, to keep the length
of new words odd, we concatenate two letters at a time. Note, the generator(s) is/are always the
smallest word(s) in a language.

ODDAB is the smallest subset of {a, b}* such that
aba, aab, abb, bab ∈ ODDAB, and if w ∈ ODDAB,
then also CONCAT(w,aa), CONCAT(w,bb), CONCAT(w,ab), CONCAT(w,ba),
CONCAT(aa,w), CONCAT(bb,w), CONCAT(ab,w), CONCAT(ba,w) ∈ ODDAB.

Or an alternative definition:
Rule 1: aba, aab, abb, bab ∈ ODDAB.

Rule 2: If w ∈ ODDAB, then also CONCAT(w,aa), CONCAT(w,bb), CONCAT(w,ab),
CONCAT(w,ba), CONCAT(aa,w), CONCAT(bb,w), CONCAT(ab,w),
CONCAT(ba,w) ∈ ODDAB.

Rule 3: Only words produced by rules 1 and 2 are in ODDAB.


QUESTION 4: Mathematical induction [10]

(i) Give a recursive definition of the set P of all positive integers greater than or equal to 5,
(1)
(ii) formulate an appropriate induction principle, and (2)
(iii) then apply the induction principle to prove that
2n – 3 ≤ 2n-2 for all integers n ≥ 5. (7)

(i) P is the smallest subset of Z (the set of integers) such that 5 ∈ P and if n ∈ P, then also n + 1 ∈ P.

(ii) If a subset A of P is such that 5 ∈ A and if n ∈ A, then also n + 1 ∈ A, then A = P.

(iii) Define A ⊆ P as follows:
A = {n ∈ P | 2n – 3 ≤ 2n-2}

2

, lOMoARcPSD|50013335




COS2601 Example exam paper

Show for n = 5
2(5) - 3 ≤ 25 - 2
i.e. 7 ≤ 8
Thus, 5 ∈ A is true.

Assume k ∈ A, i.e. we assume that 2k – 3 ≤ 2k – 2

Required to prove that k + 1 ∈ A, i.e. 2(k + 1) –3 ≤ 2(k + 1) – 2.

LHS
= 2(k + 1) – 3
= 2k + 2 – 3
= (2k – 3) + 2
≤ 2k – 2 + 2 (from induction assumption (1))
≤ 2⋅2 k – 2 (because the smallest value for 2 k – 2 with k = 5
is 2 5 – 2 = 8 and 2⋅8 = 16 > 10 = 25 – 2 + 2)
1+k–2
=2
= 2 (k +1) – 2 = RHS

Thus k + 1 ∈ A
Hence, A = P so we conclude that 2n - 3≤ 2n -2
for all integers n ≥ 5.


QUESTION 5: Finite automata [10]

Build an FA (finite automaton) that accepts the language of all words that satisfies both of the following
conditions:
• NO word contains the substring bba, and
• ALL words end with a double letter, thus all words end with either aa or bb.
Note: Only one FA must be build.

NOTE: If you provide a nondeterministic finite automata (NFA) or transition graph (TG) for (c), the
maximum mark you may be awarded is 2. Ensure that you build a deterministic FA.

CAI tutorial: Remember to use the CAI tutorial Automata available on CD or downloadable
from the web. In preparation to this question, you can navigate through all the sections in the
tutorial. Graphical illustrations are also provided. (Please refer to section 1 in this tutorial letter.)

We do not need to keep track of the number of letters that have been read at any stage - even or odd is
irrelevant for this question. A dead-end state is necessary to make provision for all words containing the
bba-substring. You should further keep in mind that words ending on aaa or bbb are, of course, also
permissible.

From the initial state 1, we move to state 2 with an a and to state 3 with a b. From state 2, we move to a
final state 4 with an a and if we read an a in the final state, we stay in the final state, because words such
as aaa and aaaa are permissible words in the language. From state 3, we move to a final state, state 5,
with a b and if we read a b in the final state, we stay in the final state, because words such as bbb and
bbbb are permissible words in the language. If, however, we read an a in state 5, we move to a dead-
end state, state 6, from which we cannot leave because then the word contains the impermissible
substring bba. The incomplete FA is given below:




3

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.
gabrielmusyoka940 db
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
1474
Lid sinds
2 jaar
Aantal volgers
247
Documenten
1488
Laatst verkocht
11 uur geleden
Bstudy

provides latest exam paper

3,2

217 beoordelingen

5
68
4
30
3
49
2
20
1
50

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

Veelgestelde vragen