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

Finite Automata Notes

Uploaded by

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

Finite Automata Notes

Uploaded by

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

CHAPTER

17 Finite Automata and Languages


All rights reserved. May not be reproduced in any form without permission from the publisher, except fair uses permitted under U.S. or applicable copyright law.

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.

17.2 BASIC TERMINOLOGY


String. A string is a finite sequence of symbols i.e., letters and digits in any order. The
length of a string w, is the number of symbols composing the string and is denoted by | w |.
e.g., 1. Consider the symbols k, l, m, n, then mnlk, kmn, lmn are all strings.
2. The length of these strings are 4, 3 and 3 respectively.
Prefix of a String. The prefix of a string is any number of leading symbols of that string.
Suffix of a String. The suffix of a string is any number of trailing symbols of that string.
e.g., Consider the string mnlk. So the prefixes of this string are m, mn, mnl, mnlk, ^.
The suffixes of this string are k, lk, nlk, mnlk, ^.
Copyright 2015. Laxmi Publications Pvt Ltd.

Alphabet. An alphabet is defined as a finite set of symbols. It is generally denoted by ∑.


Language. A language is defined as a set of strings of symbols from some given alphabet.
It is generally denoted by ∑*.

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}

17.3 OPERATIONS ON LANGUAGES


All operations that are applicable on sets can be applied to languages also.
Union Operation. Let us assume that L1 and L2 be two languages. Then L1 ∪ L2 is
also a language that contains the sentences in either L1 or L2.
Intersection Operation. Again if we have L1 and L2 be two languages. Then L1 ∩ L2 is
a language that contains all the sentences that are in both L1 and L2.
Concatenation Operation. Let L1 and L2 be two languages over the alphabet ∑. Then
the concatenation of L1 and L2, denoted by L1 L2, is the language defined as
L1L2 = {w1 w2 | w1 ∈ L, and w2 ∈ L2}
It means that L1L2 denotes the set of all strings which come from the concatenation of a
word L1 with a string from L2.
e.g., Consider the languages
L1 = {a, b} and L2 = {ab, bb}
Then, L1L2 = {aab, abb, bab, bbb}
and L2L1 = {aba, abb, bba, bbb}.
Kleen Closure Operation. It is a unary operation and is denoted by L*.
It is defined as the infinite union of L1, L2, L3, L4, ......., L∞ and is denoted as
L* = L0 ∪ L1 ∪ L2 ∪ ....... ∪ L∞

i
= U L
i=0
where, L0 = {^} ; L1 = L2 = LL ; L3 = LLL
and Ln + 1 = LnL for n > 1.

17.4 REGULAR EXPRESSIONS AND REGULAR LANGUAGES

17.4.1 Regular Expressions


The class of regular expressions over ∑ is defined recursively as follows :
(a) The symbol ^ and φ are regular expressions over ∑,
(b) Every letter a ∈ ∑ is a regular expression over ∑,
(c) If r1 and r2 are regular expressions over ∑,
then so are (r1 + r2), (r1. r2) and (r1)*.
where + indicates alternation, • denotes concatenation and * denotes closure.

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.

17.4.2 Regular Language


Consider a language L over the alphabet ∑. Then L is called a regular over ∑ if there
exists a regular expression r over ∑ such that L = L(r).
e.g., 1. If r = 01*, then L(r) consists of all strings of 0’s and 1’s that begin with 0 and followed
by any number of 1’s.
2. If r = 0 + 1*, then L(r) consists of strings containing a single 0 or any number of 1’s.
3. If r = (0 + 1)*10, then L(r) consists of all strings of 0’s and 1’s that ends with 10.

17.5 DETERMINISTIC FINITE AUTOMATA (DFA)


A DFA M is denoted by a 5-tuple (Q, ∑, δ, q0, F), where
1. Q is a finite set of states.
2. ∑ is a finite input alphabet.
3. q0 in Q is the initial state.
4. F is a subset of Q and is the set of final states.
5. δ is transition function or next-state function mapping Q × ∑ to Q.
To make a DFA, either we have to denote it by indicating its five parts or we can make
a state diagram of it.

