Tutorial 1
Tutorial 1
Tutorial No: 1
np
(a) {w {a, b} : each a in w is immediately preceded and immediately followed by a "b" }.
u.
. ed
es
ot
(b) {w {a, b} : w has abab as a substring}. en
io
m
fro
d
de
oa
Page 1 of 23
Tutorial No: 1 (Related to NFA/DFA/Regular Expression)
np
u.
. ed
es
(c) {w {a, b} : w has an odd number of a's and an even number of b's}.
ot
en
io
m
fro
Page 2 of 23
Tutorial No: 1 (Related to NFA/DFA/Regular Expression)
Design a DFA that accepts the language L= { x {0,1}* : the third bit from the left is 1 in x}
np
u.
. ed
es
ot
Design a DFA that accepts the language L= { x {0,1}* : the third bit f x from its right end is
1}
en
io
m
fro
d
de
oa
nl
ow
D
Design a DFA that accepts the language L= { x {0,1}* : 0110 occurs as a substring in x}
Page 3 of 23
Tutorial No: 1 (Related to NFA/DFA/Regular Expression)
np
u.
ed
Design a DFA that accepts the language L= { x {0,1}* : 0110 does not occurs as a substring
in x}
.
es
ot
en
io
m
Design a DFA that accepts the language L= { x {0,1,2} : the sum of digits in x is 2 mod 3 }
fro
d
de
oa
nl
ow
D
Page 4 of 23
Tutorial No: 1 (Related to NFA/DFA/Regular Expression)
np
u.
. ed
es
ot
en
io
Construct a DFA that accepts set of strings where the number of 0s in every string is multiple
of three over alphabet {0, 1}
m
Construct a DFA that accepts set of strings where the number of 1s in every string is exactly 1
fro
Page 5 of 23
Tutorial No: 1 (Related to NFA/DFA/Regular Expression)
np
u.
ed
(c) ((a*b*a*)*b)*
.
es
ot
en
io
(d) (baUb)*U(bbUa)*
Using the construction in the proofs of Theorem: Regular languages are closed under Union,
m
Concatenation, and Kleene Star , etc. ) construct finite automata accepting these languages.
fro
(a) a*(abUbaUe)b*
(b) ((aU b)*(e U c)*)*
(c) ((ab)* U (bc)*)ab
Construct a simple nondeterministic finite automaton to accept the language (ab U aba) * a. Then
d
apply to it the construction of Keene star of the proof of Theorem Theorem: Regular languages
de
are closed under Union, Concatenation, and Kleene Star , etc. ) to obtain a nondeterministic
finite automaton accepting
oa
((ab U aba)*a)*.
Design a NFA that accepts the language L= { x {0,1}* : x has a substring either 010 or 11}
Design a DFA that accepts the language L= { x {0,1}* : the fourth bit of x from its right end
nl
is 1 }
i j
Construct a NFA that accepts the language L={ 0 1 2K : i,j,k >=0} and the convert it into DFA
ow
Design a DFA that accepts the language L = {w | w contains at least one 1 and a even number
of 0s follow the last 1}
D
Page 6 of 23
Tutorial No: 1 (Related to NFA/DFA/Regular Expression)
np
Obtain the DFA that accepts/recognizes the language L(M) = {w | w = {a, b, c}* and w contains
the pat tern abac}
u.
. ed
es
Given = {a, b}, construct a DFA that shall recognize the language L ={bmabn :m, n 0}.
ot
en
io
m
Given ={a, b}, construct a DFA which recognize the language L ={a mbn :m, n 0}.
fro
d
de
oa
Construct a DFA which recognizes the set of all strings on alphabet = {a, b} starting with the
prefix ab.
nl
ow
D
Page 7 of 23
Tutorial No: 1 (Related to NFA/DFA/Regular Expression)
np
u.
ed
Determine the DFA that will accept those words from alphabets {a, b} where the number of
.
bs is divisible by three. Sketch the state table diagram of the finite Automaton M also.
es
ot
en
io
m
fro
Page 8 of 23
Tutorial No: 1 (Related to NFA/DFA/Regular Expression)
Design a DFA for the language L=(ababa)* and Convert it into NFA without e-transitions and
with e-transitions
Solutions
To see that a nondeterministic finite automaton can be a much more convenient device
to design than a deterministic finite automaton, consider the language L = (ab U aba)*,
np
which is accepted by the deterministic finite automaton illustrated in below
u.
. ed
es
ot
L is accepted by the simple nondeterministic device shown in fig below
en
io
m
fro
d
Construct a DFA that accepts set of strings either starts with 01 or end with 01 over alphabet
{0, 1}
Page 9 of 23
Tutorial No: 1 (Related to NFA/DFA/Regular Expression)
Construct a NFA accepting language L= (ab)*(ba)* aa*, and Convert the designed NFA into
DFA.
n:
Determine the DFA if = {a, b} for Language generated LA =( ab)* = (ab) , n 0 (e-not
accepted)
np
u.
. ed
es
n:
Determine the DFA if = {a, b} for Language generated LB =( ab)* = (ab) , n 1 (e-not
accepted)
ot
en
io
m
fro
Determine the DFA with the set of strings having aaa as a subword.
d
de
oa
Determine an NFA accepting all strings over {0,1} which end in 1 but does not contain the
substring 00.
Page 10 of 23
Tutorial No: 1 (Related to NFA/DFA/Regular Expression)
np
*
Obtain an NFA which should accept a language LA, given by LA = { x {a, b} : |x| 3 and
third symbol of x from the right is { a}.
u.
. ed
es
Determine a NFA accepting {ab, ba} and use it to find a DFA accepting it.
ot
en
io
m
fro
d
de
oa
nl
ow
D
Page 11 of 23
Tutorial No: 1 (Related to NFA/DFA/Regular Expression)
np
u.
. ed
es
ot
en
io
m
fro
Given the NDFA as shown in Fig. , Determine the equivalent DFA for the above given NDA.
d
Solutions
de
oa
nl
ow
D
Page 12 of 23
Tutorial No: 1 (Related to NFA/DFA/Regular Expression)
np
u.
. ed
es
An NFA that accepts all strings over {0, 1} that contain a 1 either at the third position from the
end or at the second position from the end is given below, Determine the equivalent DFA .
ot
en
io
Solutions
m
fro
d
de
oa
nl
ow
D
Page 13 of 23
Tutorial No: 1 (Related to NFA/DFA/Regular Expression)
np
u.
. ed
es
ot
en
io
m
fro
d
de
oa
nl
ow
Page 14 of 23
Tutorial No: 1 (Related to NFA/DFA/Regular Expression)
np
u.
. ed
es
2. Minimise the following DFA
ot
Current state input symbol
q0
a
q5
b
q1
en
io
q1 q2 q6
*q2 q2 q0
q4 q5 q7
m
q5 q6 q2
q6 q4 q6
fro
q7 q2 q6
q3 q6 q2
d
de
Step 1: Eliminate any state that can't be reached from the start state
In above, the state q3 can't be reached. So remove the corresponding to q3 from the
oa
a b
q0 q5 q1
ow
q1 q2 q6
*q2 q2 q0
q4 q5 q7
D
q5 q6 q2
q6 q4 q6
q7 q2 q6
Page 15 of 23
Tutorial No: 1 (Related to NFA/DFA/Regular Expression)
Step 2: Divided the rows of the table into 2 sets as
1. one set containing only rows which starts from non final states
Set 1
q0 q5 q1
q1 q2 q6
np
q4 q5 q7
q5 q6 q2
q6 q4 q6
u.
q7 q2 q6
2. another set containing those rows which start from final states
ed
* q2 q2 q0
Step 3a: Consider the set 1
.
es
q0 q5 q1 Row1
q1 q2 q6 Row2
q4 q5 q7 Row3
ot
q5 q6 q2 Row4
q6 q4 q6 Row5
q7 q2 q6 Row6
en
io
Row 2 and Row 6 are similar since q1 and q7 transit to same states on inputs a and b
so remove one of them (for instance q7) and replace q7 with q1 in rest we get
m
Set 1
q0 q5 q1 Row1
fro
q1 q2 q6 Row2
q4 q5 q1 Row3
q5 q6 q2 Row4
d
q6 q4 q6 Row5
Now Row 1 and Row 3 are similar. So remove one of them (for instance q4) and
de
Set 1
q0 q5 q1 Row1
q1 q2 q6 Row2
nl
q5 q6 q2 Row3
q6 q0 q6 Row4
ow
Set 2
*q2 q2 qq0
Do the same process for set 2
Page 16 of 23
Tutorial No: 1 (Related to NFA/DFA/Regular Expression)
But it contains only one row .It is already minimized
Step 4
Combine set 1 and set 2 we get
Current state input symbol
np
a b
q0 q5 q1
q1 q2 q6
u.
q5 q6 q2
q6 q0 q6
ed
*q2 q2 q0
Now this is minimized DFA
The transition diagram is
.
es
ot
en
io
m
fro
The language L = {vv | v {0, 1} } is not regular (F is the language of all even length strings
over {0, 1} whose first half is identical to the second half).
i j
L = {0 1 : i > j} is not regular
nl
n2:
L = {1 n 0} is not regular.
ow
n
L = {1 : n is a prime number} is not regular.
n n
L= { a b a for n=0,1,2. } in not regular
n
D
Page 17 of 23
Tutorial No: 1 (Related to NFA/DFA/Regular Expression)
L= { an! : n 1 } is not regular
[D] Problems related to Regular Expressions
np
u.
. ed
es
Solutions
ot
en
io
m
fro
d
de
oa
b. {b2 , b5 , b8 , .. }
c. {a 2n+1 | n > 0}
ow
Solution
D
Page 18 of 23
Tutorial No: 1 (Related to NFA/DFA/Regular Expression)
np
u.
3. Obtain the regular expressions for the languages given by:
. ed
es
ot
Solutions
en
io
m
fro
d
de
4. Find regular expressions over S = {a, b} for the language defined as follows:
oa
nl
Solutions
ow
D
Page 19 of 23
Tutorial No: 1 (Related to NFA/DFA/Regular Expression)
np
u.
. ed
es
5. Determine all strings in L((a + b)* b(a + ab)* ) of length less than four.
Solutions
ot
en
6. Find the regular expressions for the languages defined by
io
m
fro
Solutions
d
de
oa
nl
ow
D
*
7. Determine the NFA for regular expression a. (a+b) .b. b - See on AK Panday Book
8. Construct the e-NFA for the regular expression (0+1)* (0+1) AK Panday Book
Page 20 of 23
Tutorial No: 1 (Related to NFA/DFA/Regular Expression)
9. Find the regular expression for the DFAs given below (Use Arden's Theorem)- AK Panday
Book
np
u.
. ed
es
Solution
ot
en
io
m
fro
d
de
oa
nl
ow
D
Page 21 of 23
Tutorial No: 1 (Related to NFA/DFA/Regular Expression)
np
u.
. ed
es
ot
en
io
m
fro
d
de
Solutions : Do yourself
oa
nl
ow
D
Solutions
Page 22 of 23
Tutorial No: 1 (Related to NFA/DFA/Regular Expression)
np
u.
. ed
es
ot
en
io
m
fro
d
de
oa
nl
ow
D
Page 23 of 23
Tutorial No: 1 (Related to NFA/DFA/Regular Expression)