0% found this document useful (0 votes)
29 views

2012 April COMS3003

Uploaded by

Ureeshah Moodley
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

2012 April COMS3003

Uploaded by

Ureeshah Moodley
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

EXAMS OFFICE

hrs / /9 USE ONLY


.....................................................................................................
University of the Witwatersrand, Johannesburg

Course or topic No(s) COMS3003

Course or topic name(s)


Formal Languages and Automata
Paper Number & title

Exam to be
April 2012
held during the months(s) of

Year of Study

Degrees/Diplomas for which


BSc, BEconSc, BCom
this course is prescribed

Faculty/ies presenting Science; Commerce, Law and Management


candidates

Internal examiner(s)
and telephone extension Prof. S. Ewert x76180
number(s)

External examiner(s) Prof. James Gain, UCT

Special materials required None

Course
Time allowance COMS3003 Hours 3
nos

This is an open book examination. 130 marks = 100%.


Instructions to candidates
There are 130 marks available.
2
* As Internal Examiner/Head of Department, I certify that this question paper is in final form, as
approved by the External Examiner, and is ready for reproduction.

** As Internal Examiner, I certify that this question paper is in final form and is ready for reproduc-
tion.

* applicable to formal examinations as approved by an external examiner.


** applicable to formal tests not requiring approval by external examiner.

Delete whichever not applicable.

Name: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Signature: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

(NOT FOR REPRODUCTION)


School of Computer Science
University of the Witwatersrand, Johannesburg

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.

• xr indicates the reverse of the string x.

For lecturer’s use only


Question no. Maximum marks Marks obtained
1 4
2 6
3 29
4 29
5 8
6 5
7 14
8 8
9 27

Page 1 of 27
COMS3003 Formal Languages and Automata April 2012

Questions: please turn over

Page 2 of 27
COMS3003 Formal Languages and Automata April 2012

Question 1 — Languages in general


