Вы находитесь на странице: 1из 11

COS2601/201/2/2014

Tutorial Letter 201/2/2014


Theoretical Computer Science 2

COS2601
Semester 2
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
Which one of the following persons contributed during World War II to the birth of the first
computer?
1. Alonzo Church
2. Stephen Kleene
3. Alan Turing
4. Kurt Gdel
Answer 1: Option 3
Discussion
The birth of the computer can be linked to World War 2 in that computers were used by the Allies
to break the Germans secret code, and it was Turing who took part in the construction of the
machine. Option 3 is thus the correct option.
Refer to Cohen, p. 5
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 = 0/ and T = {}
2. S = {a, b} and T = {a, b}
3. S = {, a, b} and T = {a, ab}
4. S = {a, b, bba, aa} and T = {a, b, ba, aab}
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.) Remember that when creating a subset of another set, one
can throw away no elements, some elements, or all elements; thus 0/ L (for any set L).
Option 1
Let S = 0/ (that is, S is the null set; it contains no words) and T = {} (that is, T contains the null
string as an element). Now, S T as S (the null set) is a subset of all sets, and so will be a subset
of T this means that option 1 cannot be selected. However, it is true that T S as is an
element of T but not an element of S. Note that S* = {} (as is always an element of L*, where L
is any set) and T* = {}* = {, , , } = {} , as any concatenation of is still . Thus S* =
T*.
Option 1 should not be selected.
2

COS2601/201
Option 2
Let S = {a, b} and T = {a, b}. As any element in S is also in T, S T. Using similar reasoning,
T S. Thus the first 2 conditions have not been met and we should not select option 2. However,
it is worth noting that as S = T, S* = T*.
Option 2 should not be selected.
Option 3
Let S = {, a, b} and T = {a, ab}. As is an element of S but not of T, S T. As ab is an element
of T but not of S, T S. Thus the first two conditions have been met. Let us now consider S* and
T*. S* = {, a, b, aa, ab, ba, bb, } it contains all possible concatenations of as and bs,
together and separately, and is also a word in S*. However, T* = {, a, ab, aa, aab, aba, abab,
} and does not contain ba there is no way of generating an a followed by a b. Thus S* T*.
Option 3 should not be selected.
Option 4
Let S = {a, b, bba, aa} and T = {a, b, ba, aab}. Now S T as S contains bba, which is not an
element of T. Also, T S as aab is an element of T but not of S. As both S and T have a and b as
elements of the sets, S* and T* will contain all possible concatenations of as and bs, together and
separately, and . Thus S* = {a, b}* and T* = {a, b}*, and thus S* = T*.
Option 4 should be selected.
Question 3
Consider the language S*, where S = {bb, bab}. Which one of the following words is not in the
language S*?
1. babbb
2. bbabb
3. bbbab
4. babbabbb
Answer: Option 2
Discussion
In order to prove that a certain word is in a closure language R* (say), we must show how that
word can be written as a concatenation of words from the base set R. The words in R* comprise
all possible concatenations of words in R, together and separately, and is also a word in R*.
In order to answer this question we will illustrate how all the words provided in the options, except
one, can be generated by concatenating the building blocks bb and bab (the words belonging to
S).
Option 1
Consider babbb. This word can be factored as follows: (bab)(bb) both factors are words in S.
babbb is thus in S*.
Option 1 should not be selected.

