2012 April COMS3003
2012 April COMS3003
Exam to be
April 2012
held during the months(s) of
Year of Study
Internal examiner(s)
and telephone extension Prof. 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: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Examination
Formal Languages and Automata
student number:
April 2012
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
In 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 April 2012
Page 2 of 27
COMS3003 Formal Languages and Automata April 2012
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.
(i) L+
1 \ L1 is . . .
1. empty: The set is empty.
2. non empty: The set contains the string .
(ii) (L1 ∪ L2 )+ \ L+ +
1 ∪ L2 is . . .
1. empty: The set is empty.
2. non empty: The set contains the string .
Page 3 of 27
COMS3003 Formal Languages and Automata April 2012
6 mark(s)
Page 4 of 27
COMS3003 Formal Languages and Automata April 2012
8 mark(s)
Page 5 of 27
COMS3003 Formal Languages and Automata April 2012
b. Let L = {x ∈ {0, 1}∗ | x doesn’t contain the substring 001}. Give an FA with exactly four states
that accepts L.
7 mark(s)
Page 6 of 27
COMS3003 Formal Languages and Automata April 2012
c. In each of the following we can prove that L is not regular by showing that any two elements
cases,
of the infinite set ai | i ≥ 1 are distinguishable with respect to L.
In each case, assume 1 ≤ i < j, and give a string that distinguishes ai and aj .
For z = ,
ai z L and aj z L.
2 mark(s)
(ii) L = an bl ak | n, l ≥ 1, k ≥ n + l .
For z = ,
ai z L and aj z L.
2 mark(s)
d. In each of the following cases, give two different strings in {a, b}∗ that are indistinguishable with
respect to L, if such strings exist. If there are no such strings, state it clearly.
2 mark(s)
(ii) L = an bl ak | n, l ≥ 1, k ≥ n + l .
2 mark(s)
Page 7 of 27
COMS3003 Formal Languages and Automata April 2012
Prove that L is not regular by giving an infinite set of elements that are pairwise distinguishable
with respect to L. You must give the set and show that any two elements from the set are pairwise
distinguishable.
6 mark(s)
Page 8 of 27
COMS3003 Formal Languages and Automata April 2012
M3 = (Q3 , {0, 1} , q3 , A3 , δ3 )
that accepts
L3 = {x ∈ {0, 1}∗ | x contains both a 0 and a 1} .
1 mark(s)
(ii) Give A3 .
1 mark(s)
Page 9 of 27
COMS3003 Formal Languages and Automata April 2012
(iii) Complete the following transition table for δ3 . You may leave out the states that are not
reachable, if such states exist.
q δ3 (q, 0) δ3 (q, 1)
4 mark(s)
(iv) Give the states in M3 that are not reachable. If no such state exists, state it clearly.
1 mark(s)
Page 10 of 27
COMS3003 Formal Languages and Automata April 2012
b. Consider the FA
M = ({C, D, E} , {0, 1} , C, {C, D} , δ) ,
where δ is given in the following diagram:
As part of the process to find a minimum-state FA that accepts the same language as M , complete
the following diagram to indicate the situation after the first pass.
3 mark(s)
D
E
q C D
Page 11 of 27
COMS3003 Formal Languages and Automata April 2012
c. Consider the FA
M = ({1, 2, 3, 4, 5, 6, 7, 8, 9} , {a, b} , 1, {5, 6, 9} , δ) ,
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. Here X indicates that the pair is marked.
2
3
4
5 X X X X
6 X X X X
7 X X
8 X X
9 X X X X X X
q 1 2 3 4 5 6 7 8
Page 12 of 27
COMS3003 Formal Languages and Automata April 2012
(i) Will the pair (4, 7) be marked in this pass? Justify your answer.
2 mark(s)
(ii) Will the pair (5, 6) be marked in this pass? Justify your answer.
2 mark(s)
Page 13 of 27
COMS3003 Formal Languages and Automata April 2012
d. Consider the FA
M = ({A, B, C, D, E, F, G, H} , {0, 1} , A, {C} , δ) ,
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 the final pass. Here X indicates that the pair is marked.
B X
C X X
D X X X
E X X X
F X X X X
G X X X X X X
H X X X X X X
q A B C D E F G
On the following page, 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 14 of 27
COMS3003 Formal Languages and Automata April 2012
Page 15 of 27
COMS3003 Formal Languages and Automata April 2012
7 mark(s)
Page 16 of 27
COMS3003 Formal Languages and Automata April 2012
Suppose L is regular. According to the pumping lemma for regular languages, there exists an n such
that for every x ∈ L with |x| ≥ n, x can be written uvw for some u, v and w with |uv| ≤ n, |v| > 0,
and for any m ≥ 0, uv m w ∈ L.
x= .
Then uv = .
Moreover, v = .
uv m w = . . .
= ...
= ...
For m = , uv m w 6∈ L,
since
This contradicts the lemma, therefore our assumption that L is regular is wrong.
8 mark(s)
Page 17 of 27
COMS3003 Formal Languages and Automata April 2012
(i) Lab = ai bi | i ≥ 1
(ii) Lbc = bi ci | i ≥ 1
(iii) Lcd = ci di | i ≥ 1
(iv) Lad = ai di | i ≥ 1
(v) La = ai | i ≥ 1
(vi) Lb = bi | i ≥ 1
(vii) Lc = ci | i ≥ 1
(viii) Ld = di | i ≥ 1
(i) Gab = (Vab , Σ, Sab , Pab ), where Vab = {Sab } and Pab = {Sab → aSab b | ab},
(ii) Gbc = (Vbc , Σ, Sbc , Pbc ), where Vbc = {Sbc } and Pbc = {Sbc → bSbc c | bc},
(iii) Gcd = (Vcd , Σ, Scd , Pcd ), where Vcd = {Scd } and Pcd = {Scd → cScd d | cd},
(iv) Gad = (Vad , Σ, Sad , Pad ), where Vad = {Sad } and Pad = {Sad → aSad d | ad},
(v) Ga = (Va , Σ, Sa , Pa ), where Va = {Sa } and Pa = {Sa → aSa | a},
(vi) Gb = (Vb , Σ, Sb , Pb ), where Vb = {Sb } and Pb = {Sb → bSb | b},
(vii) Gc = (Vc , Σ, Sc , Pc ), where Vc = {Sc } and Pc = {Sc → cSc | c},
(viii) Gd = (Vd , Σ, Sd , Pd ), where Vd = {Sd } and Pd = {Sd → dSd | d},
L = {an bn cm dm | n, m ≥ 1} ,
5 mark(s)
Page 18 of 27
COMS3003 Formal Languages and Automata April 2012
Page 19 of 27
COMS3003 Formal Languages and Automata April 2012
S → AB
A → aAA |
λ
B → bBB |
λ
Using the appropriate algorithm, find the nullable variables. Show all steps.
4 mark(s)
Page 20 of 27
COMS3003 Formal Languages and Automata April 2012
b. Consider the context-free grammar G = ({S, A, B} , {a, b} , S, P ), where P is the set of produc-
tions
S → ASB |
λ
A → aAS |
a
B → SbS |
A |
bb
G1 = ({S, A, B} , {a, b} , S, P1 )
5 mark(s)
Page 21 of 27
COMS3003 Formal Languages and Automata April 2012
c. 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 |
ab
B → bBc |
bc
Using the appropriate algorithm, construct a context-free grammar in Chomsky normal form
G1 = (V, {a, b, c} , S, P1 )
5 mark(s)
Page 22 of 27
COMS3003 Formal Languages and Automata April 2012
Construct a Pushdown Automaton (PDA) M that accepts L. Give the complete definition of M ,
using the given transition table. Please note that the table is given for your convenience—the fact that
the table has 10 moves doesn’t imply that M will necessarily require 10 moves.
10
8 mark(s)
Page 23 of 27
COMS3003 Formal Languages and Automata April 2012
u = an bn cn+1 .
6 mark(s)
Page 24 of 27
COMS3003 Formal Languages and Automata April 2012
b. Consider
L = an bn ci | n ≤ i ≤ 2n .
Is L context-free?
Motivate your answer: If yes, give a grammar that will generate L or a PDA that will recognize L.
If no, use the pumping lemma for context-free languages to prove that L is not context-free.
21 mark(s)
Page 25 of 27
COMS3003 Formal Languages and Automata April 2012
Page 26 of 27
COMS3003 Formal Languages and Automata April 2012
Page 27 of 27