You are on page 1of 32

Discussion Class: COS2601

Question 1

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

(i) abbabaabab

(ii) abaabbabbbaabb
Solution:

(i) No, no concatenations of a, bb, bab and abaab
yield abbabaabab.

Try to generate the word:
abbabaabab
but ab not possible.


(ii) Yes, concatenations of a, bb, bab and abaab
yield abaabbabbbaabb.

Question 1
(b) Give an example of a set S such that S* only contains all possible
strings of combinations of as and bs that have length divisible by
three.
(c) Give an example of two sets S and T of strings such that
S* = T* but S T and T S.
Solution:

(b) S = {aaa, aab, aba, abb, baa, bab, bba, bbb}.

All words in S*: Multiples of three;
All possible combinations of as & bs.

(c) Two possible answers:

S = {, a} and T = { a, aa } or

S = {a, b, ab} and T = {a, b, ba}.
Solution:
Question 2
Consider the alphabet {a, b} and the language ODDAB
where ODDAB consists of all words of ODD length which
contain the substring ab. Provide
(i) an appropriate universal set,
(ii) the generator(s),
(iii) a function on the universal set, and then
(iv) use these concepts to write down a recursive
definition of the language ODDAB.
(i) {a, b}* suitable - contains all the words in ODDAB.

(ii) aba, aab, abb, bab (odd, contains ab)

(iii) CONCAT
2(iv) Recursive def. ODDAB:

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

Alternative recursive def.:
Rule 1: aba, aab, abb, bab ODDAB.

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

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

Another example:
A recursive definition for language EVENnotAA over {a, b}
must be compiled where EVENnotAA consists of all
words of even length and not containing the substring aa.
Provide
(i) an appropriate universal set,
(ii) the generator(s),
(iii) a function on the universal set, and then
(iv) use these concepts to write down a recursive
definition of the language EVENnotAA.

Solution:
(i) {a, b}* suitable-contains all words in EVENnotAA.

(ii) , ab, ba and bb

(iii) CONCAT
(iv) Recursive def. for EVENnotAA :
EVENnotAA is the smallest subset of {a,b}* such that
, ab, ba and bb EVENnotAA and

if w EVENnotAA, then also
CONCAT(w, ba), CONCAT(ab, w),
CONCAT(w,bb), CONCAT(bb,w) EVENnotAA, and

if w EVENnotAA and w does not end on an a, then
CONCAT(w, ab) EVENnotAA, and

if w EVENnotAA and w does not begin with an a, then
CONCAT(ba, w) EVENnotAA.
Question 3
(i) Give a recursive definition of the set P of all positive integers greater
than or equal to 5,

(ii) formulate the appropriate induction principle, and

(iii) then apply the induction principle to prove that

2n 3 2
n-2
for all n 5.
Solution:

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

(ii) If a subset A of P is such that 5A and
if nA, then also n+1A,
then A = P.
Question 3(iii)
Apply induction principle: Prove 2n3 2
n-2
for all integers n5
Solution:
Define the set A: A P: A = {nP | 2n - 3 2
n - 2
}

Is n = 5A?
2(5) - 3 2
5 - 2

i.e. 7 8
Thus, 5A is true.

Assume kA, hence we assume 2k 3 2
k 2


Required to prove k+1A, i.e. 2(k+1) 3 2
(k+1) 2

End goal to prove A = P.
Question 3(iii) cont. Apply the induction principle:
Prove 2n 3 2n-2 for all integers n 5.

Solution cont.:
Assume kA, hence we assume 2k 3 2
k 2

(1)

Required to prove k+1A, i.e. 2(k+1) 3 2
(k+1) 2
LHS:
2(k+1)3 = 2k + 2 3
= (2k 3) + 2
2
k 2
+ 2 from (1)
2(2
k 2
) smallest value for 2
k 2
, k=5 is
2
52
= 8 and 28 = 16 > 10 = 2
52
+ 2
= 2
1 + k 2
= 2
(k +1) 2
Thus k+1A