Option 2
Consider bbabb. When words belonging to S are identified as factors in bbabb, the remaining
letters cannot be factored in any way to be words in S, and so bbabb does not reduce to a
concatenation of words in S. For example, see the following.
b(bab)b cannot be in S* as b is not in S
(bb)abb cannot be in S* as abb is not in S, and neither are any of its factors
(bb)a(bb) cannot be in S* as a is not in S
bba(bb) cannot be in S* as bba is not in S, and neither are any of its factors
Thus bbabb is not in S* as no factorisation of bbabb leads to factors that are all in S.
Option 2 should be selected.
Option 3
Consider bbbab. This word can be factored as follows: (bb)(bab) both factors are words in S.
bbbab is thus in S*.
Option 3 should not be selected.
Option 4
Consider babbabbb. This word can be factored as follows: (bab)(bab)(bb) all three factors are
words in S. babbabbb is thus in S*.
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 the same
number of 4-letter words and 2-letter words?
1.
S = {bb, aa}
2.
S = {a, b}
3.
S = {bbba, aa}
4.
S = {aab}
Answer: Option 4
Discussion
Option 1
If S = {bb, aa}, then S* = {, bb, aa, bbbb, bbaa, aabb, aaaa, bbbbbb, bbbbaa, bbaabb, bbaaaa,
aabbbb, aabbaa, aaaabb, aaaaaa, }. The rest of the words in S* would be longer than 6 letters.
In this case, S* has two 2-letter words and four 4-letter words.
Option 1 should not be selected.
Option 2
If S = {a, b}, then S* = {, a, b, aa, ab, ba, bb, aaa, aab, aaaa, aaab, aaba, aabb, aba, abb, abaa,
abab, abba, abbb, baa, bab, baaa, baab, baba, babb, bba, bbb, bbaa, bbab, bbba, bbbb, }. S*
has four 2-letter words and sixteen 4-letter words. So there are more 4-letter words in S* than 2letter words.
Option 2 should not be selected.
Option 3
If S = {bbba, aa}, then S* = {, bbba, aa, bbbabbba, bbbaaa, aabbba, aaaa, }. The rest of the
words in S* would be longer than 4 letters, and so have no bearing on the answer. S* in this case
has one 2-letter word and two 4-letter words.
Option 3 should not be selected.
4

COS2601/201

Option 4
If S = {aab}, then S* = {, aab, aabaab, }. The rest of the words in S* would be longer than 6
letters as they would be made up of concatenations of words that are 3 and 6 letters long, and
longer, and so have no bearing on the answer. It this case, S* has no (or zero) 2-letter words and
no (or zero) 4-letter words; S* thus has the same number of 2- and 4-letter words.
Option 4 should be selected.
Question 5
Consider the language EVEN over {a, b} consisting of all words of even length. Which one of the
following is a suitable generator?
1. bba
2. bb
3.
4. b
Answer: Option 3
Discussion
The generator(s) of a language is/are the shortest word(s) belonging to the language. In the case
of EVEN over {a, b}, a generator should be of even length. This is important during the remainder
of the discussion. In order to select the correct answer one can ask the following question:
Is the word to be considered of even length?
If the answer to this question is yes then we know the given word belongs to EVEN. All that
remains to be considered is whether the word is one of the shortest words in the language EVEN.
Option 1
Is bba of even length? No
Thus bba is not a word in EVEN and cannot be a generator of EVEN.
Option 1 should not be selected.
Option 2
Is bb of even length? Yes
Thus bb is a word in EVEN and could be a generator of EVEN. However, bb is not the shortest
word that can generate EVEN (see option 3).
Option 2 should be not selected.
Option 3
Is of even length? Yes (note that 0 is considered even)
is of even length, and is the shortest word in the language. Thus, by applying the recursive
definition, the CONCAT function as defined in the study guide, together with this generator, can be
used in generating all the words in EVEN.
Option 3 should be selected.
Option 4
Is b of even length? No
Thus bba is not a word in EVEN and cannot be a generator of EVEN.
Option 4 should be not selected.

Question 6
Consider the language MultipleOfThreeA over {a, b} consisting of all words of a length which is
divisible by 3 without a remainder that do contain the substring a. Which one of the following is a
suitable generator?
1. babbab
2.
3. aba
4. I
Answer: Option 3
Discussion
Remember that the generator(s) of a language is/are the shortest word(s) belonging to the
language. In the case of MultipleOfThreeA over {a, b}, the following 2 questions need to be
answered:
Is the length of the word a multiple of 3?
Does the word contain the a substring?
If the answer to these two questions is yes then we know the given word belongs to
MultipleOfThreeA. All that remains to be considered is whether the word is one of the shortest
words in the language MultipleOfThreeA.
Option 1
Is the length of babbab a multiple of 3? Yes
Does babbab contain the a substring? Yes
Although the answer to both questions is yes, this cannot be a generator as it is 6 characters long,
and is not one of the shortest words in the language MultipleOfThreeA. The shortest word would
have just 3 characters.
Option 1 should not be selected.
Option 2
Is the length of a multiple of 3? Yes (as 0 x 3 = 0)
Does contain the a substring? No
does not contain the a substring, and thus is not a word in MultipleOfThreeA, and cannot be a
generator.
Option 2 should not be selected.
Option 3
Is the length of aba a multiple of 3? Yes
Does aba contain the a substring? Yes
aba has a length that is a multiple of 3 and it contains the a substring. Also, it is one of the shortest
words in the language; others are aaa, aab, baa, bba, and abb. Thus, by applying the recursive
definition, the CONCAT function as defined in the study guide, together with this generator, can be
used in generating all the words in MultipleOfThreeA.
Option 3 should be selected.

