Finite Automata Notes
Finite Automata Notes
17.1 INTRODUCTION
The term ‘finite automata’ describes a class of models of computation that are
characterised by having a finite number of states. Finite automata are computing devices that
accept/recognize regular languages and are used to model operations of many systems we find
in practice. Their operations can be simulated by a very simple computer program.
The automata might initially not seem very useful since their response to an input is to
output either a ‘yes’ or a ‘no’. They have applications in modelling hardware, building compilers,
program verification, and so on.
It will sometimes be easier to find one of the more general kinds of automata that
accept a given language rather than one of the more restricted kinds accepting the language.
And, there are languages where the smallest DFA accepting the language is exponentially
bigger than the smallest FA accepting the language. So, we will give algorithms for converting
the NFA to DFA, NFA-ε to NFA and minimization of DFA etc. The Deterministic Finite
Automata (DFA) will accept the same set of languages as the finite automata. In the later
sections the finite automata with output is introduced that have real life applications. Further,
the languages and Chomsky hierarchy is described in detail.
550
EBSCO Publishing : eBook Collection (EBSCOhost) - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW
AN: 1223926 ; Satinder Bal Gupta.; Discrete Mathematics and Structures
Account: ns190198.main.ehost
FINITE AUTOMATA AND LANGUAGES 551
e.g., 1. The set of strings ending with 00 over the alphabet {0, 1} is an infinite language.
The members of this languages are 00, 100, 000, 0000, 1000, 1100 ...... etc.
2. Consider the alphabet ∑ = {0, 1}. The following sets are all languages over the
alphabet ∑.
L1 = {0, 00, 01, 10, 100, 101}
L2 = {010, 11011}
L3 = { }
and L4 = {0n 10n | n ≥ 1}
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
552 DISCRETE MATHEMATICS AND STRUCTURES
(d) The regular expressions are only those that are obtained using rules (a) to (c).
e.g., 1. The 11 is a regular expression over the alphabet ∑ = {0, 1} representing the set {11}.
2. The (0 + 1)* is a regular expression over the alphabet ∑ = {0, 1} representing all
strings of 0’s and 1’s.
3. The (0 + 1)* 00 is a regular expression denoting all strings of 0’s and 1’s ending with
00.
4. The (1 + 10)* is a regular expression denoting all string of 0’s and 1’s that begins
with 1 and not having two consecutive zeroes.
5. The 0*1* is a regular expression denoting all strings of 0’s and 1’s having any number
of zeroes followed by any number of 1’s.
Example 1. Make a DFA M that accepts the language of all strings of 0’s and 1’s that
ends with 00.
Sol. The automata M is defined by representing its five parts, which is as follows.
1. Q = {q0, q1, q2}
2. ∑ = {0, 1}, input symbols
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
FINITE AUTOMATA AND LANGUAGES 553
States Inputs
0 1
q0 q1 q0
q1 q2 q0
q2 q2 q0
Fig. 17.1
Example 2. Draw the state diagram of the automata M, defined in the previous example.
Sol.
1 0
0 0
q0 q1 q2
1
Fig. 17.2
The Fig. 17.2 defines the automata M, which accepts all the strings of 0’s and 1’s that
ends with double 0.
In this the final state q2, is represented by a double circle, and the initial state q0 is
represented by special arrow.
Note. From now onwards, we will represent the finite state automata with its state
diagram unless and until not specified.
Example 3. Construct a DFA that accepts the language of all strings of 0’s and 1’s
which contains 000 as substring.
Sol. The DFA, accepting the language is shown in Fig. 17.3.
1
0, 1
0 0 0
q0 q1 q2 q3
1
Fig. 17.3
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
554 DISCRETE MATHEMATICS AND STRUCTURES
By acceptance of strings, we mean that M recognises the string w iff it halts in the final
state.
A language L over an alphabet Σ is called regular iff there exists a finite state automata
M such that L = L (M).
Example 4. Determine whether or not the automata M as shown in Fig. 17.4 accepts the
following strings or not :
(a) 0100 (b) 1101 (c) ε (d) 010101010.
0 1 q1
1
0
q0 1 q3
0, 1 0
q2
Fig. 17.4
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
FINITE AUTOMATA AND LANGUAGES 555
by a nondeterministic finite automata if and only if at least one of the possible transition
sequences leads to a final state.
NFA’s are not more powerful than Deterministic Finite Automata’s (DFA’s) as language
recognizer as they accept the same class of languages. This means they are equivalent but
they are convenient to construct and use.
Example 5. Construct an NFA that accepts the language L = {w ∈ {a, b}*: w starts with a}
Sol. The NFA is shown in Fig. 17.5.
a, b
a
0 1
Fig. 17.5
Example 6. Construct an NFA to accept all strings that ends with 1.
Sol. The NFA is shown in Fig. 17.6.
Start q0 0 q1 1 q2
0, 1
Fig. 17.6
Example 7. Construct an NFA to accept all strings that contain three consecutive zeroes.
Sol. The NFA is shown in Fig. 17.7.
Start q0 0 q1 0 q2 0 q3
0, 1 0, 1
Fig. 17.7
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
556 DISCRETE MATHEMATICS AND STRUCTURES
NFA-∈’s are not more powerful than NFA’s and DFA’s as language recognizer as they
accept the same class of languages. This means they are equivalent but they are convenient to
construct and use.
Example 8. Construct an NFA-∈ that accepts all strings over {a, b, c} that are missing
at least one letter. For example, aabba, cbbc, ccacc ∈ L, while abbc does not belong to L.
Sol. The NFA-∈ is shown in Fig. 17.8.
e e e
1 2 3
a, b b, c a, c
Fig. 17.8
Example 9. Construct NFA-∈ that accept all strings containing two zeroes seperated by
a substring of length 4n, where n ≥ 0.
Sol. The NFA-∈ is shown in Fig. 17.9.
Start 0 0, 1 0, 1 0, 1 0, 1 0
q0 q1 q2 q3 q4 q5 q6
Fig. 17.9
Example 10. Construct NFA-∈ that accept all strings which consist of any number of
0’s followed by any number of 1’s followed by any number of 0’s
Sol. The NFA-∈ is shown in Fig. 17.10.
0 1 0
q0 e q1 e q2
Fig. 17.10
17.9 ∈ MOVES
EQUIVALENCE OF DFAS, NFAS AND NFA-∈
Any language recognized by a DFA is regular and that any regular language is recognized
by a DFA. All regular languages are recognized by DFA’s and using union, concatenation and
Kleene closure operations, DFAs can recognize more complex languages. The operations on
FAs can be described conveniently using NFA- ∈s. These NFA-∈’s are then converted to
equivalent NFAs without ∈ moves and then to DFAs. This means they are equivalent as
discussed earlier.
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
FINITE AUTOMATA AND LANGUAGES 557
1
a a
0 b a 3
a
a
b
2
Fig. 17.11
Sol. Initially Q is empty. Then since the initial state of the DFA is {0} , {0} is added to
Q. Since δ′ (0, a) = {1, 2}. Therefore, {1, 2} is added to Q as a new state and an entry to the
transition function of δ ({0}, a) = {1, 2}.
Since δ′(0, b) = ∈. Thus ∈ is added to Q and ({0}, b) = ∈ in transition function.
At this point, we have Q = {{0}, {1, 2}, ∈}.
Since {1, 2} is now in Q, the transitions from {1, 2} on symbols a and b are computed.
Since δ (1, a) = {1, 2} , and δ′ (2 , a) = ∈. Therefore, δ ({1, 2}, a) = {1, 2}. Similarly δ ({1, 2}, b) =
{1, 3}. Thus {1, 3} is added to Q.
Similarly δ ({1, 3}, a) = {1, 2} and δ ({1, 3}, b) = ∈. Thus no new states are added to Q.
Since the transitions from all states of Q have been computed and no more states are added to
Q, the conversion process stops here.
Note that there are no states of Q′ in ∈. Hence there are no states that M′ can go to from
∈. Hence δ (∈, a) = δ (∈, b) = ∈.
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
558 DISCRETE MATHEMATICS AND STRUCTURES
For the Final states of M, since states 0 and 1 are the accepting states of the NFA, all
the states of Q that contain 0 and/or 1 are accepting states. Hence {0}, {1, 2} and {1, 3} are the
accepting states of M.
The equivalent DFA obtained from the above discussion is as shown in Fig. 17.12.
{1, 2}
a
a
b
a, b b {1, 3}
b
{0}
2
f
Fig. 17.12
Example 12. Convert the NFA given in Fig. 17.13 to DFA.
Transition table for NFA
States a b
→ q0 {q0, q1 } {q2}
q1 {q0} {q1}
q2 Φ {q0, q1}
Fig. 17.13
Sol. In NFA, M′ = (Q′, Σ, δ′, q′, F′), Thus M′ = ({q0, q1, q2}, {0, 1}, δ′, q0, {q2})
q0 is a starting state, therefore add it in DFA M;
Further, we have δ′ (q0, a) = {q0, q1}; a new state, add it in DFA M
δ′ (q0, b) = {q2}; a new state, add it in DFA M
Next we have to
δ ({q0, q1}, a) = δ′ (q0, a) ∪ δ′ (q1, a)
= {q0, q1} ∪ {q0} = {q0, q1}; an old state, already in DFA M
δ ({q0, q1}, b) = δ′ (q0, b) ∪ δ′ (q1, b)
= {q2} ∪ {q1} = {q1, q2}; a new state, add it in DFA M
δ ({q2}, a) = δ′ (q2, a) = Φ; a new state, add it in DFA M
δ ({q2}, b) = δ′ (q2, b) = {q0, q1}; an old state, already in DFA M
δ ({q1, q2}, a) = δ′ (q1, a) ∪ δ′ (q2, a)
= {q0 } ∪ Φ = {q0}; an old state, already in DFA M
δ ({q1, q2}, b) = δ′ (q1, b) ∪ δ′ (q2, b)
= {q1} ∪ {q0, q1} = {q0, q1}; an old state, already in DFA M
Note that there are no states of Q′ in ∈. Hence there are no states that M′ can go to
from ∈. Hence δ (∈, a) = δ (∈, b) = ∈.
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
FINITE AUTOMATA AND LANGUAGES 559
Since the transitions from all states of Q have been computed and no more states are
added to Q, the conversion process stops here.
Transition table for Minimized DFA is shown in Fig. 17.14
States i/p symbols
a b
→ q0 {q0, q1} {q2}
{q0, q1} {q0, q1} {q2, q2}
{Φ} Φ Φ
Fig. 17.14
a b
a, b
b
a, b
0 2
b
a, b b 4
a, b
3
b
Fig. 17.15
Sol. The equivalent DFA obtained is as shown in Fig. 17.16.
{1, 2, 4}
1
a a a
{1, 2, 3}
b
a b {1, 2}
b b
2
b {2, 3, 4} a, b
{0} b
a 4
a, b
{2, 3} a f
3
b
Fig. 17.16
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
560 DISCRETE MATHEMATICS AND STRUCTURES
∈ to NFA
17.9.2. Conversion of NFA-∈
Let M1 = (Q′, Σ, δ1, q′, F′) be an NFA-∈ that recognizes a language L. Then the NFA M2
= (Q,Σ, δ2, q, F) that satisfies the following conditions recognizes L:
(i) Q2 = Q′,
(ii) q = q′,
(iii) The transition function δ2 (q, a) = δ1 (q, a) = ∈-closure (Up ∈ ∈-closure (q) δ1(p, a) for each
state q in Q and each symbol a in Σ and
(iv) The final states is the set F = F′ ∪ {q′} if ∈-closure({q′}) F′ ≠ ′∈
Procedure: To obtain an NFA M2 = (Q, Σ, δ2, q, F) which accepts the same language as
the given NFA-∈ M1 = (Q′, Σ, δ1, q′, F′) does, you have to proceed as given below:
1. First copy the states of Q′ into Q.
2. Then for each state q of Q and each symbol a of Σ find δ2 (q, a) as follows:
Find ∈-closure ({q}) that is all the states that can be reached from q by traversing ∈
arcs. Then collect all the states that can be reached from each state of ∈-closure ({q}) by
traversing one arc labeled with the symbol a. The ∈-closure of the set of those states is δ2 (q, a).
The set of accepting states F is the same as F′ if no accepting states can be reached from
the initial state q′ through ∈ arcs in M1. Otherwise, that is if an accepting state can be reached
from the initial state q′ through ∈ arcs in M1, then all the accepting states of M1 plus state q′
are the accepting states of M2.
Example 14. Convert the NFA-∈ given in Fig. 17.17 to an 1
0
equivalent NFA without ε- moves.
Sol: e
q0 q1
Step 1. Find the ε- Closure off all the states of NFA-∈
δ2 (q0, ∈) = ε-Closure (q0) = {q0, q1}
Fig. 17.17
δ2 (q1, ∈) = ε-Closure (q1) = {q1}
Step 2. Since q0 is the initial state, thus we have to start the process from it and continue
the same process for other states in the same way.
δ2 (q0, 0) = ε-Closure (δ1 (δ2 (q0, ∈), 0))
= ε-Closure (δ1 ({q0, q1}, 0))
= ε-Closure ({q0} ∪ Φ)
= ε-Closure ({q0}) = {q0, q1}
δ2(q0, 1) = ε-Closure (δ1 (δ2 (q0, ∈), 1))
= ε-Closure (δ1 (Φ), 0))
= ε-Closure (Φ) = {Φ}
δ2(q1, 0) = ε-Closure (δ1 (δ2 (q1, ∈), 0))
= ε-Closure (δ1 ({q1}, 0))
= ε-Closure (Φ) = {Φ}
δ2(q1, 1) = ε-Closure (δ1 (δ2 (q1, ∈), 1))
= ε-Closure (δ1 ({q1}, 1))
= ε-Closure ({q1}) = {q1}
Since the transitions from all states of Q have been computed, the conversion process
stops here.
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
FINITE AUTOMATA AND LANGUAGES 561
q0 0 q1
Fig. 17.18
Example 15. Convert the NFA-∈ given in Fig. 17.19 to an equivalent NFA without
ε-moves.
e
e a a
0 1 2 3
Fig. 17.19
Sol.
Step 1. Find the ε- Closure off all the states of NFA-∈
δ2 (0, ∈) = ε-Closure (0) = {0, 1}
δ2 (1, ∈) = ε-Closure (1) = {1}
δ2 (2, ∈) = ε-Closure (2) = {2}
δ2 (3, ∈) = ε-Closure (3) = {1, 3}
Step2. Since 0 is the initial state, thus we have to start the process from it and continue
the same process for other states in the same way.
δ′({0}, a) = ε-Closure (δ1 ((δ2 (0, ∈), a))
= ε-Closure (δ1 ({0, 1}, a))
= ε-Closure (Φ ∪ {1, 2})
= ε-Closure ({1, 2})
= {1} ∪ {2} = {1, 2}
δ′({0}, b) = ε-Closure (δ1 ((δ2 (0, ∈), b))
= ε-Closure (δ1 ({0, 1}, b))
= ε-Closure (Φ) = {Φ}
δ′({1}, a) = ε-Closure (δ1 (δ2 (1, ∈), a))
= ε-Closure (δ1 ({1}, a))
= ε-Closure ({1, 2})
= {1} ∪ {2} = {1, 2}
δ′ ({1}, b) = ε-Closure (δ1 ((δ2 (1, ∈), b))
= ε-Closure (δ1 ({1}, b)
= ε-Closure (Φ) = {Φ}
δ′ ({2}, a) = ε-Closure (δ1 ((δ2 (2, ∈), a))
= ε-Closure (δ1 ({2}, a))
= ε-Closure ({Φ}) = {Φ}
δ′({2}, b) = ε-Closure (δ1 (δ2 (2, ∈), b))
= ε-Closure (δ1 ({2}), b)
= ε-Closure ({3}) = {1, 3}
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
562 DISCRETE MATHEMATICS AND STRUCTURES
a a
a
b
a
a b
0 2 3
a
Fig. 17.20
Example 16. Convert the NFA-∈ given in Fig. 17.21 to an equivalent NFA without ε- moves.
a L
L a b
0 1 2 4
L a
Fig. 17.21
a a
a
a, b
a, b
a
0 2 4
a
a a
Fig. 17.22
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
FINITE AUTOMATA AND LANGUAGES 563
3 5
a
a
1
b
b b a, b
b
a
2 4
Fig. 17.23
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
564 DISCRETE MATHEMATICS AND STRUCTURES
Also since on a state 4 goes to state 4, state 3 goes to state 5 and 4 and 5 are in different
sets in , states 3 and 4 are going to be separated from each other in Πnew.
Further, since on b 2 goes to 1, 4 goes to 4 and 1 and 4 are in different sets in Π, 2 and
4 are separated from each other in Πnew.
On the other hand 1 and 5 make the same transitions. So they are not going to be split.
Thus the new partition is Πnew := {{1, 5} , {2} , {3} , {4 }}.
2. Since Πnew ≠ Π, so we have Π: = Πnew and again apply Step 2.
Now, since 1 and 5 do the same transitions, Π remains unchanged. Thus Πfinal = {{1, 5},
{2}, {3}, {4}}.
3. Construct the DFA from Πfinal
Select 1 as the representative for {1, 5}. Since the other contains single element, they
become their own representatives.
Since the state 4 is a dead state because the only transition out of it is to itself, hence it
is removed.
Now, the set of states for the minimized DFA is {1, 2, 3}. For the transitions, since 1
goes to 3 on a, and to 2 on b in the original DFA, in the minimized DFA transitions are added
from 1 to 3 on a, and 1 to 2 on b. Also since 2 goes to 1 on b, and 3 goes to 1 on a in the original
DFA, in the minimized DFA transitions are added from 2 to 1 on b, and from 3 to 1 on a.
Since the rest of the states are as same as original DFA, all transitions between them are
taken for the minimized DFA.
The minimized DFA obtained is shown in Fig. 17.24.
b 2
1
a
a
3
Fig. 17.24
Example 18. Minimize the number of states of the DFA shown in Fig. 17.25.
b
2 4
a b
b a
1 6
a, b a
b a
b
3 5
Fig. 17.25
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
FINITE AUTOMATA AND LANGUAGES 565
b
a
b
Fig. 17.26
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
566 DISCRETE MATHEMATICS AND STRUCTURES
The number of substrings aab in the input string will be exactly the number of 1’s in the
output string.
Input string a a a b a b b a a b b
State q0 q1 q2 q2 q3 q1 q0 q0 q1 q2 q3 q0
Output 0 0 0 0 1 0 0 0 0 0 1 0
Example 17.20. Convert the transition function of Moore machine shown in Fig. 17.27
into an equivalent transition diagram.
a b OUT
q0 q1 q2 1
q1 q1 q1 0
q2 q1 q3 0
q3 q3 q1 1
Fig. 17.27
a, b
q1/0
a b
a
q0/1 a q3/1
b b
2
Fig. 17.28
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
FINITE AUTOMATA AND LANGUAGES 567
If the input is 001010 the output is 110101. This is a case where the input alphabet and
output alphabet are both {0,1}.
0/0, 0/1
1/0
Fig. 17.30
Sol. Applying the given procedure on the given state of Moore machine is converted
into an equivalent state of Mealy machine as shown in Fig. 17.32.
Example 24. Convert the Moore machine shown in Fig. 17.33 into an equivalent Mealy
Machine.
q1/1
a a a, b
q0/0 b q3/1
b b
q2/0
a
Fig. 17.33
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
568 DISCRETE MATHEMATICS AND STRUCTURES
Sol. Applying the given procedure on all the states of Moore machine step by step. The
equivalent Mealy machine obtained is shown in Fig. 17.34.
q1
a/1, b/1
a/1 a/1
q0 b/0 q3
b/0 b/0
q2
a/0
Fig. 17.34
Example 25. Convert the Moore machine shown in Fig. 17.35 into an equivalent Mealy
Machine.
q1/0 a q3/1
q0/1 b a
a b
q2/1 q4/0
b
Fig. 17.35
Sol. Applying the given procedure on all the states of Moore machine step by step. The
equivalent Mealy machine obtained is shown in Fig. 17.36.
a/0
q1 a/0 q3
b/0
a/1
q2 q4
b/1
b/1
Fig. 17.36
17.11.4 Mealy to Moore Conversion. For every Mealy machine Me, there is a Moore
machine Mo that is equivalent to it. The following procedure will construct an equivalent
Moore machine corresponding to a Mealy machine.
(1) Case 1. Two edges may come into the same state but have different output alphabets
as shown in Fig. 17.37.
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
FINITE AUTOMATA AND LANGUAGES 569
b/0
a/0 a/1
q4
b/1 b/1
Fig. 17.37
(a) In this case two copies of q4, one that prints a 0 (labeled as q4/0), and the other that
prints a 1 (labeled as q4/1). Hence, the edges a/0 and b/0 will go into q4/0 and the edge b/1 will
go into q4/1.
(b) The arrow coming out of each of these two copies must be the same as the edges
coming out of q4 originally.
The above state breaks down in two states and is shown in Fig. 17.38.
b
a a/1 a/1
q4/0 q4/1
a
b/1 b/1
Fig. 17.38
(2) Case 2. If all the edges coming into a state have the same output alphabets as
shown in Fig. 17.39.
b/1
a/1
q5
b/1
Fig. 17.39
In this case the output is pushed into the state as shown in Fig. 17.40.
b
a
q5/1
b
Fig. 17.40
a/0
q6
b/1
a/0
q3
Fig. 17.41
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
570 DISCRETE MATHEMATICS AND STRUCTURES
This edge becomes two edges in Mo, one that is a loop and a
one that is not as shown in Fig. 17.42.
(4) If there is a state that has no incoming edges, we can
q3/0
assign it any output alphabet we want, even if this state is the
a/0
start state.
b
(5) If we have to make copies of the start state in Me, we q6
can let any of the copies be the start state in Mo, because they
a/0
all give the identical directions for proceeding to other states. b
q3/1
But to make both Moore machines and mealy machines
equivalent the output of the start state must be negative.
Fig. 17.42
(6) Repeating this process for each state of Me will produce
an equivalent Mo.
Example 26. Convert the Mealy machine shown in Fig. 17.43 into an equivalent Moore
Machine.
b/1
q1
a/0 a/1
b/0
q0 a/1 q2
b/0
b/1 a/0
q3
Fig. 17.43
Sol. Applying the given procedure on all the states of Mealy machine step by step. The
equivalent Moore machine obtained is shown in Fig. 17.44.
b
q1/1
a a
a
b
q0/0 q2/0
a
b
b
q2/1
a
a
q0/1 b q3/0
b
Fig. 17.44
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
FINITE AUTOMATA AND LANGUAGES 571
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
572 DISCRETE MATHEMATICS AND STRUCTURES
non-empty string and wr denotes the reversal of string w. The corresponding CFG is as given
below.
S → aSa
S → bSb
S → aa
S → bb
Example 31. Let L be the set of algebraic expressions involving identifiers x and y,
operations + and * and left and right parentheses and L is a context-free language. The corre-
sponding CFG is as given below.
S → (S + S)
S → S*S
S→( )
S→x
S→y
Type 3: Regular Languages or Grammars. The languages defined by Type 3 gram-
mars are accepted by finite state automata. The productions of a regular grammar are of the
form A → aB, A → Ba or A → a, where A, B ∈ V and a ∈ T*. Further, S → ε is allowed if S is
NOT on the right side of any production.
Example 32. The following grammar generates anb | n >= 1. The corresponding Regular
grammar is as given below.
S → aA
A → aA
A→b
There are two kinds of Regular grammars:
1. Right-linear Grammars are those having only the rules of the form A → aB or A → b.
The structural descriptions generated with these grammars are right-branching.
2. Left-linear Grammars are those having only the rules of the form A → Ba or A → b.
The structural descriptions generated with these grammars are left-branching.
Every language generated by a left linear grammar can be generated by a right linear
grammar, and every language generated by a right linear grammar can be generated by a left
linear grammar. Every language generated by a left linear or right linear grammar can be
generated by a linear grammar. Every language generated by a linear grammar can be
generated by a context free grammar.
The Four types of languages and their associated grammars and machines are shown
in the following table.
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
FINITE AUTOMATA AND LANGUAGES 573
These languages form a strict hierarchy; that is, regular languages ⊂ context-free
languages ⊂ context-sensitive languages ⊂ recursively enumerable languages.
regularly numericals
context-sensitive
context-free
regular
Fig. 17.45
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
574 DISCRETE MATHEMATICS AND STRUCTURES
Example 33. Determine the type and name of the language represented by the given
grammar.
(i) S → aBSc (ii) S → abc
(iii) Ba → aB (iv) Bb → bb
Sol. The type of the given grammar can be determined by first determining the type of
individual production. The individual production is given the highest number possible. After
giving the number to individual productions, the grammar type is the least number of all the
productions.
In the given Grammar, productions (i) and (ii) are of type 2 and production (iii) and (iv)
are of type 1. Hence the grammar is of type 1 and is Context Sensitive Grammar.
0
1¢ 2¢
0
1 0
1 0
1 0
1 2 3
1 0 1
4¢ 3¢ 1
1
(a) (b)
Fig. 17.46
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
FINITE AUTOMATA AND LANGUAGES 575
In the table, in second column, we see that 1 is a final vertex in FSM M but 3′ is not a
final vertex which indicates the non equivalence.
SOLVED PROBLEMS
Problem 1. Consider the languages L1 = {a, a2, a3, a4} and L2 = {b, b2, ab2} over the
alphabet ∑ = {a, b}.
Determine the languages (i) L1L2 (ii) L1L1 (iii) L2L1 (iv) L2L2.
Sol. (i) The strings in L1 are concatenated with L2 and the language become
L1L2 = {ab, ab2, aab2, a2b, a2b2, a3b2, a3b, a4b2, a4b, a5b2}
(ii) The strings in L1 are concatenated with L2 and the language become
L1L1 = {a2, a3, a4, a5, a6, a7, a8}
(iii) The strings in L2 are concatenated with L1 and the language become
L2L1 = {ba, ba2, ba3, ba4, b2a, b2a2, b2a3, b2a4, ab2a, ab2a2, ab2a3, ab2a4}
(iv) The strings in L2 are concatenated with L2 and the language become
L2L2 = {b2, b3, bab2, b4, b2ab2, ab3, ab4, ab2ab2}
Problem 2. Construct the finite state automaton, which recognizes the following
languages :
(i) The set of strings of 0’s and 1’s each of which starts with a1 and ends with 010.
(ii) The set of strings of 0’s and 1’s each of which ends with 01k, k ≥ 1.
Sol. (i) The finite state automaton for the set of strings which starts with 1 and ends
with 010 is shown in Fig. 17.47.
1
1
0
1 0 1 0
q0 q1 q2 q3 q4
0 0
1
q5
0, 1
Fig. 17.47
(ii) The finite state automaton for the set of strings each of which ends with 01k, k ≥ 1 is
shown in the Fig. 17.48.
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
576 DISCRETE MATHEMATICS AND STRUCTURES
1 0 1
0 1
q0 q1 q2
Fig. 17.48
Problem 3. Construct the finite state automaton, which recognizes the following
languages :
(i) The set of strings of 0’s and 1’s none of which contains the substring 010.
(ii) The set of strings of 0’s and 1’s in each of which there is an even number of 0’s and
1’s.
Sol. (i) The finite state automaton for the set of strings none of which contains the
substring 010 is shown in the Fig. 17.49.
0
1 0
0 1 0
q0 q1 q2 q3
1
1
Fig. 17.49
Note. The trick here is to make an automaton which accepts the language of strings which ends
with 010 and make all these states final which are non final in case of 010 and non final which are final.
(ii) The automaton for the set of strings in each of which there is an even number of 0’s
and 1’s is shown in Fig. 17.50.
1
q0 q1
1
0
0 0 0
1
q2 q3
Fig. 17.50
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
FINITE AUTOMATA AND LANGUAGES 577
a b
1 2 3
a
b
2 a, b
Fig. 17.51
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
578 DISCRETE MATHEMATICS AND STRUCTURES
(b) The DFA that accepts all strings that contain cca is shown in Fig. 17.52.
a, b c a, b, c
c c a
1 2 3 4
a, b
b
Fig. 17.52
a, c a, c a, c a, b, c
b b b
1 2 3 4
Fig. 17.53
a, c a, c a, c a, c a, b, c
b b b b
1 2 3 4 5
Fig. 17.54
a, c a, c a, c
b b
1 2 3
Fig. 17.55
Problem 8. Construct a DFA which accepts all binary numbers which are multiples of
5. For example 101, 1010, 1111, 10100 and so on should be accepted.
Sol. The corresponding DFA is shown in Fig. 17.56.
0
1
1
0
2 4
1
0 0
1
0
1 3
1
Fig. 17.56
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
FINITE AUTOMATA AND LANGUAGES 579
Start q0 0 q1 1 q2
1 0 0.1
Fig. 17.57
Start 0 0 1 1
q0 q1 q2 q3 4
1
1 0 0.1
Fig. 17.58
Start 0
q0 q1
0
1 1
Fig. 17.59
Start 0
q0 q1 0 q2 0 q3
1
1 1 0.1
Fig. 17.60
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
580 DISCRETE MATHEMATICS AND STRUCTURES
Start 0
q0 q1
0
1 1 1 1
0
q3 q2
0
Fig. 17.61
Start q0 1 q1 0 q2
0 1
1 0 0
q3 q4
0
1
Fig. 17.62
Start 0
q0 q1
1
1 0 0
q2 q3
1
0, 1
Fig. 17.63
Problem 11. Construct an NFA for all strings over {a, b} containing aba as substring.
Then convert the same into an equivalent DFA.
Sol. The NFA for all strings containing aba as substring is shown in Fig. 17.64.
a b a
0 1 2 3
a, b a, b
Fig. 17.64
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
FINITE AUTOMATA AND LANGUAGES 581
b a
b
a b a b
0 0, 1 0, 2 0, 1, 3 0, 2, 3 0. 3
a
b a b
a
Fig. 17.65
Problem 12. Given an NFA-ε as shown in Fig. 17.66. Convert it into an equivalent NFA
and then to DFA.
e
a b
0 1 2
a a b
3 4 5 6
Fig. 17.66
b
a {0, 2, 3}
b
b
a a, b
{0, 3} {1, 4} {}
a
a b
b
{5} {0, 6, 3}
Fig. 17.67
Problem 13. Construct a NFA-ε to accept those strings which consist of either ‘01’ repeated
zero or more times OR pattern ‘010’ repeated one or more times. Then convert it into an equivalent
DFA.
Sol. The NFA-ε of the given language is shown in Fig. 17.68. First convert into an
equivalent NFA and then DFA.
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
582 DISCRETE MATHEMATICS AND STRUCTURES
q1 0 q6 1 q7
e e
e
Start
q0 q8
e e
q2 0 q3 1 q4 0 q5
Fig. 17.68
Problem 14. Construct Moore and Mealy machine that counts the occurrence of the
string 1101 and outputs a 1 when it detects the nal bit in the serial data stream.
Sol. The Moore machine is shown in Fig. 17.69.
0/0
Fig. 17.69
S0
0
0 1
0
S1
1 0
S1
0 1 0
1
S2
0
1
1
S3
0
Fig. 17.70
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
FINITE AUTOMATA AND LANGUAGES 583
Problem 15. Construct a Mealy machine that reads an input x ∈ {0, 1}* and produces
the binary number that represents the result of adding binary 111 to x (assumes all numbers
are positive, including results). Note: The binary number is read from least to most significant
bit.
Sol. The Mealy machine is shown in Fig. 17.71.
1/0 0/01
0/0 0/0 0/1
–100 –10 –1 –0
+111 –10
0.1
Fig. 17.71
Problem 17. Give the state table for the mealy machine whose state diagram is shown
in Fig. 17.72.
0/0 1/0 0/0
q0 q1 q2
1/0 0/1
1/0
Fig. 17.72
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
584 DISCRETE MATHEMATICS AND STRUCTURES
Sol. The state table for the FSM is shown in Table given below.
Input 0 Input 1
State Input 1
State Output State Output
q0 q1 0 q0 0
q1 q0 0 q2 1
q2 q1 1 q1 0
Problem 18. Construct the state diagram for the finite state mealy machine whose state
table is shown in table given below.
Input 0 Input 1
State Input
State Output State Output
q0 q1 1 q0 1
q1 q2 0 q0 0
q2 q0 1 q3 0
q3 q1 0 q2 1
Sol. The state diagram of the finite state machine is given in the Fig. 17.73.
0/0
1/1 0/1 0/0
1/0
q0 q1 q2 q3
1/0
1/1
0/1
Fig. 17.73
Problem 19. Given the mealy machine as shown in Fig. 17.74. Determine the output for
each of the following input strings :
0/0
q0 q1
0/1
1/0 0/1
1/1 1/0
0/0
q2 q3
1/1
Fig. 17.74
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
FINITE AUTOMATA AND LANGUAGES 585
11 00 11 00
q0 ⎯ ⎯
⎯→ q2 ⎯ ⎯
⎯→ q3 ⎯ ⎯
⎯→ q2 ⎯ ⎯
⎯→ q3
So the output for this string is 1010.
(b) Follow the same procedure as in (a). Thus
q0 ⎯ 1⎯
⎯1
→ q2 ⎯ 1⎯
⎯0
→ q0 ⎯ 0⎯
⎯0
→ q1 ⎯ 1⎯
⎯0
→ q3 ⎯ 1⎯
⎯1
→ q2 ⎯ 0⎯
⎯0
→ q3 ⎯ 1⎯
⎯1
→ q2 ⎯ 1⎯
⎯0
→ q0
So the output for the string 11011011 is 10001010.
(c) The output for the string 1010001001 is as follows.
11 00 11 00 01 01 11 00 01
q0 ⎯⎯⎯ → q2 ⎯⎯⎯ → q3 ⎯⎯⎯ → q2 ⎯⎯⎯ → q3 ⎯⎯⎯ → q1 ⎯⎯⎯ → q0 ⎯⎯⎯ → q2 ⎯⎯⎯ → q3 ⎯⎯⎯ → q1
10
⎯⎯⎯ → q3
Problem 20. Consider the mealy machine M, whose state table is shown in table given
below.
Input 0 Input 1
States State Output State Ouptut
q0 q1 a q3 b
q1 q1 a q2 a
q2 q3 b q4 b
q3 q1 b q0 b
q4 q3 b q4 b
(a) Determine the input set Σ, the state set Q, the output set Δ and the initial state of M.
(b) Construct the state diagram of M.
(c) Determine the output string if the input string
w = 110111000101.
Sol. (a) The input set Σ = {0, 1}
The state set Q = {q0, q1, q2, q3, q4}
The output set Δ = {a, b}
The initial state is q0.
(b) The state diagram of the finite state machine M is shown in Fig. 17.75.
0/a
0/a
q0
q1
1/a
0/b
1/b 0/b q2
1/b
q3
1/b
q4 1/b
0/b
Fig. 17.75
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
586 DISCRETE MATHEMATICS AND STRUCTURES
q3 ⎯ 0⎯
/b
⎯ → q1 ⎯ 0⎯
/a
⎯ → q1 ⎯ 1/
⎯⎯ a
→ q2 ⎯ 0⎯
/b
⎯ → q3 ⎯ 1/
⎯⎯ b
→ q0
Thus the string is b2a2b4a2b2.
Problem 21. Describe the elements of the set A* for the following values of A.
(i) {a b} (ii) {a a a} (iii) {b, bab}.
Sol. (i) The set of all strings consisting of zero or more consecutive pairs of ab.
(ii) The set of all strings consisting of all a’s such that the number of a’s is divisible by
three. It also includes a null string.
(iii) The set of all strings that begin and end with an b and have at least two b’s between
every pair of a’s.
Problem 22. Consider the mealy machine M, whose state diagram is shown in the
Fig. 17.76.
0/0
q0 q1
1/1
1/1
0/0 1/1
0/0
q3 q2
0/0
Fig. 17.76
(a) Determine the input set Σ, the state set Q, the output set Δ and the initial state of M.
(b) Construct the state table of M.
(c) Determine the output string if the input string
w = 12021202101.
Sol. (a) The input set Σ = {0, 1}
The state set Q = {q0, q1, q2, q3}
The output set Δ = {0, 1}
The initial state is q0.
(b) The state table of the finite state machine M is shown in table given below.
δ f
States State Output State Output
q0 q3 0 q1 1
q1 q0 0 q1 1
q2 q1 0 q3 1
q3 q1 0 q3 0
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
FINITE AUTOMATA AND LANGUAGES 587
(c) The output string corresponding to the input string w = 12021202101 is determined
by following the path in the state diagram.
Path = q0 ⎯ 1/
⎯
1 1/ 1
⎯→ q1 ⎯ ⎯
0/0
⎯→ q1 ⎯ ⎯
0/0
⎯→ q0 ⎯ ⎯
1/0
⎯→ q3 ⎯ ⎯
1/0
⎯→ q3 ⎯ ⎯
0/0
⎯→ q3 ⎯ ⎯⎯→
0/0 1/ 0 0/0 1 /1
q1 ⎯⎯⎯
→ q3 ⎯⎯⎯
→ q3 ⎯⎯⎯
→ q1 ⎯⎯⎯
→ q1
Thus the string is 12081.
Problem 23. Consider the mealy machine M, whose state diagram is shown in Fig. 17.77.
b/2
a/3
a/1
a/2
q0 q1 q2 b/3
b/1
Fig. 17.77
(a) Determine the input set Σ, the state set Q, the output set Δ and the initial state of M.
(b) Construct the state table of M.
(c) Determine the output string if the input string
w = aba2b2ababa2.
Sol. (a) The input set Σ = {a, b}
The state set Q = {q0, q1, q2}
The output set Δ = {1, 2, 3}
The initial state is q0.
(b) The state table of the finite state machine M is shown in table given below.
Input 0 Input 1
States State Output State Output
q0 q0 3 q2 2
q1 q0 2 q2 1
q2 q1 1 q2 3
(c) The output string corresponding to the input string w = aba2b2ababa2 is determined
by following the path in the state diagram.
a/3
Path = q0 ⎯ ⎯⎯→ q0 ⎯ b⎯
/2
⎯ a/1
→ q2 ⎯ ⎯ a/2
⎯→ q1 ⎯ ⎯⎯→ q0 ⎯ b⎯
/2
⎯ → q2 ⎯ b⎯
/3
⎯ a/1
→ q2 ⎯ ⎯⎯→
q1 ⎯ b⎯
/1
⎯ a/1
→ q2 ⎯ ⎯⎯→ q1 ⎯ b⎯
/1
⎯ a/1
→ q2 ⎯ ⎯ a/2
⎯→ q1 ⎯ ⎯⎯→ q0
Thus the string is 321223152.
Problem 24. Construct a finite state machine M, that adds two binary numbers.
Sol. A finite state machine to perform binary addition can be constructed using just two
states. The start state q0 is used to remember that the previous carry is 0. The second state, q1
is used to remember that the previous carry is 1. Since the inputs to the machine are pairs of
bits, there are four possible inputs. These four possible input pairs are (0, 0), (0, 1), (1, 0) and
(1, 1).
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
588 DISCRETE MATHEMATICS AND STRUCTURES
The transitions and the outputs are constructed from the sum of the two bits represented
by the input and the carry represented by the state. The transition diagram of the FSM, M is
shown in the Fig. 17.78.
(1, 1) ® 1 (0, 0) ® 0
(0, 0) ® 1
(1, 0) ® 0 q0 Carry No carry q1 (1, 0) ® 1
(1, 1) ® 0
(0, 1) ® 0 (0, 1) ® 1
Fig. 17.78
1. Let the class of languages accepted by finite state machines be L1 and the class of languages
represented by regular expressions be L2 then,
(a) L1 ⊂ L2 (b) L2 ⊆ L1
(c) L1 ∩ L2 = Φ (d) L1 = L2
2. Which of the following regular expression over {0, 1} denotes the set of all strings not containing
100 as sub string
(a) 0 * (1 * 0) (b) 0 * 1010*
(c) 0 * 1 * 01* (d) 0 * (10 + 1)*
3. What kind of strings is rejected by the following automaton?
0 0, 1
S1 S2
S0
1
0
(a) All strings with two consecutive zeros
(b) All strings with two consecutive ones
(c) All strings with alternate 1 and 0
(d) None
4. Which one of the following is not a regular expression?
(a) [(a + b)* – (aa + bb)]* (b) [(0 + 1) – (0b + a1)* (a + b)]*
(c) (01 + 11 + 10)* (d) (1 + 2 + 0)* (1 + 2).
5. In a DFA, m = (Q, Σ, δ, q0, F) transition function δ is a function which maps
(a) Q – Σ × Q (b) Q × Σ → Q
(c) Q → F (d) Q × q0 → S.
6. If n is the number of states in NFA then equivalent DFA can have maximum of
(a) n states (b) 2n states
(c) 2n states (d) n2 states
7. What language is accepted by the following deterministic finite automata
(a) 0 (b) 0n
(c) 1(0+1)* (d) (0+1)*
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
FINITE AUTOMATA AND LANGUAGES 589
8. You have given the finite state machine as shown in figure. What is the output of the input string
11100100
0/0
0/1 1/1
01 ¥
1/1
ANSWERS
1. (d) 2. (d) 3. (b) 4. (b) 5. (b)
6. (b) 7. (b) 8. (b) 9. (d) 10. (d)
EXERCISES
1. Test whether 101101, 11111 are accepted by a finite state machine M given as follows:
M = {Q = {q0, q1, q2, q3}, S = {0, 1}, δ, {q0}}
Where δ is
Inputs
States 0 1
→ q0 q2 q1
q1 q3 q0
q2 q0 q3
q3 q1 q2
2. State the relation between Regular Expression, Transition Diagram and Finite State Machines.
Using a simple example establish your claim.
3. Identify the regular set accepted by the DFA and construct corresponding transition table.
1
0 0
1 0
0 1
A B C D E
0 0
1
4. Let L be a language over {0, 1} such that each string starts with a 0 and ends with a minimum of
two subsequent 1’s. Construct,
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
590 DISCRETE MATHEMATICS AND STRUCTURES
a b
→ S0 S0 S1
S1 S1 S2
S2 S2 S3
S3 S3 S0
7. Design an DFA which accepts only even numbers of 0s and even number of 1’s.
8. For each of the following regular expressions, give a minimum-length string in (a + b)* not in the
language.
(a) a * (ab) * b *
(b) (b * + a *) (a* + b*) (b * + a*)
(c) a * (abb *) * b *
(d) b * (a + ba) * b *
9. Write regular expressions corresponding to the following languages on the alphabet {0, 1}*:
(i) All the strings that ends with 101.
(ii) All the strings that contain 00 as a substring.
(iii) All the strings that begin and end with different letter.
(iv) All the strings that begin and end with same letter.
(v) All the strings that contain even number of zeroes.
(vi) All the strings that contain exactly two zeroes.
(vii) All the strings that contain at least two zeroes.
(viii) All the strings that contain at most two zeroes.
(ix) All the strings in which the number of zeroes are divisible by 3.
10. Give a regular expression for each of the following languages:
(a) All strings over {0, 1} that represent binary numbers x, such that (x mod 4) = = 2. (2, 6, 10,
14, etc).
(b) All strings over {a, b} that contain both the substring abba and the substring baab.
(c) All strings over {a, b, c} that have at least one a, at least one b, and at least one c.
(d) All strings over {a, b, c} in which every a is followed immediately by ac.
(e) All strings over {a, b} that contain the substring aab but not the substring bb.
(f) All strings over {0, 1} that do not contain the substring 1111.
11. Give a DFA for each of the following languages:
(a) All strings over {a, b, c} that contain an even number of a’s.
(b) All strings over {a, b, c} that contain an even number of a’s and even number of b’s
(c) All strings over {a, b} that contain either bab or bba (or boh)
(d) All strings over {a, b} that contain both bab and bba
(e) All strings over {a, b} that contain bab but not bba.
(f) All strings over {0, . . . 9} that form numbers divisible by 7. So, 7, 14, 21, 28, 35, etc are all in
the language.
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
FINITE AUTOMATA AND LANGUAGES 591
(g) All strings over {a, b, c} that contain an even number of a’s and an even number of b’s and an
even number of c’s.
12. Construct DFA that accepts the following languages over the alphabet {a, b}*.
(a) All strings that contain exactly 2 a’s
(b) All strings that have length 3.
(c) All strings that begin and end with the same letter
(d) All strings that begin or end with aa
13. Construct DFA that accepts the following languages over the alphabet {0, 1}*.
(a) All strings that contain the substring 1001
(b) All strings that end with 111
(c) All strings that begin with 111
(d) All strings that begin or end with 111
(e) All strings that begin and end with 111
(f) All strings that contain 1001 or 0110
14. Give a DFA for each of the following languages:
(a) All string that contain the substring 1001 or 111
(b) (a + b)* aba(a + b)*
(c) (ab)* + (aba)*
15. Give a NFA for each of the following languages:
(a) L = All strings over {a, b, c, d} of length at least 2 whose second symbol does not appear
elsewhere in the string. So bdabc, acbab, bacbd, abcdc ∈ L, while aa, bcabc, abcbc, dd ∈ L
(b) L = All strings over {a, b, c} such that every a is followed by either the substring bcb, ccb, or
cbcc.
16. Construct NFA’s for the following languages over the alphabet {a, b}* and then convert them into
equivalent DFA’s.
(a) All the strings that contains the substring
(b) All strings that start with a and end with b
(c) All strings that have an a as one of the last 3 characters in the string. So, a, baab, bbbab,
aabbaaabb ∈ L, but bb, baabbb, bbabbbbb does not belong to L
(d) All strings that begin or end with aa
17. Construct NFA’s for the following languages over the alphabet {0, 1}* and then convert them into
equivalent DFA’s.
(a) All strings that contain 0110 or 1001
(b) All strings that contain two pairs of adjacent 0’s separated by an even number of symbols.
So, 0100110011, 01100101100101, and 01001000 are in the language, but 0100100, 1011001,
and 0111011 are not in the language.
18. Specify the transition function of the DFA shown below and describe the language.
0, 1
Start
S0 S1 0
1
19. Find the state table for the NFA with the state diagram given. Find the language recognized
by it.
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
592 DISCRETE MATHEMATICS AND STRUCTURES
0 0
S1 S3
1
Start 1 0, 1
S0
0
0
1
S2 S4
20. The statement that “All finite languages are Regular” is TRUE/FALSE. Justify.
21. We know that a DFA for recognizing an infinite Regular Language must have a loop. Why is this
fact so important in helping to prove that some infinite languages are NOT Regular?
22. What are the possible ways to combine two automatons? Explain with an example.
23. Construct the finite automaton for the state transition table given below.
a b
→ s0 s0 s2
s1 s0 s1
s2* s2 s1
24. Construct the DFA for the following languages over the alphabet {a, b}*
(i) L1 ={aabn | n is a multiple of 2}
(ii) L2 ={aabn | n is a multiple of 5}
25. Convert the NFA given in figure to DFA.
1 a, b
a, b 3
b
b
b
a, b
b a, b
0
a, b
4
2 a, b
26. Convert the NFA-ε given below to an equivalent NFA without ε- moves.
e a
5
1 2
a a
a, b
b
3 4
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
FINITE AUTOMATA AND LANGUAGES 593
0 1
1 0
1 2 3
0
1 0
1
0
1
1
0
4 0 5 0 6
1
1
0
28. Convert the NFA-ε given below to an equivalent NFA without ε- moves.
a
A b
1 2 3 4 5
a A
b
A
a
b a
6
29. Convert the NFA-ε given below to an equivalent NFA without ε- moves.
A
0 1
b a 3
a A b b
A
2 4
30. Convert the NFA-ε given below to an equivalent NFA without ε- moves.
0 1 2
q0 e q1 e q2
31. Convert the NFA-ε given below to an equivalent NFA without ε- moves.
e
1
B C
e
0 e
A 0
1 1
1 E D
1
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
594 DISCRETE MATHEMATICS AND STRUCTURES
32. Minimize the number of states of the DFA as shown in Figure below.
0
1
0 1 0
a b C d
1 0 1
0 1
1 1 0
e f g h
0
1
0
33. Minimize the number of states of the DFA as shown in Figure below.
b a, b
a a
1 2 3
b a, b
b a
7 a 4 5 6
b
a, b
34. Minimize the number of states of the DFA as shown in Figure below.
q7 0, 1 q2 q3 1 q5
0 0
0 0, 1
0 1
q0 1 q1 q4 1 q6
1
35. Minimize the number of states of the DFA as shown in Figure below.
b
b 0 1
a
2 a a
b
a, b
b
3 a 4
a
5
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
FINITE AUTOMATA AND LANGUAGES 595
36. Minimize the number of states of the DFA whose transition function is shown below.
δ a b
→ q0 q1 q0
q1 q0 q3
q2 q4 q1
q3 q4 q1
q4 q2 q6
q5 q0 q2
q6 q3 q4
37. Minimize the number of states of the DFA whose transition function is shown below.
δ a b
→ q0 q3 q2
q1 q6 q2
q2 q8 q5
q3 q0 q1
q4 q2 q5
q5 q4 q3
q6 q1 q0
q7 q4 q6
q8 q2 q7
q9 q7 q10
q10 q5 q9
38. Construct Mealy and Moore machine for input (0 + 1)*, if the input ends in 101, output A; if the
input ends in 110, output B; otherwise output C.
39. Give Mealy and Moore machine for input (0 + 1 + 2)*, print the residue modulo 5 of the input
treated as a ternary (base 3, with digits 0, 1, and 2) number.
40. Construct a Mealy machine similar to the following Moore machine.
0 1 Output
A B C 0
B C B 1
C A C 0
0 1
A B, 0 C, 1
B C, 1 B, 1
C A, 1 C, 0
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use
596 DISCRETE MATHEMATICS AND STRUCTURES
b a b
q4/0
a, b
1/1
q3
1/0 1/0
q0 1/0 q2
0/0 1/0
0/0
0/0 q1
EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use