Você está na página 1de 15

COS2601/201/1/2014

Tutorial Letter 201/1/2014


Theoretical Computer Science 2

COS2601
Semester 1
School of Computing
Discussion of Assignment 01.

Dear Student,
Solutions to the questions of assignment 01 are provided in this tutorial letter.
Regards,
COS2601 team.
Note: Solutions to selected problems in the prescribed book are provided towards the end of the
study guide.
Question 1
What does Gdels Incompleteness Theorem imply?
1. Some problem solving approach is certain and without any reliance on unpredictable and
undependable mathematical insight.
2. Some contradictions exist in what seems to be rigorously proven mathematical theorems.
3. In a specific mathematical system there are either some true statements without any possible
proof or else there are some false statements that can be proven.
4. There are problems that no algorithm can solve.
Answer 1: Option 3
In 1931 Kurt Gdel proved that there was no algorithm to provide proofs for all true statements in
mathematics. In fact, he proved that in a specific mathematical system there are either some true
statements without any possible proof or else there are some false statements that have proofs for
their correctness, ie can be proven. He laid the foundation for Alonzo Church, Stephen Kleene,
Emil Post, Andrei Andreevich Markov, John von Neumann and Alan Turing who researched which
mathematical statements do have proofs. Thus option 3 should be selected.
Gdel attended to proofs of statements and not to problem solving. The statements in options 1
and 4 deals with problem solving and not with providing proofs for statements. Option 2 refers to
work done by Georg Cantor.
Refer to Cohen, pp 3 - 5.

COS2601/201
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, b, ab, bb} and T = {a, b, ba, bb}
2. S = {a, aaa} and T = {a, aaa, aaaa}
3. S = {a, b} and T = {a, b, ab}
4. S = {a, ab, bb} and T = {a, ab, ba, bb}
Answer: Option 4
Discussion
Firstly we should remember that for any sets A and B, A = B iff A B and B A.
(A B iff each element of A is also an element of B.)
Option 1
Let S = {a, b, ab, bb} and T = {a, b, ba, bb}. It holds for sets T and S that T S since ba is an
element of T and not of S. It is also the case that S T since ab is an element of S but not of T.
However, it is true that S* = T*. Both set S and set T contain the words a and b. Thus T* = S* = {a,
b}* = { , a, b, aa, bb, ab, ba, aaa, bbb, abb, bba, aab, baa,}, comprising all possible
concatenations of as and bs, together and separately, and is also a word in S* and T*.
Consequently option 1 should not be selected.
Option 2
Let S = {a, aaa} and T = {a, aaa, aaaa}. In this case S* = T* = {a}* = { , a, aa, aaa, aaaa,}. Thus
this option 2 should not be selected although T S and S T. The reason for this is that aaaa is
an element of T but not of S and all the elements in S are also elements of T.
Option 3
Let S = {a, b} and T = {a, b, ab}. In this case it is true that T S. T contains the word ab which is
not an element of S. It holds that S T since each element of S is also an element of T.
However, it is true that S* = T* = {a, b}*. Option 3 should not be selected.
Option 4
S = {a, ab, bb} and T = {a, ab, ba, bb}. Again T S. T contains the word ba which is not an
element of S. S T, ie all the words belonging to S are also elements of T. For option 4 it also
holds that S* T*. We provide a counterexample to prove that S* T*: the word babb is an
element of T* but not of S*. Thus option 4 should be selected.

