You are on page 1of 3

1.

Given the following non-deterministic finite state automaton:

i. Construct a deterministic finite state automaton. [4]


ii. Give the regular expression for the machine by applying the state elimination
algorithm and eliminate states in the order q2, q1 and q0 [5]
iii. Give the regular grammar for the language generated by the machine [2]
iv. In your vernacular language, describe the language defined by the machine [2]

a) L1 is the language over the alphabet {a, b} of strings which do not contain double b. L2 is
the language over the alphabet {a, b} of strings that end with letter a.

i. Give the transition diagram of a deterministic finite automaton for L1. [3]
ii. Give a regular grammar for L1. [2]
iii. Give the transition diagram of a deterministic finite automaton for L2. [1]
iv. Give transition diagram of a deterministic finite automaton L2*. [3]
v. Give the transition diagram of a deterministic finite automaton for L1  L2. [5]
vi. Give the transition diagram of a deterministic finite automaton for L1  L2. [1]
vii. Give the transition diagram of a deterministic finite automaton for L2 L1. [8]
viii. Give the transition diagram of a deterministic finite automaton for L1 L2. [5]
ix. Give the transition diagram of a deterministic finite automaton for L2 L1. [5]
x. Hence or otherwise show that L2 L1 ≠L1 L2 [2]

2. Give a deterministic finite automaton over { } that accepts each of the


language defined the following RE:
a. 1*01*01* [4]
b. 1*0 (1* 01* 01*)*1* [5]
c. 1*(101*0*01+100+000*)(0+1)* [5]
d. (1+ 0)* 0 (0 + 1)* [5]
* *
e. 1(0 + 1) 0 + 0(0 + 1) 1 [4]
f. For the language defined as the set of all strings over {0, 1, 2} in which there are
at least two occurrences of 0 between any two occurrences of 2.
i. Construct a deterministic finite automaton [6]
ii. Give the RE [5]
iii. Give the RG [5]
3. Construct a deterministic finite automaton that accepts all strings of valid basic
mathematical expressions in Java. Your machine must accept strings like
{count=num1+num;, difference= x-y; , and other expressions which only use the
subtraction, addition, multiplication and division operator. [Hint you can use any
symbol to represents sets of symbols eg C to represent the set {a..z}.]
[7]
4. L is the language over {a, b, c} of strings which start and end with different symbols.
M is the language over {a, b, c} of strings which do not contain the string cc.
g. Give a regular expression for L. [5]
h. Give a regular expression for M. [5]
i. Give a regular grammar for L. [5]
j. Give a regular grammar for M. [5]

5. L is the language over {0, 1, 2} of strings with an odd number of 1s followed by an


even number of 2s followed by an odd number of 0s. M is the language over {0, 1, 2}
of strings with up to three 0s followed by an odd number of 2s followed by more than
two 1s.
k. Give the transition diagram of a deterministic finite automaton for L. Your
transition diagram may not contain Λ-transitions. [4]
l. Give a regular expression for L. [3]
m. Give a regular grammar for L. [3]
n. Give the transition diagram of a deterministic finite automaton for M. Your
transition diagram may not contain Λ-transitions. [5]
o. Give a regular expression for M. [3]
p. Give a regular grammar for M. [3]

6. Consider the following BNF definition of simple assignment statements:

<assign> → <id> = <expr>


<id> → A | B | C

<expr> → <expr> + <term> | <term>

<expr> → <expr> - <term> | <term>

<term> → <term> * <factor> | <factor>

<factor> → ( <expr> ) | <id>

i. Create a rightmost derivation to show that the following string is a legal assignment
statement: C = (A - C) * ((A * C)-B) [10
Marks]
ii. Create a parse tree to show that the following string is a legal assignment statement: C
= (A - C) * ((A * C)-B) [10 Marks]

7. L is the language over alphabet {a, b, c} in which every string has the same number of as and
bs, all the as come before the bs, and arbitrarily many cs can be in front, behind or
among the as and bs. For example, L includes the strings abc, caabcb,
ccacaabcccbcbcc and so on.
i. Give a context-free grammar for L. [5]

8. Using the pumping lemma, prove that the Language L= {0n110n for n = 0, 1, 2, 3, E}
is not regular. [5]

You might also like