You are on page 1of 16

lOMoARcPSD|8462104

COS2601 2020 1 102 - The assignments for the first


semester of 2020
Theoretical Computer Science 2 (University of South Africa)

StuDocu is not sponsored or endorsed by any college or university


Downloaded by Khensani Malazi (khensaniprincessmalaz@gmail.com)
lOMoARcPSD|8462104

COS2601/102/1/2020

Tutorial letter 102/1/2020

Theoretical Computer Science II


COS2601

Semester 1

School of Computing

This tutorial letter contains the assignments for semester 1

BARCODE

Downloaded by Khensani Malazi (khensaniprincessmalaz@gmail.com)


lOMoARcPSD|8462104

COS2601/102/1/2020

Dear student

Hope you are well on your way to familiarise yourself with the content of COS2601. This tutorial letter
contains the three assignments for the first semester. Best wishes for your COS2601 studies!

Regards
COS2601 team

SEMESTER 1 - ASSIGNMENT 1
Material to be tested Cohen, Chapters 1 – 4

Additional material Learning Units 1 – 4

Submission procedure Mark-reading sheet or electronic submission via myUnisa

Weight towards semester mark 20%

Note: In all questions where some given languages are mentioned, they are defined over {a b} unless
otherwise stated.

Question 1

Consider the language S*, where S = {ba bab bba}. Which one of the following words is in this language?

1. bbababb
2. babbaababa
3. babbbabbbabba
4. bababab

Question 2

Which one of the following is an example of two sets S and T of strings such that S  T and T  S, but S*
≠ T*?

1. S = {a, ab, bb} and T = {a, ab, ba, bb}


2. S = {a, aaa} and T = {a, aaa, aaaa}
3. S = {a, b} and T = {a, b, ab}
4. S = {a, b, ab, bb} and T = {a, b, ba, bb}

Downloaded by Khensani Malazi (khensaniprincessmalaz@gmail.com)


lOMoARcPSD|8462104

COS2601/102/1/2020

Question 3

Consider the language S*, where S = {bb, bab}. Which one of the following words is not in the language
S*?

1. bbabb
2. babbb
3. bbbab
4. babbabbb

Question 4

Which one of the following is an example of a set S such that the language S* has less 5-letter words than
3-letter words?

1. S = {aaa, ba, a}
2. S = {aaa, aa, bb, a}
3. S = {aabba, aabb, bbb, aaa}
4. S = {babbb, b, bab}

Question 5

Consider the language EVENABAB over the alphabet ∑ = {a b} consisting of all words of even length that
contain the substring abab. Which one of the following is a suitable generator?

1. abab
2. ab
3. a
4. 

Question 6

Consider the language MultipleOfFourNotAAandB consisting of all words of a length which is divisible by
4 without a remainder that do not contain an aa-substring but contains a b-substring. Which one of the
following can be used as one of the generators of the language?

1. babababa
2. Λ
3. aaba
4. baba

Downloaded by Khensani Malazi (khensaniprincessmalaz@gmail.com)


lOMoARcPSD|8462104

COS2601/102/1/2020

Question 7

Which one of the following regular expressions generates a language equivalent to the language
generated by (ab + ba)*?

1. (abba)*
2. ((ab)*(ba)*)*
3. (a + b)*
4. (aa + ab)*ba

Question 8
Which one of the following regular expressions defines the language of all strings that ends on an a- or an
abbb-substring?

1. (a + b)*a + (a + b)*bbb
2. (a + b)*a(a + b)*bbb(a + b)*
3. (a + b)*a( + bbb)
4. (a + b)*(a + bbb)

Question 9

Which one of the following words cannot be generated by the regular expression?
(b + a)*(ab + ba)(b) ?

1. abbabbb
2. babbbabab
3. baabbbbbab
4. babb

Question 10

Which one of the following regular expressions generates a language equivalent to the language
generated by the regular expression?

aaa*[(ab + babab)(a + b)* + ba]

1. aaa*(ab + babab)(a + b)* + ba(a + b)*


2. aaa*[ab(a*b*)* + babab)(a*b*)* + ba]
3. [aaa*ab + aaa*babab](a + b)* + ba
4. (a + b)* + ba

Downloaded by Khensani Malazi (khensaniprincessmalaz@gmail.com)


lOMoARcPSD|8462104

COS2601/102/1/2020

SEMESTER 1 - ASSIGNMENT 2
Material to be tested Cohen, Chapters 3 – 6

Additional material Learning Units 3 – 6

Submission procedure Written solution in assignment cover or electronic submission via


myUnisa

Weight towards semester mark 60%

Provide detailed solutions to all questions. It is possible that not all these questions will be marked. We
will decide in advance which of them (or all) to mark and you will not be informed in advance about the
decision.