Question 3
Consider the language S*, where S = {abb, abba, a}. Which one of the following words does not
belong to S*?
1. aaabbaabb
2. abbaaabbabbb
3. abbabbaaaabba
4. aaabbaaaaa
Answer: Option 2
Discussion
In order to prove that a certain word is in a closure language R* (say), we must show how it can be
written as a concatenation of words from the base set R. The words in R* comprises all possible
concatenations of words in R, together and separately, and is also a word in R*.
In order to answer this question we shall illustrate how all the words provided in the options,
except one, can be generated by concatenating the building blocks a, abba and abb (words
belonging to S).
Option 1
It is possible to generate the word aaabbaabb by firstly concatenating a to itself. Thereafter abba
should be concatenated to aa to obtain the string (a)(a)(abba). Finally add the word abb. Thus we
can factor the required word: (a)(a)(abba)(abb). Therefore option 1 should not be selected.
Option 2
In order to generate abbaaabbabbb we firstly have to concatenate abb to aa where aa is
obtained by concatenating a to itself. Thus we have (abb)(a)(a). Next we should concatenate abb
to abbaa. This gives us (abb)(a)(a)(abb). Then concatenate abb again. Thus we obtain the word
(abb)(aa)(abb)(abb). It is impossible to concatenate a b to this string.
Alternatively, we can try to factor the given word as follows: (abba)(a)(abb)(abb) but then it is
impossible to concatenate a b to this string, or we can try (abba)(a)(abba) but then it is impossible
to concatenate a bb to this string. Note that all possible factorisations should be considered.
By inspection, if we consider our building blocks, then it is clear that three bs can never occur next
to each other by concatenating the words provided in S.
Consequently option 2 should be selected.
Option 3
It is possible to generate the word abbabbaaaabba by firstly selecting abb. Thereafter abba
should be concatenated to abb to obtain the string (abb)(abba). We should now concatenate aa,
ie a concatenated to itself. Finally concatenate the word abba to the string abbabbaaa. Thus we
can factor the required word: (abb)(abba)(a)(a)(abba). Thus option 3 should not be selected.
4

COS2601/201
Option 4
The word aaabbaaaaa can be generated by concatenating aa (ie two concatenations of a) to
abba and in turn concatenate aaaa (ie four concatenations of a) . Thus we have
(a)(a)(abba)(a)(a)(a)(a). Alternatively we can factor aaabbaaaaa as follows:
(a)(a)(abb)(a)(a)(a)(a)(a). Therefore option 4 should not be selected.
Question 4
Which one of the following is an example of a set S such that the language S* has more 8-letter
words than 5-letter words?
1. S = {babbb, aababbb}
2. S = {aaaaa, bb}
3. S = {bbbbb, bbb}
4. S = {aaa, bb}
Answer: Option 4
Discussion
Option 1
For S = {babbb, aababbb} it is the case that S* has more 5-letter words than 8-letter words. The
word babbb consits namely of 5 characters whereas the word aababbb has 7 letters. If we
consider the lengths of the words in S then it is clear that it is not possible to concatenate them in
any manner such that a word of length 8 can be generated. Concatenating two 5-letter words
results in a word of length 10 and 10 > 8. Concatenating a 5-letter word to a 7-letter word results in
a word with a length of 12 and 12 > 8. If we consider concatenating two 7-letter words then we end
up with words of length 14. Again 14 > 8. Thus option 1 should not be selected.
Option 2
For S = {aaaaa, bb} it is the case that S* has exactly as many 5-letter words as 8-letter words,
namely one word only. The only 5-letter word in S* is aaaaa. The only 8-letter word in S* can be
generated by concatenating bb four times. Thus bbbbbbbb, consisting of 8 letters, can be
generated. bb cannot be used to generate a 5-letter word any concatenations of bb to itself will
result in words with an even number of letters. Possible concatenations of bbs with aaaaas will
result in words with lengths longer than 5 but no word with length 8 can be generated. For
example, a possible 7-letter word is bbaaaaa, a possible 9-letter word is bbbbaaaaa and a
possible 12 letter word is bbaaaaaaaaaa, and so on. Therefore S* contains exactly as many 5letter words as 8-letter words exactly one word of each length. Option 2 should not be selected.
Option 3
Let S = {bbbbb, bbb}. Two words, consisting of bs only, are provided as building blocks to
generate words belonging to S*. The word bbbbb is the only word in S* consisting of 5 lettters.
The number of words consisting of 8 letters is also one namely bbbbbbbb which can be
generated by concatenating bbbbb to bbb. Therefore option 3 should not be selected.
5