17.5.1 State Diagram of a DFA


A DFA can be defined by means of its state diagram. The state diagram is a labeled
directed graph, where
— The vertices of the graph are the states in Q.
— The arrow from the state qi to qj with label a represents a transition or next-state
function, which defines δ(qi, a) = qj.
— The initial state q0 is represented by an arrow.
— The final state or accepting state is represented by a double circle.

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

3. q0, is the initial state


4. F = {q2}, is the final state
5. δ, the transition function is represented by the table as shown in figure 17.1.

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

17.6 RELATIONSHIP BETWEEN REGULAR LANGUAGES AND FINITE AUTOMATA


Every automata M defines a language over ∑, where ∑ is an input alphabet.
If M is the finite Automata, then L(M) is the language accepted by automata, which is
the collection of all strings constructed from ∑, which are accepted by M.

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

Sol. (a) Trace the path by taking one symbol at a time, so


0 1 0 0
Path = q0 ⎯⎯ → q0 ⎯⎯→ q1 ⎯⎯→ q0 ⎯⎯→ q0
Since it halts in the final state, hence the string is accepted.
(b) Again trace the path, hence
1 1 0 1
Path = q0 ⎯⎯ → q1 ⎯⎯→ q2 ⎯⎯→ q0 ⎯⎯→ q1
Since, it does not halt in the final state at the end, hence the string is not accepted.
(c) This time since the initial state is the final state hence without inputing anything
we were in the final state hence it is accepted.
(d) This time the path is
Path :
0 1 0 1 0 1 0 1 0
q0 ⎯⎯→ q0 ⎯⎯→ q1 ⎯⎯→ q0 ⎯⎯→ q1 ⎯⎯→ q0 ⎯⎯→ q1 ⎯⎯→ q0 ⎯⎯→ q1 ⎯⎯→ q0
Since, q0 is the final state at the end, hence it is accepted.

17.7 NONDETERMINISTIC FINITE AUTOMATA (NFA)


A Nondeterministic Finite Automata (NFA) is a 5-tuple (Q, Σ, δ, q0, F), where
1. Q is a finite set of states.
2. Σ is a finite set of input alphabet.
3. q0 in Q is the initial state.
4. F is a subset of Q and is called the set of final states.
5. δ is transition function mapping Q x Σ to 2Q.
The transition function takes a state in Q and an input alphabet from Σ as arguments
and returns a subset of Q.
This definition states that a nondeterministic finite automata can exhibit several
different transition sequences for a given state and a given input. An input string is accepted

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

17.8 NONDETERMINISTIC FINITE AUTOMATA WITH ∈ MOVES (NFA-∈


∈)
A Nondeterministic Finite Automata with ∈- Moves (NFA- ∈) is a 5-tuple (Q, Σ, δ, q0,
F), where
1. Q is a finite set of states.
2. Σ is a finite set of input alphabet.
3. q0 in Q is the initial state.
4. F is a subset of Q and is called the set of final states.
5. δ is transition function mapping Q × (Σ ∪ {ε}) to 2Q.
The transition function takes a state in Q and an input alphabet from Σ including ε as
arguments and returns a subset of Q.
This definition states that a nondeterministic finite automata can exhibit several
different transition sequences for a given state and a given input. An input string is accepted
by a nondeterministic finite automata if and only if at least one of the possible transition
sequences leads to a final state.

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

17.9.1 Conversion of NFA to DFA