COS2601/201
Option 4
Is the length of bbb a multiple of 3? Yes
Does bbb contain the a substring? No
As bbb does not contain the a substring, it cannot be a word in the MultipleOfThreeA language,
and thus can also not be a generator.
Option 4 should not be selected.
Question 7
Which one of the following regular expressions generates a language equivalent to the language
generated by (ab + ba)*?
1. (abba)*
2. (a + b)*
3. ((ab)*(ba)*)*
4. (aa + ab)*ba
Answer: Option 3
Discussion
The easiest way to go about answering this question is to start by considering the kinds of words
that can be generated by the regular expression provided, as well as the shortest words that can
be generated.
Remember that two regular expressions are equivalent if all the words generated by the one
regular expression are also generated by the other regular expression. Also, we need to check
that no words are generated by the one regular expression that cannot be generated by the other.
It first needs to be noted that (ab + ba)* can generate , and so we need to check which of the
regular expressions provided in the options can also generate . Also, words generated by
(ab + ba)* must contain either ab or ba after , these are the shortest words in the language. All
other words will be concatenations of these two words concatenated in various ways, together and
separately. Thus, if L is the language generated by (ab + ba)*, then L = {, ab, ba, abab, abba,
baab, baba, }. Let us now consider the options.
Option 1
(abba)* can generate , but cannot generate the words ab or ba since all words in the language
will be made up of concatenations of abba; that is, the language generated by (abba)* is {, abba,
abbaabba, }.
Option 1 should not be selected.
Option 2
(a + b)* can generate , and so we need to look further. If L is the language generated by (a + b)*,
then L = {, a, b, }. As a and b are in the language generated by (a + b)* but are not in the
language generated by (ab + ba)*, (a + b)* and (ab + ba)* do not generate the same language.
Option 2 should not be selected.

Option 3
((ab)*(ba)*)* can generate , and so we again look further. Look at the first example on page 47 of
Cohen: (a*b*)* = (a + b)*. Now if we think of a as (ab) and b as (ba), we have the following:
((ab)*(ba)*)* = (ab + ba)* - which is what we wanted to show. Note that you cannot substitute a
as ab and b as ba (that is, without the brackets), as ab* and (ab)* mean different things.
Option 3 should be selected.

Option 4
The shortest word in the language generated by (aa + ab)*ba is ()(ba), which is ba. Thus
(aa + ab)*ba cannot generate , and thus cannot be equivalent to the language generated by
(ab* + ba)* (which can generate ).
Option 4 should not be selected.
Question 8
Consider S = {a, ba}. Which is the smallest, listed word not belonging to S*?
1.
2.
3.
4.

ba
bb
bab

Answer: Option 3
Discussion
Consider S = {a, ba}. S* is made up of all possible concatenations of the words in S, together and
separately, and is also an element of S*. The easiest way to find words not in S* is to look for
words whose factors are not in S. S* = { , a, ba, aa, aba, baa, baba, }. Note that it is possible
that there are several words that do not belong in S*, but that we are looking for the shortest one
belonging to S* in the listed options.
Option 1
is in S*, so this option does not need to be considered further.
Option 1 should not be selected.
Option 2
ba is in S, and thus also in S*, so this option does not need to be considered further.
Option 2 should not be selected.
Option 3
bb is not an element of S, and thus also not in S* (as there is no way to generate 2 bs following
each other). bb is also the shortest word that is not in S* (see option 4).
Option 3 should be selected.
Option 4
No matter how bab is factored, there remains a factor (or factors) that is/are not in S: (ba)(b),
(b)(a)(b), (b)(ab); bab is thus not in S*. Thus option 4 is a possibility. However, bab is longer than
bb (see option 3) and so it is not the shortest word in S*.
Option 4 should not be selected.

COS2601/201
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
Answer: Option 1
Discussion
The easiest way to go about answering this question is to start by considering the kinds of words
that can be generated by the regular expression provided. We can divide our regular expression
into different parts as follows:
Part 1

(b + a)*

Here we generate all possible concatenations of as and bs, together and


separately, as well as .

Part 2

(ab + ba)(b)

Here we generate ab or ba, followed by a b. Thus the word must end on


abb or bab.