Option 4
The words in S are aaa and bb. There are two 5-letter words in the closure of S, ie S*, namely
aaabb and bbaaa. There are, however, four words consisting of 8 letters namely bbbbbbbb (bb
concatenated four times), aaaaaabb (aaa concatenated twice and thereafter bb concatenated to
aaaaaa), aaabbaaa (aaa concatenated to bb and thereafter aaa concatenated to aaabb ) and
bbaaaaaa (bb concatenated to aaa and thereafter aaa concatenated to bbaaa). Thus S* has
more 8-letter words than 5-letter words. Consequently option 4 should be selected.
Question 5
Consider the language ODDAAnotB consisting of all words of odd length and containing the
substring aa but not the substring b. Which one of the following is a suitable generator?
1. a
2.
3. aaa
4. aab
Answer: Option 3
Discussion
The generator(s) of a language is/are the shortest word(s) belonging to the language. In the case
of ODDAAnotB a generator should not contain the b-substring, should contain the aa-substring
and be of odd length. This is important during the remainder of the discussion. To select the
correct answer one can ask three questions as follows:

Is the word to be considered of odd length?

Does the word contain the aa-substring?

Is the b-substring not included in the word?


If the answer to all these questions is yes then we know the given word belongs to ODDAAnotB.
All that remains to be considered is whether the word is one of the smallest words in the language
ODDAAnotB.
Option 1

Is a of odd length? --- Yes

Does a contain the aa-substring? --- No

Is the b-substring not included in the word? --- Yes

The answers to two of the posed questions are yes. However, the answer to the second question
is no. Consequently a is not a word in ODDAAnotB. The word a does not contain the aa-substring.
Therefore a cannot be a generator of ODDAAnotB. Option 1 should not be selected.

COS2601/201
Option 2

Is of odd length? --- No

Does contain the aa-substring? --- No

Is the b-substring not included in the word? --- Yes

The answers to two of the posed questions are no. Consequently is not a word in ODDAAnotB.
is of even length and does not contain the aa-substring. Therefore cannot be a generator of
ODDAAnotB. Thus option 2 should not be selected.
Option 3

Is aaa of odd length? --- Yes

Does aaa contain the aa-substring? --- Yes

Is the b-substring not included in the word? --- Yes

The answers to all the posed questions are yes aaa is of odd length, contains the aa-substring
and does not include the b-substring. Furthermore, aaa is also the shortest word in the language.
In fact ODDAAnotB = {aaa, aaaaa, aaaaaaa}. Thus by applying the recursive definition, the
CONCAT function as defined in the study guide together with the generator aaa can be used in
generating all the words in ODDAAnotB. Consequently option 3 should be selected.
Option 4

Is aab of odd length? --- Yes

Does aab contain the aa-substring? --- Yes

Is the b-substring not included in the word? --- No

The answers to two of the posed questions are yes. The answer to the final question is, however,
no. Consequently aab is not a word in ODDAAnotB. The word aab contains the b-substring.
Therefore aab cannot be a generator of ODDAAnotB.

Question 6
Consider the language ODDABnotendA, where ODDABnotendA consists of all words of odd
length that contain the substring ab but do not end on the substring a. A recursive definition for the
language ODDABnotendA should be compiled. abb, bab and aab are the generators, and the
CONCAT function is applied in defining a recursive definition for the language. We begin our
definition with:
ODDABnotendA is the smallest subset of {a,b}* such that
abb, bab, aab ODDABnotendA, and if w ODDABnotendA then.
Certain CONCAT operations which can generate all possible words belonging to ODDABnotendA
should now be provided.
Which one of the following is a possible CONCAT operation in this definition?
1. CONCAT(w, b)
2. CONCAT(aa, w)
3. CONCAT(w, ba)
4. CONCAT(w, a)
Answer: Option 2
Discussion
The generators of a language (as mentioned in question 5) are the shortest words belonging to the
language. In the case of ODDABnotendA a generator should not end in an a should contain the
ab-substring and be of odd length. These properties hold for all the words belonging to
ODDABnotendA. As the generators all contain the ab-substring we do not have to make provision
for the ab-substring to be included in all words. Thus to select the correct answer one can ask two
questions as follows:

Does the CONCAT function generate only words of odd length?

Do all the generated words end in a b?


If the answer to the first question posed is yes and the answer to the second question posed is
yes then we know the generating function is generating words belonging to ODDABnotendA.

Option 1
Consider CONCAT(w, b):
Does the generating function generate only words of odd length? --- No

Do all the generated words end in a b? --- Yes