Let M′ = (Q′, Σ, δ′, q, F′) be an NFA that recognizes a language L. Then the DFA M = (Q,
Σ, δ, q0, F) that satisfies the following conditions recognizes L:
(i) Q = 2Q2, that is the set of all subsets of Q2,
(ii) q0 = {q′},
(iii) The transition function δ(q, a) = Up ∈ q δ′(p, a) for each state q in Q and each symbol
a in Σ and
(iv) The final states are F = {q ∈ Q | q ∩ F′ ≠ ∈}
Procedure: To obtain a DFA M = (Q, Σ, δ, q0, F) which accepts the same language as
the given NFA M′ = (Q′, Σ, δ′, q′, F′) does, you have to proceed as given below:
1. Initially Q = ∈.
2. First put {q′} into Q. {q′} is the initial state of the DFA M.
3. Then for each state q in Q do the following:
(a) add the set Up ∈ q δ′ (p, a), where δ′ is the transition function of NFA M′, as a state to
Q if it is not already in Q for each symbol a in Σ.
(b) For this new state, add δ(q, a) = Up ∈ q δ′(p, a) to δ where δ′ is the transition function
of NFA M′.
4. When no more new states can be added to Q, the process terminates. All the states
of Q that contain accepting states of M2 are accepting states of M.
Example 11. Convert the NFA given in Fig. 17.11 to DFA.
a

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}

{q2} Φ {q0, q1}

{q1, q2} {q0} {q0, q1}

{Φ} Φ Φ

Fig. 17.14

Example 13. Convert the NFA given in Fig. 17.15 to DFA.


a

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

The NFA without ε- moves obtained is shown in Fig. 17.18


1
0

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