Note: In all questions where some given languages are mentioned, they are defined over {a b} unless
otherwise stated.

Question 1

A recursive definition for the language ODDnotAB over the alphabet ∑= {a b} must be compiled where
ODDnotAB has as elements all words that are of odd length and do not contain the ab-substring.
Give
(i) an appropriate universal set,
(ii) the generator(s) of ODDnotAB, and
(iii) an appropriate function on the universal set, and then
(iv) use these concepts to write down a recursive definition of the language ODDnotAB.

Question 2

This question has three parts and tests mathematical induction.

(i) Give a recursive definition of the set P of all positive integers greater than 0,
(ii) formulate the appropriate induction principle, and then
(iii) use mathematical induction to prove that

11 + 15 + 19 + … + (4n + 7) = 2n2 + 9n

for all positive integers n > 0.

Question 3

Construct a regular expression that defines the language M (say) containing all words with either exactly
one single a-substring or all words with only ab-substrings. (Words such as aa, aabaab, aabbbaaabbb and
Λ do not belong to M.)

Downloaded by Khensani Malazi (khensaniprincessmalaz@gmail.com)


lOMoARcPSD|8462104

COS2601/102/1/2020

Question 4

Construct a regular expression that defines the language L containing all the words with either exactly one
aba-substring or exactly one bab-substring but not both aba- and bab-substrings.
(Hint: For example, the word abab does not belong to L.)

Question 5

Build an FA that accepts the language P consisting of all words with no aa-substring.

Question 6

Build an FA that accepts the language consisting of only those words that do not end in ab.

Question 7

a TG which accepts the language of all strings consisting of at least 4 characters such that the next-to-last
letter is identical to the second letter. Use as few states as possible.

Downloaded by Khensani Malazi (khensaniprincessmalaz@gmail.com)


lOMoARcPSD|8462104

COS2601/102/1/2020

SEMESTER 1 - ASSIGNMENT 3
Material to be tested Cohen, Chapters 7 – 11

Additional material Learning Units 7 – 11

Submission procedure Mark-reading sheet or electronic submission via myUnisa

Weight towards semester mark 20%

Note: In all questions where some given languages are mentioned, they are defined over {a b} unless
otherwise stated.

Question 1

Kleene's theorem should be used to find a regular expression that generates the language accepted by
the following TG (Transition Graph):

b a, b

aa
z1 z2
bab ^
^
- b ab +
bb ^
^
z6 a z4 b

In the process, states are eliminated until only the start and end states
are left with an edge connecting them and with a label that represents the required regular expression.
Which one of the following is not a label of a required path when state z2 is eliminated?

1. (aa + bab)(a + b)*


2. (b + ab)(a + b)*
3. b(a + b)*bb
4. ab(a + b)*bb

Downloaded by Khensani Malazi (khensaniprincessmalaz@gmail.com)


lOMoARcPSD|8462104

COS2601/102/1/2020

Question 2

Consider the following FA with the regular expression r:

–w1

b a a, b

b
w2 +w3

By applying Kleene’s theorem, an FA must be built for the regular expression r*. In the process a transition
table is compiled. Which one of the following tables is the correct table in the solution for this problem?

1.
New state Read an a Read an b
±z1 = w1 z2 z3
z2 = w1 z2 z3
z3 = w2 z2 +z4
+z4 = w1 or w3 +z4 +z5
+z5 = w1 or w2 or w3 +z4 +z5

2.
New state Read an a Read an b
z1 = w1 z1 z2
z2 = w2 z1 +z3
+z3 = w1 or w3 +z3 +z4
+z4 = w1 or w2 or w3 +z3 +z4

3.
New state Read an a Read an b
±z1 = w1 ±z1 z2
z2 = w2 ±z1 +z3
+z3 = w1 or w3 +z3 +z4
+z4 = w1 or w2 or w3 +z3 +z4

4.
New state Read an a Read an b
z1 = w1 z1 z2
z2 = w2 z1 +z3
+z3 = w3 +z3 +z3

Downloaded by Khensani Malazi (khensaniprincessmalaz@gmail.com)


lOMoARcPSD|8462104

COS2601/102/1/2020

Question 3

Consider the following Moore machine:

q0 /0 b q2 /1

a a a
b

a
q1 /1 q3 /1 b
b

What is the output if the input string is abbbaabab?

1. 11110111
2. 011110111
3. 111110111
4. 0111110111

Question 4

Consider the following Mealy machine:

a/0
q0 q2
b/1

a/1 a/1 b/0

b/0
q1 q3
b/1
a/0

The given Mealy machine must be converted to a Moore machine. Which one of the diagrams provided in
the following options represents the required Moore machine?