The answer to the first question is no. Words are generated consisting of an even number of
letters. In the question statement it is given that w ODDABnotendA. It is the case that w consists
of an odd number of letters. If we concatenate an odd length of characters (w) to an odd length
string (b) then well be generating a new string of even length. (We can look at some words that
can be generated in this case: if w = abb then CONCAT(w, b) generates the word abb(b), or if
w = bbbbbab then CONCAT(w, b) generates the word bbbbbab(b). It is clear that the generated
words are of even length.) Note that all generated words will, however, end in a b. Option 1 should
not be selected.

COS2601/201
Option 2
Consider CONCAT(aa, w):

Does the generating function generate only words of odd length? --- Yes

Do all the generated words end in a b? --- Yes

The answer to the first question is yes. Words are generated consisting of an odd number of
letters. It is the case that w ODDABnotendA. If we concatenate an even length string (aa) to an
odd length of characters (w) then well be generating a new string of odd length. Furthermore we
are only concatenating letters, in this case, to the front of words already belonging to
ODDABnotendA thus all the words generated will still end in a b and generated words will not end
in an a. Consequently we may conclude option 2 should be selected.
Option 3
Consider CONCAT(w, ba):
Does the generating function generate only words of odd length? --- Yes

Do all the generated words end in a b? --- No

CONCAT(w, ba) will generate words ending in an a only, for example abb(ba). Note that the
length of the generated words is odd. Option 3 should not be selected.
Option 4
Consider CONCAT(w, a):

Does the generating function generate only words of odd length? --- No

Do all the generated words end in a b? --- No

The answer to both the posed questions is no. As explained for option 1, by concatenating a word
with an odd number of letters to a single letter string, the words generated will be of even length.
Furthermore, CONCAT(w, a) will generate words ending in an a only, for example abb(a). Option
4 should not be selected.

Question 7
Let S = {aaa, bbb} and T = {aba, bab}. Which one of the following statements is not true?
1. S* T* contains all possible strings of as and bs that have a length divisible by 3.
2. S* and T* contain the same number of 6 letter words.
3. S* {a, b}* and T* {a, b}*.
4. S* T* = {}.
Answer: Option 1
Option 1
For S* T* to possibly contain all possible strings of as and bs that have a length divisible by
three, S = {aaa, bbb} and T = {aba, bab} should have as members all the building blocks to
generate all the words in the required language. The number of words over = {a, b} with a length
of 3 is 23 = 8. We only have two words in S and two words in T, a total of four words. Thus from
this argument it is clear that the statement is option 1 is false. Only words in S concatenated to
themselves or words in T concatenated to themselves belong to the set S* T*. Thus no words
generated by concatenating words belonging to S to words belonging to T may belong to S* T*,
and no words generated by concatenating words belonging to T to words belonging to S may
belong to S* T*. By providing a counterexample we prove that S* T* does not have all the
required words as members: bbbbab S* T*. Option 1 should be selected as the statement
provided is false.
Option 2
Both S and T have as elements two words consisting of 3 letters each. The number of six letter
words that belong to S* is 22 = 4 and the same number of six letter words belong to T*. All the
possible 6-letter words belonging to S* are aaaaaa, aaabbb, bbbaaa and bbbbbb (ie all possible
concatenations of aaa and bbb), and all the possible 6-letter words belonging to T* are abaaba,
ababab, bababa and babbab (ie all possible concatenations of aba and bab). Thus S* and T*
contain the same number of six letter words. The statement presented by option 2 is true. Thus
option 2 should not be selected.
Option 3
The statement provided in this option is true. {a, b}* has as members and all the possible words
that can be generated by concatenating any number of as and any number of bs in any order to
one another. Thus inclusive of the set {a, b}* will be all the words that can be generated by
concatenating as and bs with a length such that the length is divisible by 3. Option 3 is true and
should not be selected.
Option 4
S T = 0/ = { } (empty set). Thus, although the words in both S and T are of length three, S* and
T* do not have any words in common apart from . Consequently the statement in option 4 is true
and should not be selected.

10