Hence, A = P
thus 2n - 3 2n - 2 for all n 5.
Question 4(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 aaa does not appear at all? If not, give a
counterexample.

Solution:

No, the regular expression does not define the language.

All words must contain bbb.

No word contains aaa.

However, not all words can be generated some
counterexamples are:
babbb
aabbb
bbba.

Question 4(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.
Solution:

Regular expression:
Must generate 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 + )
Question 5
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.
Solution: We begin to draw the FA as follows:












- 1
2
3
+ 5
6
a
a, b
b
a
b
b
+ 4
a
a
Question 5
NO word contains the substring bba, and
ALL words end with a double letter, either aa or bb.
Solution:












- 1
2
3
+ 5
6
a
a, b
b
a
b
b
+ 4
a
a
a
b
b









Question 6
By using Kleenes theorem, find a regular expression that generates
the language accepted by the following TG (transition graph):
-
ba
b
+
+
a
b
a
aa
bb
a
Question 6 cont.
By using Kleenes theorem, find a regular expression.
Solution:
Step 1 - Create a unique start state and a unique final state:

1
4
3
2
a
a
a
b
b
bb
ba
aa
-
+





Question 6 cont. Solution:
Step 2 - Eliminate state 3:

1
4
2
a
a
a
b
bb
-
+






bab*aa

1
4
3
2
a
a
a
b
b
bb
ba
aa
-
+





Question 6 cont. Solution:
Step 3 - Eliminate state 4:
1
4
2
a
a
a
b
bb
-
+






bab*aa

1
2
a
a
-
+




(b + bab*aa)(bb)*a
(b + bab*aa)(bb)*
Question 6 cont. Solution:
Step 4 - Eliminate state 2:
1
2
a
a
-
+




(b + bab*aa)(bb)*a
(b + bab*aa)(bb)*
1
-
+


[a + (b + bab*aa)(bb)*a]a*
(b + bab*aa)(bb)*
Regular expression:
[a + (b + bab*aa)(bb)*a]a* + (b + bab*aa)(bb)*

1
-
+


[a + (b + bab*aa)(bb)*a]a* + (b + bab*aa)(bb)*
Question 6 cont. Solution:
Step 5 - Eliminate state 1:

1
-
+


[a + (b + bab*aa)(bb)*a]a*
(b + bab*aa)(bb)*
Question 7 Consider the following FA with a corresponding
regular expression r
1
:
Build an FA for the regular expression r
1
* by applying
Kleenes theorem.
-x1
+x3
x2
a, b
b
b
a
a
Question 7 cont FA for a regular expression r1*
Solution: First compile a transition table
-x1
+x3
x2
a, b
b
b
a
a
New
state
Read
a
Read
b
z
1
= x
1
z
3
z
2

z
2
= x
1
z
3
z
2

z
3
= x
2
z
3
z
4

+z
4
= x
1

or x
3

z
5
z
4

+z
5
= x
2

or x
3
or
x
1

z
5
z
4

Question 7 cont. Solution: FA for a regular expression r1*
New state Read an a Read a b
z
1
= x
1
z
3
z
2

z
2
= x
1
z
3
z
2

z
3
= x
2
z
3
z
4

+z
4
= x
1
or x
3
z
5
z
4

+z
5
= x
2
or x
3
or x
1
z
5
z
4

z1
z2
+z4
z3
+z5
a
b
b
a
b
a
a
a
b
b
Question 8(a)
Convert the following Mealy
machine to a Moore machine:

q
0

q
2


q
1


b/1
b/1
b/0
a/0
a/0
a/1
q
0
1
/
0

q
2
/
0

q
1
/
1

q
0
2
/
1

b
b
b
b
a
a
a
a
Solution:
Solution:
Question 8(b)
Consider the following FA:
Find an NFA (non-deterministic FA) with four states
that accepts the same language.

-
+
a
a
a
a
a
b
b
b
b
b

-
+
a
a
a,b
b
a,b
Assume L = {a
n
b
n
a
m
, where n, m{0,1,2,3,...}} is regular.

Then there exists an FA with, say k states, that accepts L.
Let w = a
k
b
k
a
p
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
i.e. both x and y can only be as.

Pumping lemma: xyyz must also be an element of L.
Not the case: xyyz has more as (in first group of as) than bs.

This a contradiction. Our assumption that L is regular is
incorrect and we conclude that L is not regular.
Question 9 Use the Pumping Lemma with length to prove that the
following language is nonregular:
L = {a
n
b
n
a
m
, for some n = 0,1,2,3, and m = 0,1,2,3,}.
Solution:
Extra example: Use the Pumping Lemma with length to prove that the
following language is nonregular:
L = { ab
n + 1
c
5
a
n
n = 1, 2, 3,... }.
Assume L = {ab
n + 1
c
5
a
n
n = 1, 2, 3,... } is regular.

Then there exists an FA with, say k states, that accepts L.
Let w = ab
k + 1
c
5
a
k
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

Pumping lemma: xyyz must also be an element of L.
We see this is not the case.

Solution:
w = xyz = ab
k + 1
c
5
a
k
. Three possible cases:
1. y consists of only the first a
2. y consists of the first a and some of the bs
3. y consists of only bs.
In all cases the pumped string xyyz is not in L:
Case 1: xyyz contains more than one a in beginning of the
string but only k as in the second group of as;
Case 2: xyyz contains more than one ab sub-string;
Case 3: in xyyz contains more than k+1 bs but only k as in
the second group of as.
Pumped words do not belong to L.
This a contradiction. Our assumption that L is regular is
incorrect and we conclude that
L is not regular.
(a) An effective solution to a problem with a Yes or No as answer is
called a decision procedure.

(b) A problem for which a decision procedure can or may be found is
called decidable.

(c) If some FA has N states and there are m letters in its alphabet, then
there exist
m
N
+ m
N + 1
+ m
N + 2
+ + m
2N 1

different input strings in the range N length of string < 2N.

All these words can be tested by executing the FA on them.

If any of these words are accepted, then the language is infinite. If none of
these words is accepted, then the language is finite.
Question 10 in TL 103. Question 11
(a) Define a decision procedure.
(b) Use the definition in (a) to define decidability.
(c) Describe an effective procedure to decide whether a given FA accepts
a finite or infinite language. (Th. 20 p. 216, Cohen)
(d) Using the decision procedure in (c) above, determine whether each
FA
1
and FA
2
accepts a finite or an infinite language (see next pp.)
Solution:
-
+
a
b
a
a
b
b
a
a, b
b
Question 11 cont.
(d) Using the decision procedure described in (c), determine whether the
following FA
1
accepts a finite or infinite language.
Solution:

N = 5; 2N = 10.

Only words accepted by
FA
1
: b and ab.
(Lengths 1 and 2.)

Words of length
5 length of string < 10
not accepted.

Thus language is finite.
Question 11 cont.
(d) Using the decision procedure described in (c), determine whether the
following FA
2
accepts a finite or infinite language.
-
+
b
a, b
a
b
a
Solution:

N = 3; 2N = 6.

Consider bbaa:
Length(bbaa) = 4 > N = 3

bbaa is accepted by FA
2

where
3 length(bbaa) = 4 < 6.

Thus language accepted
is infinite.

You might also like