Downloaded by Khensani Malazi (khensaniprincessmalaz@gmail.com)


lOMoARcPSD|8462104

COS2601/102/1/2020

1.

q0 /0 b q2 /1
a a
b
q21 /0 a
a q1 3 /1 b
a a
b
a q23 /0
q11 /1 b

2.

q0 /0 b q2 /1
a a
a b
q21 /0
a q1 3 /1 b
a b
b q23 /0
b
q11 /1 a

3.

q0 /0 b q2 /1
a a
q21 /0 b
a b
a
b q3 /1
b
q1 1 /1 a

4.

q0 /0 b q2 /1
a

a b b

a
q3 /1
b
q1 /1 a

10

Downloaded by Khensani Malazi (khensaniprincessmalaz@gmail.com)


lOMoARcPSD|8462104

COS2601/102/1/2020

Question 5

The set of regular languages is closed under (a) certain operation(s). Which one of the following
alternatives provides (all) this/these possible operation(s)?

1. Only intersection and union.


2. Only concatenation.
3. Only Kleene closure.
4. Intersection, union, concatenation, complementation and Kleene closure.

Question 6

The following FAs are provided for given regular expressions:

FA1 for (b + ab)*(a + Λ):

b
+ x2 a, b
b
± x1
b a x4

a
+ x3
a

and

FA2 for (a + b)*aa(a + b)*:

b a, b
a
a
- y2 +
y1 y3
b

11

Downloaded by Khensani Malazi (khensaniprincessmalaz@gmail.com)


lOMoARcPSD|8462104

COS2601/102/1/2020

Which one of the following FAs represents FA1 ∩ FA2?


1.

+z2
a

-z1
a a, b

b
z3
b

2.

z2
a

-z1
a a, b

b
+z3
b

3.

z2
a a a, b

-z1 z4
a b

b
z3
b

4.

z2
a a a, b

-z1 +z4
a b

b
z3
b

12

Downloaded by Khensani Malazi (khensaniprincessmalaz@gmail.com)


lOMoARcPSD|8462104

COS2601/102/1/2020

Question 7

Which one of the following statements regarding nonregular languages is true?

1. The language {baban, with n  {2, 3, 4, ...}, n ∈ ℤ} can be generated by the regular expression baba*.
2. There exists an FA that accepts the nonregular language {banc, with n  {1, 3, 4, ...}, n ∈ ℤ}.
3. If a finite set of words is added to a nonregular language, the result is a nonregular language.
4. {anbn} = a*b*.

Question 8

The following question is given: Use the Pumping Lemma with length to prove that the following language
is nonregular:

L = {babn-2an, with n  {3, 4, 5, ...}, n ∈ ℤ}.

The solution to this question is partly given as follows:

Assume L = {babn-2an, where n  {3, 4, 5, ...}, n ∈ ℤ} is regular.


Then there exists an FA with, say k states that accepts L.

Let w = babk-2ak be a word in L.

According to the pumping lemma, w may be written as


w = xyz such that
length(x) + length(y) ≤ k AND length(y) > 0

Which one of the following is not one of the possible correct choices for y?

1. y comprises the a in between b and bk-2.


2. y comprises the first ba-substring.
3. y comprises ba followed by possible b’s.
4. y comprises ba followed by a possible second ba substring.

Question 9

Refer to Theorem 20, page 216 of Cohen.

By applying the decision procedure described in the theorem proof to the following FA, what will the
conclusion be?

b
a a a, b

- b a

b a, b b
+

13

Downloaded by Khensani Malazi (khensaniprincessmalaz@gmail.com)


lOMoARcPSD|8462104

COS2601/102/1/2020

1. Words with the following length


6 ≤ length of string < 12
will be accepted.
Thus the language is finite.

2. Words with the following length


6 ≤ length of string < 12
will be accepted.
Thus the language is infinite.

3. Words with the following length


6 ≤ length of string < 12
will not be accepted.
Thus the language is finite.

4. Words with the following length


6 ≤ length of string < 12
will not be accepted.
Thus the language is infinite.

Question 10

The blue paint procedure must be applied to determine whether or not the following FA accepts any words:
a
a
a a
- b a b +
b
b b
b a

Which one of the following diagrams represents the final diagram in the solution to the given problem?

1.

- +

14

Downloaded by Khensani Malazi (khensaniprincessmalaz@gmail.com)


lOMoARcPSD|8462104

COS2601/102/1/2020

2.

a
a
- +

3.

- +

4.

a
a
- +
b
b
b a

UNISA
©
2019

15

Downloaded by Khensani Malazi (khensaniprincessmalaz@gmail.com)

You might also like