COS2601/201
Question 8
Which one of the following regular expressions does not define the language of all strings that
ends on an a?
1. (a + b)*a
2. b*aa*(bb*aa*)*
3. [a(ba)* + b(ab)*](a + b)*a
4. (b + aa*b)*a(a + bb*a)*
Answer: Option 3
Discussion
The best (simplest) way to prove that a certain regular expression does not generate a required
language is by providing a counterexample. Within our context a counterexample can either be a
word generated by a regular expression which does not belong to the required language, OR it
can be a word which cannot be generated by a given regular expression but which actually does
belong to the requested language. Most of the time it is meaningful to pay special attention to
some shortest words belonging to a certain language. In the case of the language under
consideration the shortest words are a, aa and ba.
Option 1
The regular expression provided in option 1 clearly generates all the words in the requested
language. (a + b)* ensures that any possible combination of as and bs, together or separately, or
can be generated. The final a in the regular expression (a + b)*a ensures that all words in fact
end in an a. Thus no word not belonging to the language can be generated. The given regular
expression indeed defines the language of all words that end on an a. Option 1 should not be
selected.
Option 2
The regular language generated by b*aa*(bb*aa*)* has as elements words ending in a only. The
word a is the shortest word in the language. The generated words can either begin with as or bs
any number of them. The aa* parts of the regular expression ensures that words will always end
in an a. The regular expression (bb*aa*)* generates words by concatenations of repeated factors
consisting of a b followed by a possible string of bs, followed by an a, and lastly followed by a
possible string of as; or can be generated. If is generated by (bb*aa*)* then the shortest word
generated by the b*aa* part is a. All possible words ending in an a are generated. Option 2 should
not be selected.
Option 3
In the case of option 3 well immediately ask the question whether the shortest word in the
language can be generated. Consider the given regular expression [a(ba)* + b(ab)*](a + b)*a: if
(ba)*, (ab)* and (a + b)* generate then the shortest words the expression can generate are aa
or ba. Thus the word a cannot be generated. Consequently we have found a counterexample.
Thus option 3 should be selected.
11

Option 4
Let us consider the regular expression (b + aa*b)*a(a + bb*a)*:
This regular expression generates words that begin with a possible string of concatenations of
repeated factors consisting of either a b, or an a followed by a possible string of as followed by a
b. This is followed by a single a and lastly possible strings of concatenations of repeated factors
consisting of either an a, or a b followed by a possible string of bs followed by an a.
We can divide the regular expression into part 1 and part 2 as follows:
(b + aa*b)*a part 1
(a + bb*a)*part 2
From part 1 of the presented regular expression we can generate the following shortest words in
the language: a, ba and aba. The generated words can either begin with as or bs any number
of them. In part 2, bb*a ensures that all words containing bs will end with as.
We provide examples:
i) How can bba be generated? Let (b + aa*b)* generate a b. Since we have a closure, b can be
generated again and the string bb can be formed by the concatenation of the two bs. Now let
(b + aa*b)* generate then the string bb, ie bb is formed. Next, a can now be concatenated to
bb to form the word bba, and if (a + bb*a)* generates then the word bba, ie bba is formed.
ii) How can aa be generated? Let (b + aa*b)* generate . Then (b + aa*b)*a generates an a.
Next, let (a + bb*a)*generate an a which can now be concatenated to the a initially generated, to
form the word aa.
Option 4 should not be selected.

12

COS2601/201
Question 9
Which one of the following words can be generated by the regular expression
aab*a(bb*a)*a[a + bb*a(bb*a)*a]*?
1. aaba
2. abba
3. aaa
4. aaaa
Answer: Option 4
Discussion
The easiest way to go about answering this question is to start by considering the smallest words
that can be generated by the regular expression provided. We can divide our regular expression
into different parts as follows:
aab*a.. part 1
(bb*a)*.part 2
a[a + bb*a(bb*a)*a]*.part 3
The shortest word that can be generated by aab*a(bb*a)*a[a + bb*a(bb*a)*a]* is aaaa.
From part 1 we have the option to include bs or not. aab*a can generate aaa if b* generates . It
is, however, clear that each word in the language consists of at least 3 as. From part 2 of the
given regular expression none of the substrings generated by possible repeated factors has to be
included during the generation of words, as bb*a is enclosed between brackets with the Kleene
star. Thus (bb*a)* can generate . Part 3 has a compulsory a in front of the first bracket of
[a + bb*a(bb*a)*a]*. Thus we should at least concatenate another a to the existing aaa-substring
obtained in part 1. Therefore aaaa is the shortest word that can be generated by the given regular
expression. Furthermore all generated words should contain at least four as. We are now ready to
consider the options provided.
Option 1
The word aaba does not contain 4 as; consequently it is not a word in the language generated by
the regular expression. Option 1 should not be selected.
Option 2
Similarly, abba does not contain 4 as, consequently it is not a word in the language generated by
the regular expression. Option 2 should not be selected.
Option 3
The same holds for aaa. aaa does not contain 4 as; consequently it is not a word in the language
generated by the regular expression. Option 3 should not be selected.