δ′({3}, a) = ε-Closure (δ1 ((δ2 (3, ∈), a))


= ε-Closure (δ1 ({1, 3}, a))
= ε-Closure ({Φ ∪ {1, 2}})
= ε-Closure ({1, 2})
= {1} ∪ {2} = {1, 2}
δ′({3},b) = ε-Closure (δ1 ((δ2 (3, ∈), b))
= ε-Closure (δ1 ({1, 3}, b))
= ε-Closure ({Φ ∪ Φ})
= ε-Closure (Φ) = {Φ}
The NFA without ε-moves obtained is shown in Fig. 17.20

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

Sol. The NFA without ε- moves obtained is shown in Fig. 17.22.


a

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

17.10 MINIMIZATION OF DFA


The DFAs that recognize a regular language can be transformed into a unique DFA by
minimizing the number of their states. Let M = (Q, Σ, δ, q0, F) be a DFA that accepts a language
L. Then the following algorithm produces the DFA, say M1 that has the smallest number of
states among the DFAs that accept L.
Minimization Algorithm for DFA
Step 1. Construct a partition Π = {F, Q – F} of the set of states Q;
Step 2. Apply the following procedure to Π to construct a new partition Πnew :
for each set S of do
partition S into subsets such that two states p and q of S are in the same subset of S
if and only if for each input symbol a; p and q make a transition to (states of) the
same set of. The subsets thus formed are sets of the output partition in place of S. If
S is not partitioned in this process, S remains in the output partition.
end
Step 3. If Πnew = Π, then Πfinal: = Π. Otherwise repeat step 2 with : = Πnew.
Construction of the Minimum DFA M1 from final:
(a) Select one state in each set of the partition Πfinal as the representative for the set.
These representatives are states of minimum DFA M1.
(b) Let p and q be representatives i.e., states of minimum DFA M1. Let us also denote by
p and q the sets of states of the original DFA M represented by p and q, respectively. Let s be
a state in p and t a state in q. If a transition from s to t on symbol a exists in M, then the
minimum DFA M1 has a transition from p to q on symbol a.
(c) The start state of M1 is the representative which contains the start state of M.
(d) The accepting states of M1 are representatives that are in F. Note that the sets of
Πfinal are either a subset of A or disjoint from F.
Note. Remove from M1 the dead states and the states not reachable from the start
state, if there are any. Any transitions to a dead state become undefined. A state is a dead
state if it is not an accepting state and has no out-going transitions except to itself.
Example 17. Minimize the number of states of the DFA shown in Fig. 17.23.
a

3 5
a
a

1
b
b b a, b
b
a
2 4

Fig. 17.23

Sol. Initially = {{ 1, 5}, { 2, 3, 4}}.


1. Apply step 2 to Π to obtain Πnew.
Since on b state 2 goes to state 1, state 3 goes to state 4 and 1 and 4 are in different sets
in Π, states 2 and 3 are going to be separated from each other in Πnew.

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

Initially = {{3}, {1, 2, 4, 5, 6}}.


Π new = {{3} , {1, 4, 5}, {2, 6}}
Since Πnew ≠ Π, so Π:= Πnew.
Now, Πnew = {{3}, {1, 4}, {5}, {2}, {6}}
Since again Πnew ≠ Π, so Π:= Πnew.
Again, Πnew = {{1}, {2}, {3}, {4}, {5}, {6}}
Since again Πnew ≠ Π, so Π: = Πnew.
Again, Πnew = {{1}, {2}, {3}, {4}, {5}, {6}}
Since now Πnew = Π, so we reached at the solution. Thus,
ΠFinal = {{1}, {2}, {3}, {4}, {5}, {6}}
From the above, we have found that the number of states of the given DFA is already
minimum and it cannot be reduced any further.

17.11 FINITE AUTOMATA WITH OUTPUTS


The finite automata described earlier have binary output. i.e., they accept the string or
do not accept the string. This acceptability was decided on the basis of reachability of the final
state from the initial state. This restriction limits the ability of the finite automata. Now,
consider the model where the outputs can be chosen from some other alphabet. There are two
different models: When the value of the output function depends only on the present state
then it is called Moore machine. When the value of the output function is a function of the
present state and the present input it is called a Mealy machine.

17.11.1 Moore Machine


The Moore machine is a six-tuple (Q, Σ, Δ, δ, λ, q0) where
Q is a set of finite states:
Σ is the input alphabet;
Δ is the output alphabet;
δ is the transition function Σ × Q into Q;
λ is the output function mapping Q into Δ.
q0 is the initial state;
Example 19. Construct the Moore machine that will count the number of times the
substring aab occurs in an input string.
Sol. The Moore machine is shown in Fig. 17.26.
b a
a
a b
q0/0 q1/0 q2/0 q3/1

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

Sol. The transition diagram of the corresponding transition function is shown in


Fig. 17.28.

a, b

q1/0
a b
a
q0/1 a q3/1

b b
2

Fig. 17.28

17.11.2 Mealy Machine


The Moore machine is a six-tuple (Q, Σ, Δ, δ, λ, q0) where
Q is a set of finite states:
Σ is the input alphabet;
Δ is the output alphabet;
δ is the transition function Σ × Q into Q;
λ is the output function mapping Q × Σ into Δ.
q0 is the initial state; 1/0, 0/1
Example 21. Construct the Mealy machine that prints out the 1’s
complement of an input bit string. q0
Sol. The mealy machine is shown in Fig. 17.29.
Fig. 17.29

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

Example 22. Construct the Mealy machine No


carry
called the increment machine, that increments 1 in the 0/1
given binary input.
Sol. The Mealy Machine is shown in Fig. 17.30 Start 0/1
If the input is 1011 the output is 1100.
1/0
Both Moore and Mealy machines are equivalent.
Carry

1/0

Fig. 17.30

17.11.3. Moore to Mealy Conversion. If Mo is a Moore machine, then there is a


Mealy machine Me that is equivalent to Mo. The following procedure will construct an
equivalent mealy machine corresponding to a Moore machine.
(1) Consider a particular state in Mo, say state q0, which prints a certain character, say t.
(2) Consider all the incoming edges to q0. Suppose these edges are labeled with a, b, c, ...
(3) Let us relabel these edges as a/t, b/t, c/t, ... and let us erase the t from inside the state
q0. This means that we shall be printing at on the incoming edges before we enter q0.
(4) We leave the outgoing edges from q0 alone. They will be relabeled to print the character
associated with the state to which they lead.
(5) If we repeat this procedure for every state q1, q2, ..., we turn Mo into its equivalent Me.
Example 23. Consider a single state q0 of a Moore machine as shown in Fig. 17.31.
a a/t
b q0/t b/t q0
c c/t

Fig. 17.31 Fig. 17.32

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

q0 b/0 b/0 a/1


q/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

(3) Case 3. An edge that was a loop in Me as shown in Fig. 17.41.

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

17.11.5. Comparison of Moore and Mealy machine


In Moore machines the output is a function of the previous state and the input. However,
in Mealy machines the output is a function of change of state or change of input. A Moore
machine may require more states than a Mealy machine to accomplish the same task. The
output logic of a Mealy machine may be more complex than the output logic of an equivalent
Moore machine. In Moore machine, if the initial state has a positive output, it will be produced
without inputting anything, as you can enter in the initial state without inputting anything.
This is not the case with the Mealy machine.

17.12 LANGUAGES AND GRAMMARS


A grammar consists of a finite set of rules or productions that specifies the syntax of the
language. Also a grammar imposes structure on the sentences of a language. The use of
grammar helps in two classes of problems.
1. Generation of valid strings in the language.
2. Determination of whether a given string is in language.

17.12.1 The Chomsky Hierarchy Languages or Grammars


Languages or Grammars are classified in a hierarchy by Noam Chomsky according to
the form of their productions. Each of the levels in the hierarchy has a corresponding machine
that accepts the automaton class:
Type 0: Unrestricted/ Phrase Structure Languages or Grammars. The languages
defined by Type 0 grammars are accepted by Turing machines. Type 0 grammars have rules of
the form α → β where α and β are arbitrary strings and α ≠ ε.
Example 27. This grammar generates the string aab. The corresponding unrestricted
grammar is as given below.
S → CaB
Ca → aaC
CB → b
Type 1: Context-sensitive Languages or Grammars. The languages defined by Type
1 grammars are accepted by linear bounded automata. Type 1 grammars have rules of the
form α A β αBβ, where A, B ε V, B ≠ ε, and α, β ε T*. Further, S → ε is allowed if S is NOT on
the right side of any production.
Example 28. The language {an bn cn : n ≥ 0} is a context-sensitive grammar. The
productions for the grammar are as follows:
S → aXBC S → aBC X → aXBC
X → aBC CB → BC aB → ab
bB → bb bC → bc cC → cc
Type 2: Context-free Languages or Grammars. The languages defined by Type 2
grammars are accepted by push-down automata; the syntax of natural languages is definable
almost entirely in terms of context-free languages and the tree structures generated by them.
Type 2 grammars have rules of the form A → β, where A ε V and β ε (V ∪ T)*.

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

Example 29. L1 = {anbn | n is a positive integer} is a context-free language. The corre-


sponding CFG is as given below.
S → aSb
S → ab
Example 30. L = {ww | w belongs to {a, b}+} is a context-free language , where w is a
r

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

Language Grammar Machine Example


Type 3 or Regular Regular grammar Finite State Automaton a*
language
Type 2 or Context-free Context-free grammar Pushdown automaton a n bn
language (PDA)
Type 1 or Context- Context-sensitive Linear-bounded a n b n cn
sensitive language grammar automaton(LBA)
Type 0 or Recursively
enumerable language/ Unrestricted grammar Turing machine (TM) Any computable
Unrestricted Language function

These languages form a strict hierarchy; that is, regular languages ⊂ context-free
languages ⊂ context-sensitive languages ⊂ recursively enumerable languages.

17.13 RELATION BETWEEN DIFFERENT CLASSES OF LANGUAGES


Every regular language is context-free, every context-free language, not containing the
empty string, is context-sensitive and every context-sensitive language is recursive and every
recursive language is recursively enumerable. These are all proper inclusions, meaning that
there exist recursively enumerable languages which are not context-sensitive, context-sensitive
languages which are not context-free and context-free languages which are not regular.
If a language L generated by a context free grammar does not contain ε, then L can be
generated by a context sensitive grammar. If L contains ε, then L-{ε} can be generated by a
context sensitive grammar. Every language generated by a context sensitive grammar can be
generated by a phrase structure grammar.
The families of languages generated by the grammars in the Chomsky hierarchy form
an inclusive hierarchy that may be represented as
L3 ⊂ L2 ⊂ L1 ⊂ L0
Thus, for example, the context-free languages are included in the family of context-
sensitive languages, and the context-free languages include the regular or finite languages.
The inclusion is proper so that, for example, there are context-free languages that are not
regular or finite.

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.

17.14 EQUIVALENT FA’S


Two finite state automaton are said to be equivalent if, starting from their initial states,
both will produce the same output sequence when they have the identical input sequence.

Finite Automaton (FA) Equivalence Algorithm


This algorithm is developed by E.F. Moore, and it determines whether or not two FSM’s
M and M′ over ∑ are equivalent.
Let us assume that ∑ = {a, b} with n = 2.
Step 1. Construct a comparison table
The comparison table consists of n + 1 = 3 columns.
In the first column, list an ordered pair of vertices (V, V′), where V ∈ M and V′ ∈ M′.
In the second column, list the pairs (Va, Va′) if there is an arrow labelled a ∈ ∑ leading
from V to Va and V′ to Va′.
In column three, list the pairs (Vb, Vb′) if there is an arrow labelled b ∈ ∑ leading from
V to Vb and V′ to Vb′. Repeat this exercise for all other column in the table. If (Va, Va′) does not
occur previously in column 1, place it in column 1 of the next row and repeat the process).
Treat the (Vb, Vb′) and other pairs similarly.
Step 2. Establish the equivalence.
If in the table a pair (V, V′) is reached in which V is a final vertex of M and V′ is a non
final vertex of A′ or vice-versa, stop. The FSM’s are not equivalent. Otherwise, terminate
when there are no new pairs in columns, 2, 3, ...., n that do not occur in column 1. In this case,
M and M′ are equivalent.
Example 34. Consider the two FA’s given in Fig. 17.46 with ∑ = {0, 1}. Determine whether
they are equivalent or not.
0

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

Sol. Construct the comparison table as shown in Table given below.

(V, V′) (V0, V0′) V1, V 1′

(1, 1′) (1, 1′) (2, 4′)


(2, 4′) (3, 2′) (1, 3′)

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

Problem 4. Consider the language L = (a2, b2, ab). Determine


(i) L0 (ii) L2 (iii) L3.
0
Sol. (i) The language L = {^}
(ii) The language L2 = (a4, a2b2, a3b, b2a2, b4, b2ab, aba2, ab3, abab) the language.
(iii) The language L3 = (a6, a4b2, a5b, a2b2a2, a2b4, a2b2ab, a3ba2, a3b3, a3bab, a2a4, b2a2b2,
b2a3b, b4a2, b6, b4ab, b2aba2,b2ab3, b2abab, aba4,aba2b2, aba3b,
ab3a2, ab5, ab3ab, ababa2, abab3, ababab).

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

Problem 5. Describe the following sets by regular expression R over Σ = {a, b}


(i) L1 = the set of all strings which consists of all words with exactly two a’s.
(ii) L2 = the set of all strings which consists of all words beginning with ‘a’ followed by
zero or more b’s.
(iii) L3 = (^, a, aa, aaa, aaaa, ...)
(iv) L4 = (ab, ba)
(v) L5 = The set of all words without a double a.
Sol. (i) The regular expression for L1 is R = b* ab* ab*
(ii) The regular expression for L2 is R = ab*
(iii) The regular expression for L3 is R = a*
(iv) The regular expression for L4 is R = ab + ba
(v) The regular expression for L5 is R = b* (abb*)*(^ + a).
Problem 6. Give regular expressions for each of the following:
(a) All strings of a’s and b’s containing the substring abba.
Sol. (a + b)*abba(a + b)*
(b) All strings of a’s and b’s not containing the substring abba.
Sol. (b + a(a + ba)*bbb)*(a(a + ba)*(b + bb)?)?
(c) All strings of a’s and b’s with an even number of a’s.
Sol. (ab*a + b)*
(d) All strings of a’s and b’s with an even number of a’s and an even number of b’s.
Sol. (aa + bb)*((ab + ba)(aa + bb)*(ab + ba)(aa + bb)*)*
(e) All strings of a’s and b’s with an equal number of occurrences of ab and ba as
substrings. Note that aba contains one substring ab and one substring ba. But abab has two
ab’s but only one ba.
Sol. ε + a + b + a(a + b)*a + b(a + b)*b
Problem 7. Give DFAs that recognize the following languages, where the alphabet is
{a, b, c}:
(a) L1 consists of all strings that start with ab.
(b) L2 consists of all strings that contain cca.
(c) L3 consists of all strings that contain at least 3 b’s (not necessarily consecutive)
(d) L4 consists of all strings that contain exactly 3 b’s (not necessarily consecutive)
(e) L5 consists of the strings where the number of b’s is a multiple of 3.
Sol.
(a) The DFA that accepts all strings that start with ab is shown in Fig. 17.51.
a, b

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

(c) The corresponding DFA is shown in Fig. 17.53.

a, c a, c a, c a, b, c

b b b
1 2 3 4

Fig. 17.53

(d) The corresponding DFA is shown in Fig. 17.54.

a, c a, c a, c a, c a, b, c

b b b b
1 2 3 4 5

Fig. 17.54

(e) The corresponding DFA is shown in Fig. 17.55.

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

Problem 9. Construct a DFA


(i) to accept a string containing a zero followed by a one.
(ii) to accept a string containing two consecutive zeroes followed by two consecutive ones.
(iii) to accept a string containing even number of zeroes and any number of ones.
Sol.
(i) The corresponding DFA is shown in Fig. 17.57.

Start q0 0 q1 1 q2

1 0 0.1

Fig. 17.57

(ii) The corresponding DFA is shown in Fig. 17.58.


0

Start 0 0 1 1
q0 q1 q2 q3 4
1

1 0 0.1

Fig. 17.58

(iii) The corresponding DFA is shown in Fig. 17.59.

Start 0
q0 q1
0

1 1

Fig. 17.59

Problem 10. Construct a DFA


(i) to accept all strings which do not contain three consecutive zeroes
(ii) to accept all strings containing even number of zeroes and even number of ones
(iii) to accept all strings which satisfies #(x) mod 5 = 2
(iv) to accept all strings (0 + 1)* with an equal number of 0’s & 1’s such that each prefix
has at most one more zero than ones and at most one more one than zeroes
Sol.
(i) The DFA is shown in Fig. 17.60.

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

(ii) The corresponding DFA is shown in Fig. 17.61.

Start 0
q0 q1
0

1 1 1 1

0
q3 q2
0

Fig. 17.61

(iii) The corresponding DFA is shown in Fig. 17.62.

Start q0 1 q1 0 q2

0 1
1 0 0

q3 q4
0
1

Fig. 17.62

(iv) The corresponding DFA is shown in Fig. 17.63.

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

Further the equivalent DFA is shown in Fig. 17.65.

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

Sol. The corresponding DFA is shown in Fig. 17.67.

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

1/0 1/0 1/0


S0 S1 S2 S3
0/0
0/0
1/1

Fig. 17.69

The equivalent mealy machine is shown in Fig. 17.70.

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

1¢0 1.0 0/1

+111 –10
0.1

Fig. 17.71

Problem 16. Give an example for each of the following:


(a) A context-free language that is not regular.
Sol. { anbn | n ≥ 0}
(b) A context-free language whose complement is regular.
Sol. a*
(c) A context-free language whose complement is not context free.
Sol. L = { ww | w is in (a + b)*} is not context-free.
The complement of L is context free.
(d) A context-free language in which all strings are palindromes.
Sol. { wwR | w is in (a + b)*}
(e) Two context-free languages whose intersection is not context free.
Sol. Let L = { anbnci | i, n ≥ 0 } and M = { aibncn | i, n ≥ 0} are two CFG’s.
But M ∩ N = { anbncn | n ≥ 0} is not context free.

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

(a) 1010 (b) 11011011 (c) 1010001001.


Sol. (a) Beginning at q0, follow the path which are labeled by the input symbols and
write the output symbols. Thus.

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

The output is 1010111010.

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

(c) The output string corresponding to the input string of w = 12 0 13 03 1 0 1 is determined


by following the path in the state diagram.
1/b 1/b 0/a 1/ a 1/b 1/b 0/b
Path = q0 ⎯⎯⎯
→ q3 ⎯⎯⎯
→ q0 ⎯⎯⎯
→ q1 ⎯⎯⎯
→ q2 ⎯⎯⎯
→ q4 ⎯⎯⎯
→ q4 ⎯⎯⎯

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

MULTIPLE CHOICE QUESTIONS

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

(a) 11100100 (b) 00010100


(c) 11110100 (d) 00011011
9. Which of the following is a finite state language ?
(a) L1 = { 0n1n | n ≥ 1} (b) L2 = { 0n1m| n ≥ m}
(c) L1 = { ww | w is a string of a’s and b’s} (d) L1 = { an bm | n, m ≥ 1}
10. Which of the following grammar is ambiguous?
(a) E → E + E | E*E | id (b) S → CD | AAD, C → a/Ca, D → b
(c) S → aSbs | bSaS | ε, (d) All the above.

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

(i) the regular expression to specify L.


(ii) a finite state automata M, such that M(L) = L.
(iii) a regular grammar G, such that G(L) = L.
5. Give the regular expression of the set of all even strings over the alphabet {a, b} with at least one
of the two substrings aa or bb. Also construct the finite automata that can accept the above
language.
6. Consider transition table as given below. Construct the transition diagram for it.

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

27. Convert the NFA given below to DFA.

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

41. Construct a Moore machine equivalent to the following Mealy machine.

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

42. Construct a Mealy machine similar to the following Moore machine.

q0/0 a q1/0 b q2/0 a q3/1

b a b

q4/0

a, b

43. Construct a Moore machine equivalent to the following Mealy machine.

1/1
q3
1/0 1/0

q0 1/0 q2
0/0 1/0

0/0
0/0 q1

44. If G = ({S}, {0, 1}, {S → OS1, S → ∈}, S), find L(G).


45. Explain Chomsky classification of languages with suitable examples.
46. Define grammar. Differentiate a context-free grammar from a regular grammar.
47. Construct the grammar G that generates the language L = {0n1n2n : n ≥ 1}.
48. Determine the type and the name of the grammar the following set of production rules belong to.
Also identify the language it can generate.
S1 → S 1S2
S1 → 1S1
S1 → e
S2 → S 2S3
S2 → 01S2
S2 → 01
S3 → 0S3
S3 → e
49. Determine the type and the name of the grammar the following set of production rules belong to.
(a) S → AB/Ca, B → BC/AB, A → a, C → aB/b.
(b) S → aB/aA, A → a/aS/bAA , B → b/bS/aBB.

Answers and Hints to Selected Problems


4. (i) 0(0+1)*11 5. (aa + bb + abba + abab + baba + baab)*
9. (i) (0+1)*101 (iii) 0(0+1)*1 + 1(0+1)*0 (v) (1*01*01*)*
(ix) (1*01*01*01*)*+1*
49. (a)

EBSCOhost - printed on 9/30/2024 6:39 AM via INTEGRAL UNIVERSITY, LUCKNOW. All use subject to https://www.ebsco.com/terms-of-use

You might also like