Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

21CS2215RA/21CS2215AA AUTOMATA THEORY AND FORMAL LANGUAGES

(REGULAR / ADVANCED/PEER MENTORS)

TUTORIAL WORKBOOK
Contents

Sno Topic Remarks


1 Finite Automata with Output - Mealy and Moore Machines
2 Minimization of DFA
3 NFA, DFA and Regular Expressions
4 Pumping Lemma for Regular Languages
5 Design of Context Free Grammar for CFL
6 CFG Simplification
7 Ambiguity in Context Free Grammars
8 Designing Pushdown Automata
9 PDA – CFG Conversions
10 Designing Turing Machines

2
Tutorial—1 : Finite Automata with Output—Mealy and Moore Machines

1.1 Construct a Mealy machine M that takes as input strings of 0’s and 1’s. Its output is to be
a string of 0’s until the first 1 occurs in the input, at which time it will switch to printing 1’s.
This is to continue until the next 1 is encountered in the input, when the output reverts to 0.
The alternation continues every time a 1 is encountered. For example, FM (0010010) =

0011100.

1.2 Convert the Mealy machine constructed in 1.1 to its equivalent Moore Machine.

3
Tutorial—2: Minimization of DFA

2.1 Find minimal dfa's for the following languages. In each case prove that the result is
minimal.

(a) L = {an bm> :n≥2,m≥1}.


(b) L = {an b:n ≥0} ∪{bn a:n ≥1}

(c)L={an :n≥0,n≠3}.

2.2 Minimize the states in the dfa depicted in the following diagram.

4
Tutorial—3: NFA, DFA and Regular Expressions

3.1 For each of the languages below, over the alphabet {0, 1}, specify a DFA. Use a state
diagram to specify your DFAs unless either the number of states is too large or the diagram too
clumsy. In such cases, specify specify the DFA formally, using appropriate mathematical
notation.

1. The set of all strings in {0, 1}∗ except 11 and 111.

2. {x ∈ {0, 1}∗ : x does not contain the substring 110}.

3. The set of all strings in {0, 1}∗ such that each string is of length at least three and every
block of three con- secutive symbols has at least one 0. (Thus, for example, 0011001 is
in the language, but 0011100 is not.)

3.2 Give regular expressions for the following languages.

1. {w ∈ {0, 1}∗ : w has three consecutive 0’s or three consecutive 1’s or both}.

2. {w ∈ {0, 1}∗ : w has three consecutive 0’s and three consecutive 1’s}.

3. The set of strings in {0, 1}∗ with an equal number of 0’s and 1’s such that no prefix has
two more 0’s than 1’s nor two more 1’s than 0’s.

5
Tutorial—4: Pumping Lemma for Regular Languages

4.1 For each of the following languages, say whether or not the language is regular and prove
your answer. To prove that a language is regular, specify a finite automaton or a regular
expression for that language. To prove that a language is not regular, use the pumping lemma.

a. L= {0m1n0m+n : m, n ≥ 0}.

b. {0m1n : m divides n}.

c. {xwxR : x,w ∈ {0,1}∗,|x| > 0 and |w| > 0}.

n
d. {02 : n ≥ 0}.

e. {0m1n :m,n≥0andm̸=n}.

6
Tutorial—5: Design of Context Free Grammar for CFL

1. Design a context-free grammar that generates the language


{x∈{0,1}∗ : x is not of the form ww for any w∈{0,1}∗}.

2. Consider the following CFG:

S −→1S00|00S1|SS |0S1S0|ε

Give a simple description of the language it generates, in the form {x ∈ {0, 1}∗ : ⟨some simple
property of x⟩}. The simple property might be expressed as an equation or a sentence or some
combination of the two.

7
Tutorial—6: CFG Simplification and Normal Forms

6.1 Eliminate useless productions from

6.2 Remove all unit-productions, all useless productions, and all λ-productions from the
grammar

8
Tutorial—7: Ambiguity in Context Free Grammars

7.1 Show that the following grammar is ambiguous.

7.2 Show that the following grammar is ambiguous.

9
Tutorial—8: Designing Pushdown Automaton

8.1 Design pushdown automata (PDAs) for each of the following languages:

1. {x ∈ {0, 1}∗ : x contains more 0’s than 1’s}.


2. {x ∈ {0, 1}∗ : |x| is odd and the middle symbol of x is a 0}.
3. x ∈ {0,1,2}∗ : N0(x) = N1(x) or N1(x) = N2(x)}. Here Ni(x) denotes the number of
occurrences of the character i in the string x.

10
Tutorial—9: Pushdown Automata to CFG Conversion

9.1 Construct an npda that accepts the language generated by the grammar

9.2 Construct an npda corresponding to the grammar

9.3 Find a context-free grammar that generates the language accepted by the npda M =
({q0,q1}, {a, b}, {A, z},δ, q0, z, {q1}), with transitions

δ(q0, a,z) = {(q0, Az)},

(q0,b, A) = {(q0, AA)},

δ(q0, a, A) = {(q1)λ}

11
Tutorial—10: Designing Turing Machines

10.1 Construct Turing machines that will accept the following languages on {a, b}.

(a) L = L(aba*b).
(b) L = {w : |w| is even}.
(c) L = {w : |w| is a multiple of 3}.

(d) L = {anbm: n≥1, n ≠m}. (e) L = {w: na(w)= nb(w)}.

(f) L = {anbman+m : n ≥ 0,m ≥1}.

(g) L = {anbnanbn : n ≥0}.

(h) L = {anb2n: n ≥ 1}.

12

You might also like