13

Option 4
From our previous discussion of the provided regular expression it follows that aaaa is a word in
the language generated by the given regular expression. Thus option 4 should be selected.
Question 10
Which one of the following regular expressions generates a language that is equivalent to the
language generated by
[ a(ba)*(a + b(ab)*b) + b(ab)*(b + a(ba)*a) ](a + b)* ?
1. (a + b)*
2. [ a(ba)*a + (b + ab)(ab)*(b + aa) ](a + b)*
3. (aa + abb)* (a + b)* (bb + baa)*
4. (aa + abb)* (bb + baa)* (a + b)*
Answer: Option 2
Discussion
The approach to answering this question will be similar to that of Question 9. Well consider the
smallest words generated by the respective regular expressions. From observing the regular
expressions provided in option 1, option 3 and option 4 it is clear that these regular expressions
can generate . can, however, not be generated by

[ a(ba)*(a + b(ab)*b) + b(ab)*(b + a(ba)*a) ](a + b)*. Thus we are left to show that the regular
expression provided in option 2 is equivalent to the regular language under discussion. Both these
expressions are concluded with (a + b)*. Thus if the shortest words generated by the two regular
expressions under discussion are similar then we may conclude the regular expressions are
equivalent. Two regular expressions are equivalent if all the words generated by the one regular
expression are also generated by the other regular expression AND if no words are generated by
the one regular expression that cannot be generated by the other. Next well consider our options:
Option 1
The language generated by the regular expression presented in option 1 includes which cannot
be generated by [ a(ba)*(a + b(ab)*b) + b(ab)*(b + a(ba)*a) ](a + b)* --- we do not have a Kleene
closure preceding the expression (a + b)*. Option 1 should not be selected.
Option 2
Refer to the regular expression bottom page 42. We can apply this principle to the regular
expression under consideration and the regular expression provided in this option.
Beginning with the regular expression under consideration:

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


= [ a(ba)*a + a(ba)*b(ab)*b + b(ab)*b + b(ab)*a(ba)*a) ](a + b)*

14

COS2601/201
Let (ba)* and (ab)*generate .
We look at the shortest words generated by the regular expression under consideration:
a(ba)*a can generate aa ;
a(ba)*b(ab)*b can generate abb;
b(ab)*b can generate bb; and
b(ab)*a(ba)*a can generate baa.
Now consider the regular expression in this option:
[ a(ba)*a + (b + ab)(ab)*(b + aa) ](a + b)*
= a(ba)*a + b(ab)*b + ab(ab)*b + b(ab)*aa + ab(ab)*aa
The shortest words generated by this regular expression:
a(ba)*a can generate aa;
b(ab)*b can generate bb;
ab(ab)*b can generate abb;
b(ab)*aa can generate baa; and
ab(ab)*aa can generate abaa.
This general expression can generate abaa. Can the regular expression given in the question
statement generate this word? Yes, surely a(ba)*a can generate abaa.
Similar shortest words can be generated by both regular expressions under discussion. Thus the
two regular expressions are equivalent when considering the initial discussion in this question.
Therefore option 2 should be selected.
Option 3
The language generated by the regular expression presented in this option has as member but
cannot be generated by [ a(ba)*(a + b(ab)*b) + b(ab)*(b + a(ba)*a) ](a + b)*. Option 3 should
not be selected.
Option 4
The language generated by the regular expression presented in this option includes as member
but cannot be generated by [ a(ba)*(a + b(ab)*b) + b(ab)*(b + a(ba)*a) ](a + b)*. Option 4
should not be selected.

---oooOooo--
UNISA 2014

15

Você também pode gostar