Professional Documents
Culture Documents
University of The Witwatersrand, Johannesburg
University of The Witwatersrand, Johannesburg
Examination to be
June 2007
held during the months(s) of
Year of Study
Internal examiner(s)
and telephone extension Dr S. Ewert x76180
number(s)
Course
Time allowance COMS3003 Hours 3
nos
** As Internal Examiner, I certify that this question paper is in final form and is ready for reproduc-
tion.
Name: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Signature: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Exam
Formal Languages and Automata
student number:
June, 2007
Instructions
• Answer all the questions on the question paper.
• Answer all the questions in the space allocated for the answer immediately following the question.
If you run out of space, you may continue on the last page; in that case, remember to give the
number of the question.
Comments
• Throughout this paper, na (x) indicates the total number of occurrences of the symbol a in the
string x.
Page 1 of 27
COMS3003 Formal Languages and Automata June 2007
Question 1 —
Consider the following statement. ‘If a student has failed course X more than once, he or she may not
register for it again’.
Student Y isn’t registered for course X. Which one of the following statements is correct? Circle the
correct answer.
3. Y may or may not have failed course X more than once, but we cannot say for sure given the
information we have.
1 mark(s)
Page 2 of 27
COMS3003 Formal Languages and Automata June 2007
Question 2 —
1. In each of the following you are given two possible answers, labelled empty and non empty,
respectively. Circle either empty or non empty; moreover, if you choose the answer labelled
non empty, complete the sentence.
5 mark(s)
7 mark(s)
(a) (L1 ∪ L2 )+ \ L+ +
1 ∪ L2
i. empty: The set is empty.
ii. non empty: The set contains the string .
+
(b) L+ +
1 ∪ L2 \ (L1 ∪ L2 )
i. empty: The set is empty.
ii. non empty: The set contains the string .
+
(c) L+ +
2 L1 \ (L2 L1 )
i. empty: The set is empty.
ii. non empty: The set contains the string .
+
(d) (L2 L1 ) \ L+ +
2 L1
i. empty: The set is empty.
ii. non empty: The set contains the string .
Page 3 of 27
COMS3003 Formal Languages and Automata June 2007
Question 3 —
Consider the following regular expressions. In each case, give a string of length 4 in {0, 1}∗ that is not
in the language corresponding to the given regular expression.
1. (0 + 10)∗ 1∗
2 mark(s)
2. (λ + 0 + 00) (1 + 10 + 100)∗
2 mark(s)
Page 4 of 27
COMS3003 Formal Languages and Automata June 2007
Question 4 —
1. Let L ⊆ Σ∗ be any language. Let L1 be the set of prefixes of elements of L. We want to investigate
the relationship between the two partitions of Σ∗ corresponding to the equivalence relations IL and
IL1 , respectively.
Complete the following proof.
8 mark(s)
Suppose x and y are distinguishable w.r.t. L1 . Specifically, suppose that for some z,
xz ∈ L1 and yz 6∈ L1 .
Therefore, if x and y are in different equivalence classes with respect to IL1 , they are in (circle the
correct answer)
Therefore,
(a) any equivalence class w.r.t. IL is the union of equivalence classes w.r.t. IL1 .
(b) any equivalence class w.r.t. IL1 is the union of equivalence classes w.r.t. IL .
(c) we cannot say anything about the relationship between the equivalence classes w.r.t. IL and
IL1 .
Page 5 of 27
COMS3003 Formal Languages and Automata June 2007
2. For a certain language L ⊆ {a, b}∗ , IL has exactly four equivalence classes. They are [λ], [a], [ab],
and [b]. It is also true that
(a) the three strings a, aa, and abb are all equivalent, and
(b) the two strings b and aba are equivalent.
Finally,
(a) ab ∈ L,
(b) λ 6∈ L,
(c) a 6∈ L,
(d) b is not even a prefix of any element of L.
6 mark(s)
Page 6 of 27
COMS3003 Formal Languages and Automata June 2007
(a) L = {0m 1n 0p | p ≥ m + n}
For z = ,
0i z L
and 0j z L.
3 mark(s)
For z = ,
0i z L
and 0j z L.
3 mark(s)
4. In each of the following cases, give two strings that are indistinguishable with respect to L; no
justification is necessary. If no such strings exist, state it clearly.
2 mark(s)
2 mark(s)
Page 7 of 27
COMS3003 Formal Languages and Automata June 2007
Question 5 —
1. Let
M1 = ({A, B, C, D} , {0, 1} , A, {C, D} , δ1 ) ,
and
M2 = ({P, Q} , {0, 1} , P, {Q} , δ2 ) ,
be Finite Automata (FA) recognizing languages L1 and L2 , respectively, where
Page 8 of 27
COMS3003 Formal Languages and Automata June 2007
M3 = (Q3 , {0, 1} , q3 , A3 , δ3 )
that accepts
L3 = {x ∈ {0, 1}∗ | x ends in 00} .
In the following, use the notation AQ for the states in Q3 .
i. Give the start state of M3 .
1 mark(s)
ii. Give A3 .
2 mark(s)
iii. Complete the following transition table for δ3 . You may leave out the states that are not
reachable, if such states exist.
4 mark(s)
q δ3 (q, 0) δ3 (q, 1)
Page 9 of 27
COMS3003 Formal Languages and Automata June 2007
iv. Give the states in M3 that are not reachable. If no such state exists, state it clearly.
2 mark(s)
v. Consider the following list:
A. L1 ∩ L2
B. L′1 ∩ L2
C. L1 ∩ L′2
D. L′1 ∩ L′2
E. L1 ∪ L2
F. L′1 ∪ L2
G. L1 ∪ L′2
H. L′1 ∪ L′2
Complete the following statement by giving the label of the correct expression in the list.
L3 =
1 mark(s)
Page 10 of 27
COMS3003 Formal Languages and Automata June 2007
2. Consider the FA
M = ({1, 2, 3, 4, 5, 6, 7} , {a, b} , 1, {4, 6, 7} , δ) ,
where δ is given in the following diagram:
As part of the process of finding a minimum-state FA that accepts the same language as M , com-
plete rows 5 and 7 in the following diagram to indicate the situation after the first pass.
5 mark(s)
2
3
4
5
6
7
q 1 2 3 4 5 6
Page 11 of 27
COMS3003 Formal Languages and Automata June 2007
3. Consider the FA
M = ({1, 2, 3, 4, 5, 6} , {a, b} , 1, {1, 2, 7} , δ) ,
where δ is given in the following diagram:
In the process of finding a minimum-state FA that accepts the same language as M , we obtain the
following diagram after completion of a pass.
2
3 X X
4 X X
5 X X
6 X X
7 X X X X
q 1 2 3 4 5 6
2 mark(s)
(b) Give one pair that doesn’t get marked in this pass.
2 mark(s)
Page 12 of 27
COMS3003 Formal Languages and Automata June 2007
4. Consider the FA
M = ({1, 2, 3, 4, 5, 6, 7} , {a, b} , 1, {2, 6} , δ) ,
where δ is given in the following diagram:
2 X
3 X
4 X X X
5 X X
6 X X X X
7 X X X
q 1 2 3 4 5 6
Here X indicates that the pair is marked. Give the minimum-state FA Mmin for M as a diagram.
In each state of Mmin , indicate clearly which states of M it represents.
8 mark(s)
Page 13 of 27
COMS3003 Formal Languages and Automata June 2007
7 mark(s)
Page 14 of 27
COMS3003 Formal Languages and Automata June 2007
Question 6 —
1. Consider the language
8 mark(s)
x= .
Then uv = .
This implies that w = .
Moreover, v = .
According to the lemma, uv m w ∈ L for every m ≥ 0.
Consider
uv m w = . . .
= ...
For m = , uv m w 6∈ L,
since .
This contradicts the lemma, therefore our assumption that L is regular is wrong.
Page 15 of 27
COMS3003 Formal Languages and Automata June 2007
Question 7 —
Consider
1. Lab = ai bi | i > 0
2. La = ai | i > 0
3. Lb = bi | i > 0
1. Gab = (Vab , Σ, Sab , Pab ), where Vab = {Sab } and Pab = {Sab → aSab b | ab},
L = ai bj | i, j ≥ 1, i 6= j ,
13 mark(s)
Page 16 of 27
COMS3003 Formal Languages and Automata June 2007
Page 17 of 27
COMS3003 Formal Languages and Automata June 2007
Question 8 —
1. Consider the context-free grammar G = ({S, A, B} , {a, b, c} , S, P ), where P is the set of pro-
ductions
S → AB
A → aAb |
λ
B → bBc |
λ
Find the nullable variables, using the appropriate algorithm. Show all steps.
4 mark(s)
2. Consider the context-free grammar G = ({S, T } , {a, b} , S, P ), where P is the set of productions
S → aSc |
T
T → aT b |
λ
4 mark(s)
Page 18 of 27
COMS3003 Formal Languages and Automata June 2007
3. Consider the context-free grammar G = ({S} , {(, )} , S, P ), where P is the set of productions
S → S (S) |
(S) |
S ()
G1 = (V, {(, )} , S, P1 )
5 mark(s)
Page 19 of 27
COMS3003 Formal Languages and Automata June 2007
Question 9 —
1. Consider the language
n o
L = ai bj ck | i, j, k ≥ 0, j = i or j = k ,
that accepts L.
We proceed as follows. The PDA makes an initial choice as to whether it will compare the number
of b’s to the number of a’s or to the number of c’s; q1 and q4 are the states that begin these respective
processes. In q1 , one possibility is that there are no a’s or b’s at all. Otherwise, the PDA saves a’s
on the stack, and when it sees a b, it pops a’s off the stack to match inputs of b. In either case, when
the stack is empty except for Z0 , the PDA goes to q3 , from which it can move to the accepting state
any time. The only other move from q3 is to read a c, leaving the stack alone.
Starting in q4 the moves are similar. The PDA moves to q5 at any time, and the only move it can
make before that is to read an a, leaving the stack alone. From q5 , the PDA pushes b’s onto the
stack, and when it sees a c it starts to remove b’s from the stack to match the c’s in the input. It
enters the accepting state whenever the stack is empty except for Z0 .
Complete the following transition table.
17 mark(s)
Page 20 of 27
COMS3003 Formal Languages and Automata June 2007
1 q0 λ Z0
2 q1 λ Z0
3 q1 a Z0
4 q1 a a
5 q1 b a
6 q2 b a
7 q2 λ Z0
8 q3 c Z0
9 q3 λ Z0
10 q4 λ Z0
11 q4 a Z0
12 q4 b Z0
13 q5 b b
14 q5 c b
15 q6 c b
16 q6 λ Z0
Page 21 of 27
COMS3003 Formal Languages and Automata June 2007
Question 10 —
1. The Pumping Lemma for Context-free Languages (CFLs) states:
Let L be a CFL. Then there is an integer n such that for any
u∈L
with
|u| ≥ n ,
there are strings v, w, x, y, and z satisfying
u = vwxyz
|wy| > 0
|wxy| ≤ n
for any m ≥ 0, vwm xy m z ∈ L
5 mark(s)
Page 22 of 27
COMS3003 Formal Languages and Automata June 2007
2. In each of the following you are given a language L. You want to use the pumping lemma for
context-free languages given above to show that L is not context-free. Give the word u ∈ L that
you would use to start your proof.
(a) L = ai bi cj | i, j ≥ 0, j ≤ i
2 mark(s)
(b) L = ai b i ∪ ai b 2i ∪ ai bi ci
2 mark(s)
Page 23 of 27
COMS3003 Formal Languages and Automata June 2007
3. Consider n o
L = ai bj ck | i, j, k ≥ 0, i < j, i ≤ k ≤ j
15 mark(s)
Suppose L is context-free. According to the pumping lemma, there is an integer n such that for
any u ∈ L with |u| ≥ n, there are strings v, w, x, y, and z satisfying u = vwxyz, |wy| > 0,
|wxy| ≤ n, and for any m ≥ 0, vwm xy m z ∈ L.
Let n be the integer in the statement of the pumping lemma.
Choose u ∈ L such that |u| ≥ n; we choose
u = an bn+1 cn .
Page 24 of 27
COMS3003 Formal Languages and Automata June 2007
Page 25 of 27
COMS3003 Formal Languages and Automata June 2007
Question 11 —
Consider the following theorem:
Let L1 be a context-free language and L2 be a regular language. Then L1 ∩ L2 is context-free.
Use the theorem to prove that the language
5 mark(s)
Page 26 of 27
COMS3003 Formal Languages and Automata June 2007
Page 27 of 27