a. Let
L1 = {w ∈ {a, b}∗ | na (w) > nb (w) ; na (w) , nb (w) ≥ 1}
and
L2 = {w ∈ {a, b}∗ | na (w) < nb (w) ; na (w) , nb (w) ≥ 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.

(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 .

[Total marks for Question 1 = 4 marks]

Page 3 of 27
COMS3003 Formal Languages and Automata April 2012

Question 2 — Regular expressions


Give a regular expression for the following language:

L = {w ∈ {a, b}∗ | w consists of alternating a’s and b’s; na (w) , nb (w) ≥ 1} .

6 mark(s)

[Total marks for Question 2 = 6 marks]

Page 4 of 27
COMS3003 Formal Languages and Automata April 2012

Question 3 — Regular and Nonregular Languages


a. Let L = an b2n | n ≥ 1 .


(i) Then [λ], the equivalence class containing λ, . . .


(circle the label of the correct answer)
1. equals {λ}.
2. equals L.
3. equals {w ∈ {a, b}∗ | w is not a prefix of any x ∈ L}.
4. More than one of the above.
5. None of the above.
(ii) Then a2 b4 , the equivalence class containing a2 b4 , . . .
 

(circle the label of the correct answer)


1. equals {λ}.
equals a2 b4 .

2.
3. equals L.
4. More than one of the above.
5. None of the above.
(iii) Then a2 b3 , the equivalence class containing a2 b3 , . . .
 

(circle the label of the correct answer)


1. equals {λ}.
2. equals L.
equals an b2n−1 | n ≥ 1 .

3.
4. More than one of the above.
5. None of the above.
(iv) Then a2 b5 , the equivalence class containing a2 b5 , . . .
 

(circle the label of the correct answer)


1. equals {λ}.
2. equals L.
equals a2 b5 .

3.
4. equals {w ∈ {a, b}∗ | w is not a prefix of any x ∈ L}.
5. More than one of the above.
6. None of the above.

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 .

(i) L = {w ∈ {a, b}∗ | na (w) 6= nb (w)}.

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.

(i) L = {w ∈ {a, b}∗ | na (w) 6= nb (w)}.

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

e. Consider L = w ∈ {a, b, c}+ | na (w) < nb (w) < nc (w) .




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)

[Total marks for Question 3 = 29 marks]

Page 8 of 27
COMS3003 Formal Languages and Automata April 2012

Question 4 — Finite Automata and Decision Algorithms


a. Let
M1 = ({p, q} , {0, 1} , p, {q} , δ1 ) ,
and
M2 = ({r, s} , {0, 1} , r, {s} , δ2 ) ,
be Finite Automata recognizing languages L1 and L2 , respectively, where δ1 and δ2 are given in
Figures 1 (a) and (b) respectively:

Figure 1: M1 and M2 , respectively.

Using M1 and M2 only, construct the Finite Automaton (FA)

M3 = (Q3 , {0, 1} , q3 , A3 , δ3 )

that accepts
L3 = {x ∈ {0, 1}∗ | x contains both a 0 and a 1} .

Use the notation AQ for the states in Q3 .

(i) Give the start state of M3 .

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

Consider the next pass.

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

Please answer Question 4.d here.

Page 15 of 27
COMS3003 Formal Languages and Automata April 2012

e. Given two FAs M1 = (Q1 , Σ, q1 , A1 , δ1 ) and M2 = (Q2 , Σ, q2 , A2 , δ2 ), and two states p, q ∈ Q1 ,


is there a string x ∈ L (M2 ) so that δ1∗ (p, x) = q?

7 mark(s)

[Total marks for Question 4 = 29 marks]

Page 16 of 27
COMS3003 Formal Languages and Automata April 2012

Question 5 — The Pumping Lemma for Regular Languages


Consider the language n o
L = ak bm ap | k, m, p ≥ 1, p ≥ k + m .
We want to prove that L is not regular.

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.

Let n be the integer in the statement of the pumping lemma.

Choose x so that |x| ≥ n.

Complete the proof.

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.

8 mark(s)

[Total marks for Question 5 = 8 marks]

Page 17 of 27
COMS3003 Formal Languages and Automata April 2012

Question 6 — Context-Free Languages


a. Consider

(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


These languages are generated by the grammars

(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},

respectively, where Σ = {a, b, c, d}.


Construct a context-free grammar G for generating

L = {an bn cm dm | n, m ≥ 1} ,

using the given languages and grammars only.

5 mark(s)

Page 18 of 27
COMS3003 Formal Languages and Automata April 2012

[Total marks for Question 6 = 5 marks]

Page 19 of 27
COMS3003 Formal Languages and Automata April 2012

Question 7 — Chomsky Normal Form


a. Consider the context-free grammar G = ({S, A, B} , {a, b} , S, P ), where P is the set of produc-
tions

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

The nullable variable is S.


Using the appropriate algorithm, construct a context-free grammar without λ-productions

G1 = ({S, A, B} , {a, b} , S, P1 )

that generates L (G) \ {λ}.

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 )

that generates L (G).

5 mark(s)

[Total marks for Question 7 = 14 marks]

Page 22 of 27
COMS3003 Formal Languages and Automata April 2012

Question 8 — Pushdown Automata


Consider the language

L = {x ∈ {0, 1}∗ | every prefix of x has at least as many 0’s as 1’s} .

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.

Move State Input Stack Move(s)


No. symbol

10

8 mark(s)

[Total marks for Question 8 = 8 marks]

Page 23 of 27
COMS3003 Formal Languages and Automata April 2012

Question 9 — The Pumping Lemma for Context-free Languages


a. Consider
L = ai bi cj | i, j ≥ 1, i < j .


We want to prove that L is not context-free.


Suppose L is context-free. According to the pumping lemma, there is an integer n so 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 so that |u| ≥ n; we choose

u = an bn cn+1 .

Suppose v, w, x, y, and z are any strings satisfying the conditions above.


Complete the following parts of the proof.
If w and y contain

(i) a’s only, then vwm xy m z 6∈ L for


m= ,
since

(ii) c’s, then vwm xy m z 6∈ L for


m= ,
since

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

[Total marks for Question 9 = 27 marks]

Page 26 of 27
COMS3003 Formal Languages and Automata April 2012

End of question paper

Page 27 of 27

You might also like