So, any word generated by this regular expression can have all possible concatenations of as and
bs, together and separately, as well as , followed by abb or bab. Thus, in each case, we only
need to consider the last 3 characters in a given word to decide whether the regular expression
will generate it or not.
Option 1
Consider the last 3 characters of the word abba(bbb). This word does not end with abb or bab;
thus this word cannot be generated by the regular expression.
Option 1 should be selected.
Option 2
Consider the last 3 characters of the word babbba(bab). This word ends with bab, and it is
preceded by a string of as and bs. Thus this word can be generated by the regular expression.
Option 2 should not be selected.
Option 3
Consider the last 3 characters of the word baabbbb(bab). This word ends with bab, and it is
preceded by a string of as and bs. Thus this word can be generated by the regular expression.
Option 3 should not be selected.
Option 4
Consider the last 3 characters of the word b(abb). This word ends with abb, and it is preceded by
a b. Thus this word can be generated by the regular expression.
Option 4 should not be selected.

Question 10
Which one of the following regular expression generates a language equivalent to the language
generated by the regular expression
(aa + bb + ab + ba)*(a + b)?
1. (a + b)*(a + b)
2. (a + b)(ab + ba + aa + bb)*
3. (aa)*(bb)*(ab)*(ba)*(a + b)
4. (aa + bb + ab + ba)*(a + b)*
Answer: Option 2
Discussion
The approach to answering this question will be similar to that of Question 9. Well consider the
shortest words generated by the respective regular expressions.
The shortest words that (aa + bb + ab + ba)*(a + b) can generate are a and b. cannot be
generated (as only the first part of the regular expression can generate , and we are left with
(a + b) which gives either an a or a b).
Again, 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.
Option 1
The shortest words that (a + b)*(a + b) can generate are the following (remembering that (a + b)*
can also generate ): a, b, aa, ab, ba, bb, . Now both a and b can also be generated by
(aa + bb + ab + ba)*(a + b). However, (aa + bb + ab + ba)*(a + b) cannot generate 2-letter words
such as aa, ab, ba, and bb; it can only generate , 1-letter, and 3-letter words (pairs of letters from
the first part, followed by a single letter from the second part). Thus (aa + bb + ab + ba)*(a + b)
and (a + b)*(a + b) cannot generate the same language.
Option 1 should not be selected.
Option 2
The language generated by (aa + bb + ab + ba)*(a + b) is {, a, b, aaa, bba, aba, baa, aab, bbb,
abb, bab, }.
The language generated by (a + b)(ab + ba + aa + bb)* is {, a, b, aab, aba, aaa, abb, bab, bba,
baa, bbb, }.
Apart from , all other words in the languages generated by these two regular expressions will
have an odd number of letters an even number of letters from the Kleene closure part, and a
single letter from the other part. As the Kleene closure part allows for all possible combinations of
words with an even length such as , aa, bb, ab, ba, aaaa, aabb, bbbb, to be generated, when
concatenating an a or a b to the beginning or end of the words, it allows us to refactor the word
and still get a word in both languages. For example, (aa)(a) = (a)(aa) and (a)(bb) = (ab)(a). This
will work for all words in the languages generated by these two regular expressions, and so the
languages generated by them are equivalent.
Option 2 should be selected.
Option 3
Consider (aa)*(bb)*(ab)*(ba)*(a + b). Breaking this into parts, the first 4 parts can all generate ,
and the fifth part an a or a b. Thus the shortest words that can be generated by
(aa)*(bb)*(ab)*(ba)*(a + b) are a and b this is the same for (aa + bb + ab + ba)*(a + b). Now
10

COS2601/201
consider longer words. (aa + bb + ab + ba)*(a + b) can generate words where aa, bb, ab and ba
can occur in any order, followed by a final a or b. Thus, (bb)(aa)(b) is a word generated by (aa +
bb + ab + ba)*(a + b). However, in the language generated by (aa)*(bb)*(ab)*(ba)* (a + b),
concatenations of aa need to precede concatenations of bb, and bbaab cannot be generated.
Option 3 should not be selected.
Option 4
Taking the 2 parts of (aa + bb + ab + ba)*(a + b)* separately: (aa + bb + ab + ba)* and (a + b)*,
each part can generate , leading to the shortest word that can be generated as . As cannot
be generated by (aa + bb + ab + ba)*(a + b), these two regular expressions cannot generate the
same language.
Option 4 should not be selected.

UNISA 2014

11

Вам также может понравиться