You are on page 1of 21

Chapter 1

Finite Automata
and Regular Languages

LEARNING OBJECTIVES

 Fundamentals  Mealy and Moore machines


 Languages  Equivalence of Moore and Mealy machine
 Operations  Regular languages
 Finite state machine  Constructing FA for given RE
 NFA with -moves  Pumping lemma for regular sets
 Conversion of NFA to DFA  Closure properties of regular sets
 Minimization of DFA  Regular grammar
 Equivalence between NFA and DFA

FuNdAMeNtAls Languages
Alphabet: An alphabet is a finite non-empty set of symbols. • A language ‘L’ over Σ is any finite or infinite set of strings over Σ.
Example: Portion of a calculator: {0, 1, 2, 3 … 9, ÷, =, –, +, ×, (,)} • The elements in L are strings – finite sequences of symbols.
• A language which does not contain any elements is called
Note: 1. At least one symbol is necessary. ‘empty language’.
2. ‘Σ’ denote Alphabet.
Note: Empty language, { } ≠ {e}, empty string because { } = ∅ ≠
String: A string over an alphabet ‘A’ is a finite ordered sequence e i.e., Empty language resembles empty set i.e., ∅.
of symbols from ‘A’. The length of string is number of symbols in
string, with repetitions counted. • A language L over an alphabet A is subset of A* i.e., L ⊂ A*.
Example: If Σ = {0 – 9, ÷, =, –, +, × (,)} then Strings valid: 12 + Example 1: Language (L) for strings that consists of only 0’s or
34, 90 × 10, (1 + 2) × (1 ÷ 3) only 1’s and have an odd length over alphabet {0, 1} is
Strings Invalid: sin (45), log (10) etc. These strings are not valid (A) {0, 1, 00, 11, 000, 111 …}
because sin ( ), log ( ) are not defined over the alphabet set. (B) {00, 11, 01, 10 …}
Note: Repetitions are allowed. (C) {000, 101, 110, 111 …}
Length of |12 + 34| = 5(1, 2, +, 3, 4) (D) {0, 1, 000, 111, 11111, 00000 …}
• The Empty string denoted by ‘e’, is the (unique) string of length Solution: (D)
zero. Only 0’s → should have only 0’s. It should not be combination of
Note: Empty string, e ≠ empty set, ∅. 0’s and 1’s.
• If S and T are sets of strings, then ST = {xy|x ∈ S and y ∈ T} Only 1’s → should have only 1’s. It should not be combination of
Given an alphabet A, 0’s and 1’s.
Ao = {e} Odd length → only odd number of 0’s or odd number of 1’s i.e.,
An+1 = A.An length of string should be odd.


A∗ = ∪ An
n =0
5.4 | Unit 5  •  Theory of Computation

An Empty Languages  An empty language is a language 4. Reversal: If ‘w’ is a string, then wR is reversal of string
which does not accept any strings includinge. The Finite spelled backwards.
automata for empty language can be represented as Rules:
•• x = (xR) R
•• (xz)R = zR . xR
Example 4:  A string, x is defined as, x = butter. Then (xR)R
is _______
(A) butter (B) rettub
(i.e., One state, non-accepting and no transitions).
(C) butret (D) retbut
A language which only accepts (e)
E: The language which only accepts ‘e’ can be represented as Solution:  (A)
x → butter
xR → rettub
(xR)R → butter.

Operations on languages
This machine accepts E – only. 1. Union: Given some alphabet Σ, for any two languages,
Σ*: The set of all strings over an alphabet Σ will be denoted L1, L2 over Σ, the union L1 ∪ L2 of L1 and L2 is the
by Σ*. language, L1 ∪ L2 = {w ∈ Σ*|w ∈ L1 or w ∈L2}
Σ+: This will denote the set Σ* – {e}. 2. Intersection: Given some alphabet Σ, for any two
Ex: If Σ = {0, 1} then languages L1, L2 over Σ, the intersection L1 ∩ L2 of L1
Σ* = {e, 0, 1, 00, 01, 10, 11, 000, 001, …} and L2 is language, L1 ∩ L1 = {w ∈ Σ*|w ∈ L1 and w ∈
Σ+ = {0, 1, 00, 01, 10, 11, 000, 001,} L2}
3. Difference: Given some alphabet Σ, for any two
Operations languages L1, L2 over Σ, the difference L1 – L2 of L1 and
L2 is language, L1 – L2 = {w ∈ Σ*|w ∈ L1 and w ∉ L2}
Operations on strings
1. Concatenation: Combines two strings by putting one Note: Difference is also called ‘Relative Complement.’
after other. A special case of difference is obtained when L1 = Σ*, in
which case. Complement L of language, L is defined as,
Example 2:  Two strings are defined as x = java, y = script.
The concatenation (x.y) of two strings results in _______. L = {w ∈ Σ∗| w ∉ L}
4. Concatenation: Given an alphabet Σ, for any two
(A) scriptjava (B) javascript
languages L1, L2 over Σ, the concatenation L1 L2 of L1
(C) jascriptva (D) scrijavapt
and L2 is language
Solution:  (B) L1L2 = {w ∈ Σ*|∃ u ∈ L1, ∃ v ∈L2, w = uv}
x.y = java.script = javascript Properties:
Note: Concatenation of empty string with any other string
L∅ = ∅ = ∅L
gives string itself.
L {e} = L = {e} L
i.e., x.ε = ε.x = x
(L1 ∪ {e})L2 = L1L2 ∪ L2
2. Substring: If ‘w’ is a string, then ‘v’ is a substring of
L1 (L2 ∪ {e}) = L1L2 ∪ L1
‘w’ if there exists string x and y such that w = xvy.
Ln L = LLn = Ln+1
‘x’ is called ‘prefix’ and y is called suffix of w.
Note: L1L2 ≠ L2L1
Example 3:  String, w = ‘gymnastics’ is defined with prefix,
x = ‘gym’ and suffix, y = ‘cs’. The substring of the given Example 5:  Let L1 = {00, 11}, L2 = {01, 10}. Then L1oL2
string is _______ = _______
(A) nasti (B) mnas (A) {00, 11, 01, 10}
(C) gymnastics (D) ics (B) {0001, 0010, 1101, 1110}
(C) {0001, 0010, 11, 01, 10}
Solution:  (A) (D) {00, 1101, 1110, 11, 10}
Because, w = xvy
⇒ gymnastics = gymvcs Solution:  (B)
∴ v = nasti L1oL2 = {00, 11} o {01, 10} = {00.01, 00.10, 11.01, 11.10}
3. Kleen star operation: Let ‘w’ be a string, w* is set of = {0001, 0010, 1101, 1110}
strings obtained by applying any number of concatena- 5. Kleen * closure (L*): Given an alphabet Σ, for any
tions of w with itself, including empty string. language L over Σ, the * closure L* of L is language,
Example: a* = {ε, a, aa, aaa, …} L∗ = U n ≥ 0 Ln
Chapter 1  •  Finite Automata and Regular Languages  |  5.5

6. Kleen + closure (L+): The kleen +closure, L+ of L is Steps:


the language, L+ = U n ≥1 Ln •• Start at ‘initial state’, qo .
L* = L0 ∪ L1 ∪ L2 ∪ … Ln ∪ … •• For every input symbol in sequence w, do.
L+ = L1 ∪ L2 ∪ L3 … ∪ Ln ∪ … •• Compute the next state from current state, given the cur-
rent input symbol in w and transition function.
Properties: •• If after all symbols in ‘w’ are consumed, the current state
∅* = {e} is one of the final states (f) then accept ‘w’;
L+ = L*L •• Otherwise, reject w.
(L*)* = L*
L* L* = L* Transition diagram: State machines are represented by
directed graphs called transition (state) diagrams.
Finite State Machine (FSM) •• The vertices denoted by single circle represent the
•• FSM is simplest computational model of limited memory state and arcs labeled with input symbol correspond to
computers. transition.
•• FSM is designed to solve decision problems i.e., to decide •• The final states are represented with double circles.
whether given input satisfies certain conditions.
Transition Table: Transition function can be represented
•• The next state and output of a FSM is a function of input
by tables.
and of current state.
Example 6:  The following finite state machine accepts all
State
Output those binary strings in which the numbers of 0’s and 1’s are
Inputs transition State Outputs
conditions respectively.
conditions
0 0

Types of FSM: 1 q8 q9 1 q 10
q7
1. Melay machine. 0 1
1 1 1 0
2. Moore machine
q1 0 q2 q 11
0 0 0
Finite Automata (FA): 1
q0 1
1 0 q3
•• FA is a state machine that comprehensively captures all 1 0 1
q6 0
possible states and transitions that a machine can take 0
q5 q4 0 q 12
while responding to a stream (sequence) of input symbols. 1
•• FA is recognizer of ‘regular languages’. 1 1
q 14 1 q 13
State Machine
0
0
Finite state machine Finite automata
(generates o/p) (doesn’t generates o/p) (A) Divisible by 3 and 2 (B) Odd and even
(C) Divisible by 5 and 3 (D) Divisible by 2 and 3
Mealy Moore DFA NFA ∈-NFA Solution:  (C)
Number of 0’s is divisible by 5.
Types of FA Number of 1’s is divisible by 3.
1. Deterministic Finite Automata (DFA): Table  Transition Table

•• DFA machine can exists in only one state at any given time. Current State 0 1
•• DFA is defined by 5-tuple: {Q, Σ, q0, F, d}, where → q0 q1 q5
q1 q2 q7
Q → Finite number of states (elements)
Σ → Finite set of symbols (alphabets) q2 q3 q9
qo → Start/Initial state q3 q4 q11
F → Set of final states. q4 q0 q13
δ → Transition function, which is a mapping between q5 q7 q6
δ: Q × Σ → Q. q6 q8 q0
How to use DFA: q7 q9 q8
Input: A word w in Σ* q8 q10 q1
Question: Is w acceptable by DFA?
5.6 | Unit 5  •  Theory of Computation

q9 q11 q10 String: 0100100


q10 q12 q2 q0 0
→{q0 , q1}
q11 q13 q12
q12 q14 q3 q0 0
→ q0 1
→ q0 0
→{q0 , q1}
q13 q0 q14 q0 0
→ q0 1
→ q0 0
→ q0 0
→{q0 , q1}
q14 q6 q4
q
01
→ q0 0
→ q0 0
→{q0 , q1} (Non-deterministic)
Note: Minimum number of states for k-divisibility is q0 0
→ q0 1
→ q0 0
→ q0 0
→{q0 , q1}
k-states.
In above example, q0 – q14 → 15 – states. q1 1
→ q2 0
→ q2 0
→ q2
∴  5 × 3 = 15
The given binary strings have number of 0’s divisible by 5 Table 2  Difference between NFA and DFA
and number of 1’s divisible by 3. DFA NFA
2.  Non-deterministic finite Automata (NFA): 1. All transitions are deter- 1. Transitions could be non-
ministic i.e., each transition deterministic i.e., a transition
•• The machine can exist in multiple states at the same time. leads to exactly one state. could lead to a subset of
•• Each transition function maps to a set of states. states.
•• NFA is defined by 5-tuple: {Q, Σ, q0, F, d}, where 2. For each state, the transition 2. For each state, not all sym-
Q → Finite number of states (elements) on all possible symbols bols necessarily have to be
should be defined. defined.
Σ → Finite set of symbols. (Alphabets)
qo → Start/Initial state 3. Accepts input if last state is 3. Accepts input if one of last
in ‘F’. states is in ‘F’.
F → Set of final states.
d → Transition function which is a mapping between 4. Practical implementation is 4. Practical implementation
feasible. has to be deterministic (so
δ = Q × Σ → 2Q needs conversion to DFA).
How to use NFA:
Relation between DFA and NFA
Input: a word w in Σ*
Question: Is w accepted by NFA? •• A language ‘L’ is accepted by a DFA if and only if it is
Steps: accepted by a NFA.
•• Every DFA is special case of a NFA.
•• Start at ‘start state’ q0.
•• For every input symbol in the sequence, w does. Example 8: Let Nf and Df denote the classes of languages
•• Determine all possible next states from current state, given accepted by non-deterministic finite automata and deterministic
the current input symbol in w and transition function. finite automata respectively. Which one of following is true?
•• If after all symbols in w are consumed, at least one of the (A) Df ⊂ Nf (B) Df ⊃ Nf
current states is a final state then accept w. (C) Df = Nf (D) Df ∈ Nf
•• Otherwise, reject w.
Solution:  (C)
Example 7: What is the language, L generated by the According to ‘subset construction’, every language accepted
below NFA, given strings defined over alphabet, Σ = {0, 1}. by NFA is also accepted by some DFA.
∴  Df = Nf
0,1 0

q0 0 q1 1 q2
NFA with ∈-Moves
•• ∈-transitions in finite automata allows a state to jump to
(A) Strings that end with ‘0’ another state without consuming any input symbol.
(B) Strings that start with ‘0’ and end with ‘0’ Conversion and Equivalence:
(C) Strings that contain ‘01’ as substring
(D) Strings that contain ‘01’ as substring and end with ‘0’ ∈-NFA → NFA → DFA
NFA without ∈-moves:
Solution:  (D)
•• Two FA, N∈ and N are said to be equivalent, if L(N∈) =
State 0 1 L(N) i.e., any language described by some N∈, there is an
→ q0 {q0, q1} {q0}
N that accepts the same language.
q1 ∅ q2
•• For N∈ = (Q, Z, d, q0, F) and N = (Q, Σ′, d ′, q0, F′ ), Find
q2 {q2} ∅
•• d ′(q, a) = ∈-closure (δ(∈-closure(q), a))
Chapter 1  •  Finite Automata and Regular Languages  |  5.7

•• F ′ = {F ∪ {q0}}, if ∈-closure (q0) contains a member of That is, to compute δD(S, a), look at all states P in S, see
F = F, otherwise. what states N goes to starting from P on input a, and take
Note: When transforming N∈ to N, only transitions are the union of all those states.
required to be changed and states remains same. Note: For any NFA, N with ‘n’ states, the corresponding
Example 9:  Consider following NFA with ∈-moves. DFA, D can have 2n states.
a ∈ Example 10:  What is the number of final states in DFA
q0 ∈ q1 a q2 b q3 constructed from the given NFA?
a

If given NFA is converted to NFA without ∈-moves, which


of following denotes set of final states? 1
(A) {q0, q1} (B) {q1, q2} a, b
a b
(C) {q1, q2, q3} (D) {q1}
a, b b
Solution:  Let N = (Q, Σ1, δ1, q0, F1) 0 2 b
F1 = F ∪ {q0} b
a, b 4
ε-closure (q0) = {q0, q1}
∴ F1 = {q1} ∪ {q0, q1} = {q0, q1} 3 a, b
Conversion N∈→N:
To compute, δ1 b
∈-closure (q0) = {q0, q1}, ∈-closure (q3) = {q3, q1}
δ1(q0, a) = {q1, q2}, δ1(q0, b) = ∅, d1(q2, a) = ∅. (A) 1 (B) 2
δ1(q1, a) = {q1, q2}, δ1(q1, b) = ∅, d1(q2, b) = {q1, q3} (C) 3 (D) 4
δ1(q3, a) = {q1, q2}, δ1(q3, b) = ∅ Solution:
Table 4  Transition Table of NFA
Table 3  Transition Table
Input Input
State a b State a b
→ q0 {q1, q2} ∅ → 0 {1, 2, 3} {2, 3}
q1 {q1, q2} ∅ 1 {1, 2} {2, 3}
q2 ∅ {q1, q3} 2 ∅ {2, 3, 4}
q3 {q1, q2} ∅ 3 {4} {3, 4}
4 ∅ ∅
a
Table 5  Transition Table of DFA
q1
Input
a
a b State a b
a
→0 [1, 2, 3] [2, 3]
q0 a q2 b q3
1 [1, 2] [2, 3]
a 2 ∅ [2, 3, 4]

Figure 1  Transition diagram 3 4 [3, 4]


4 ∅ ∅
Conversion of NFA to DFA [1, 2] [1, 2] [2, 3, 4]

Let a NFA be defined as, N = (QN, Σ, δN, q0, FN) [2, 3] [4] [2, 3, 4]
The equivalent DFA, D = (QD, Σ, δD, q0, FD) where: [3, 4] [4] [3, 4]
Step I: QD = 2QN ;  i.e., QD is set of all subsets of QN i.e., it is
[1, 2, 3] [1, 2, 4] [2, 3, 4]
power set of QN.
Step II: FD is set of subsets S of QN such that S ∩ FN ≠ [1, 2, 4] [1, 2] [2, 3, 4]
∅. i.e., FD is all sets of N’s states that include atleast one [2, 3, 4] [4] [2, 3, 4]
accepting state of N.
Step III: For each set, S ≤ QN and for each input symbol a in Hence final states in obtained DFA is ‘4’.
Σ : δ D ( S , a ) = ∪ P∈S δ N ( P, a ) DFA is: Choice (D)
5.8 | Unit 5  •  Theory of Computation

a b 2
b
a a (B)
[1, 2, 3] [1, 2, 4] [1, 2] 1 a
a
b b a 3
0 b
b a a, b
[2, 3, 4] 2
b b b
1 3 4
[2, 3] (C) a
a
a a b b
b b
4 a 1
3 (D) 1 2
a b
[3, 4] b a a

b 5

Solution:  (B)
Minimization of DFA Initially, {1, 5}, {2, 3, 4}
Depending on next states and inputs, the partitions of states
Given a DFA, M = (Q, Σ, δ , q0 , F ), we construct a reduced
can be as: {{1, 5}, {2}, {3}, and {4}}
DFA, M ′ = ( Q ′, Σ′, δ ′, q0′ , F ′ ) as follows Since, 1 to 5 have same transition, unite {1, 5}
1. Remove all inaccessible states. All states that are State 4 is dead state → It has transition only to itself.
unreachable from the initial state are removed. Since, {2}, {3} are singletons, they exist.
2. Consider all pairs of states (p, q), If p ∈ F and q ∈ F ∴ States in minimized DFA are {1, 2, and 3}
or vice versa mark the pair (p, q) as distinguishable. {1} → {1, 5}
3. Repeat until no previously unmarked pairs are For transitions, since 1 a → 3, 1 b→ 2 in given DFA,
marked. For all pairs (p, q) and all a ∈ Σ, compute in minimized DFA, transitions are added from
1 a → 3, 1 b → 2. Also, since 2 b →1, 3 a
→1 in
δ ( p, a ) = pa and δ ( p, q ) = qa . If the pair (pa, qa) is
given DFA, the minimized DFA, transitions are added from
marked as distinguishable mark (p, q) as distinguishable.
2 b→1, 3 a → 1.
4. Find the sets of all indistinguishable states, say
{qi , q j ,  qk }, {q , qm ,  qn }, etc. For each set
{qi, qj, … qk} of such indistinguishable states, create Equivalence Between NFA
a state labelled ij … k for M. and DFA
5. For each transition rule of M of the from δ (qr , q ) = q p , There is a DFAD for any NFAN i.e.,
find the sets to which qr and qp belong. If qr ∈ {qi,qj, L (D) = L (N).
… qk} and qpe {q , qm ,  qn }, add a rule to δ : Construction:
δ ′(ij … k , a ) = m … n. •• In DFA or NFA, whenever an arrow is followed, there is
a set of possible states. This set of states is a subset of Q.
Example 11:  A DFA with alphabet Σ = {a, b} is given below: •• Track the information about subsets of states that can be
a reached from initial state after following arrows.
•• Consider each subset of states of NFA as a state of DFA
a 3 5 and every subset of states containing a final state as a final
a
b
1 b b state of DFA.
a, b
2 4 Example 12:  Which of following is equivalent DFA for the
b a
NFA given below:
Which of the following is valid minimal DFA which accepts c
same language as given DFA?
q1 d q4
b
b
a a d d c c
1 3 5
(A) a
b q2 c q3
b
a, b
4 d
Chapter 1  •  Finite Automata and Regular Languages  |  5.9

c the start state of M2 to the final state of M2 labeled


a1a2… ak.
q1 (ii) If there is a path from the start state of M2 to a final state
d M2 labeled b1b2 … bi then there is a path from the start
(A)
d c state of M1 to the final state of M1 labeled b1b2 … bi .
d q3

q2
Example:
c

c d 0
M1
q1 d q3 1
q0 q1
(B) c d 1
c
0
q2 0

c d q2
1
q1 d q4
(C)
c c M2:
d
q3
0
c, d d
(D) 1
q1 c q2 p0 p1
1

Solution:  (A) 1 0

Table 6  Transition Table of NFA 0


p3 p2 1
d c d
0
→ q1 q1 {q2, q4}
q2 q3 q1 In M2, states p1 and p3 are equivalent (as both are reaching
either final or non-final states with same input). After mini-
q3 q4 q3
mizing M2, we will get
q4 q3 ∅
0
Table 7  Transition Table of DFA
d c d
p0 1 p 1p 3
→ q1 q1 q2
1
q2 q3 q1
q3 q2 q1 0 0

Table 8  Common Table


p2
d c d
1
(q1, q1) (q1, q1) (q2, q4, q2)
(q2, q2) (q3, q3) (q1, q1)
\ M1 and M2 are equivalent.
(q3, q3) (q4, q2) (q3, q3)
Union: The union of two languages L and M is the set of
(q4) q3 ∅ strings that are in both L and M.
Ex: L = {0, 1}, M = {111}
Equivalence of Finite Automatas: L U M = {0, 1,111}.
•• Two automatas A and B are said to be equivalent if both Concatenation: The concatenation of Languages L and M
accept exactly the same set of input strings. is the set of strings that can be formed by taking any string
•• If two automatas M1 and M2 are equivalent then in L and concatenating it with any string in M.
(i) If there is a path from the start state of M1 to a final Example: L = {0, 1}, M = {e, 010}
state of M1 labeled a1a2 … ak then there is a path from LM = {0, 1, 0010, 1010}.
5.10 | Unit 5  •  Theory of Computation

Closure, Star or Kleen star of a language L: Union of M1 and M2:


Kleen star is denoted as L*. It represents the set of strings that 0
can be formed by taking any number of strings from L with
repetition and concatenating them. It is a Unary operator. q 01 q 12
q 01 q 02
L0 is the set; we can make selecting zero strings from L.
L0 = {e} 0
L1 is the language consisting of selecting one string from L.
L2 is the language consisting of concatenations selecting 1 1 1 1
two strings from L.
… 0
L* is the union of L0, L1 , …L∞.
Ex: L = {0,10} q 11 q 02 q 11q 12
L* = {0,00,000,10,010, …}
0
Intersection:
Let two DFAs M1 and M2 accept the languages L1 and L2. Difference: The difference of L1 and L2 can be given as
M1 = (Q1, Σ, d1, q01, .F1) L1 - L2 with M = (Q, ∑, d, q0, F).
M2 = (Q2, Σ, d2, q02, F2) Q = Q1 × Q2
The intersection of M1 and M2 can be given as
q0 = (q01, q02)
M = (Q1, Σ, d, q0 F)
Q = Pairs of states, one from M1 and one from M2 i.e., d ((qi1, qj2), x) = (d1 (qi1, x), d2(qj2, x))
Q = {(q1, q2) | q1 ∈ Q1 and q2 ∈ Q2} F = {(q1, q2) | q1, ∈ F1 and q2 ∉ F2}
Q = Q1 × Q2.
q0 = (q01, q02) 0
d (qi1 qj2), x) = (d1(q11, x), d2(qj2, x))
F = {(q1, q2) | q1, ∈ F1 and q2 ∈ F2} q 01 q 02 q 01 q 12

Example: 0
M1: Strings with even number of 1’s.
0 0 1 1 1 1
1
0
q 01 q 11
q 11q 02 q 11q 12
1
M2: Strings with odd number of 0’s. 0

1 1
0 Reversing a DFA:
q 12
•• M is a DFA which recognizes the language L.
q 02
•• MR will accept the language LR.
0 To construct MR:
•• Reverse all transitions
M1 ∩ M2: Strings with even number of 1’s and odd number
•• Turn the start state to final state
of 0’s.
•• Turn the final states to start state.
0 •• Merge states and modify the FA,
such that the resultant contain a single start state.
q 01 q 02 q 02 q 12

0 Mealy and Moore Machines


Moore Machine
1 1 1 1
A moore machine is a finite state machine, where outputs
0 are determined by current state alone.
A Moore machine associates an output symbol with each
q12 q02 q12 q12 state and each time a state is entered, an output is obtained
simultaneously. So, first output always occurs as soon as
0 machine starts.
Chapter 1  •  Finite Automata and Regular Languages  |  5.11

Moore machine is defined by 6-tuples: Only this second resultant output is considered as the final
(Q, Σ, δ, q0, ∆, λ), where output of (Me)2. If final output string is same as original
Q → Finite set of states input string then (Me)2 has an identity property. Consider
 Σ → Finite set of input symbols following machines.
 ∆ → It is an output alphabet
 δ → Transition function, Q × Σ → Q (state function) 0/1, 1/0
 λ → Output function, Q → ∆ (machine function) (i)
q0 → Initial state of machine
0/0, 1/1
Note: The output symbol at a given time depends only on (ii)
present state of moore machine.
Example 13: The language generated by the following 0/1, 1/0
moore machine is: (iii) 0/0, 1/1
0
0
q 1/1 Which of above machines have identity property?
1 0 (A) (i) only
q 0 /0 (B) (i) and (ii) but not (iii)
(C) (i) and (iii) but not (ii)
1 (D) All have identity property
q 2/0
Solution:  (D)
1

(A) 2’s complement of binary number. (i) Consider i/p string


(B) 1’s complement of binary number. 01 0 1
(C) Has a substring 101. ↓↓ ↓ ↓
(Input string
(D) Has a substring 110. o/p string 10 1 0
reprocessed)
↓↓ ↓ ↓
Solution:  (B) 01 0 1 o/p string
Binary number: 1011
1’s complement: 0100 (ii)
q0 → q2 , → q1 → q2 → q2
1/ 0 0 /1 1/ 0 1/ 0 i/p string: 0 1 1 0
↓ ↓ ↓ ↓
1 → 0, 0 → 1, 1 → 0, 1 → 0
o/p string: 0 1 1 0

(i/p string) ↓ ↓ ↓ ↓
Mealy Machine
•• A mealy machine is a FSM, where outputs are determined o/p string: 0 1 1 0
by current state and input.
•• It associates an output symbol with each transition and (iii)
i/p string: 1 0 0 1
the output depends on current input.
↓ ↓ ↓ ↓
•• Mealy machine is defined on 6-tuples: (Q, Σ, δ, q0, ∆, λ),
where o/p string: 1 1 1 0
(i/p string) ↓ ↓ ↓ ↓
Q – Finite set of states.
Σ – Finite set of input symbols. o/p string: 1 0 0 1
δ – (Q × Σ → Q) is transition function.
q0 → q0 ∈ Q is initial state. Equivalence of Moore and Mealy machine
∆ → Finite set of output symbols.
(a) Mealy machine equivalent to Moore machine:
l → Output function, l(Q → ∆)
If M1 = (Q, Σ, D, d, l, q0) is a Moore machine, then there is
Note: In Moore machine, for input string of length n, the a Mealy machine M2 equivalent to M1.
output sequence consists of (n + 1) symbols.
Proof: Let M2 = (Q, Σ, D, d, l1, q0) and define l1 (q, a) to be
In Mealy machine, for input string of length n, the output
l(d (q, a)) for all states q and input symbol ‘a’.
sequence also consists of ‘n’ symbols.
Then M1 and M2 enter the same sequence of states on the
Example 14:  Let (Me)2 mean that given a Mealy machine, same input, and with each transition M2 emits the o/p that
an input string is processed and then output string is M1 associates with the state entered.
immediately fed into the machine (as input) and reprocessed. Let us consider Mealy Machine
5.12 | Unit 5  •  Theory of Computation

Next State Every induction on ‘n’ shows that if M1 enters states q0, q1
Present Input a=0 Input a=1 … qn on inputs a1, a2 … an and emits output b1, b2, … bn then
State State Output State Output M2 enters states [q0, b0], [q1, b1] … [qn, bn] and emits outputs
→ q1 q3 0 q2 0 b0, b1 … bn.
Let us consider the Moore machine
q2 q1 1 q4 0
q3 q2 1 q1 1 Next State
Present
q4 q4 1 q3 0 State a=0 a=1 Output
→ q0 q3 q1 0
To convert the Mealy machine to Moore machine, q1 q1 q2 1
q2 q2 q3 0
•• We look into the next state column for any state, say qi
q3 q3 q0 0
and determine the number of different outputs associated
with qi in next column.
•• Split qi into several different states, the number of such •• To convert Moore into Mealy machine, we must follow
states being equal to the number of different outputs asso- the reverse procedure of converting Mealy machine into
ciated with qi. Moore machine.
•• For every input symbol we form, the pair consisting of the
next state and the corresponding output and reconstruct
Next State
the table for Mealy machine.
Present Input a=0 Input a=1
•• For example, the state q3 and q1 in the next state column
State State Output State Output
should be associated with outputs 0 and 1, respectively.
→ q1 q3 0 q20 0
q20 q1 1 q40 0 The Transition table for Mealy machine is:
q21 q1 1 q40 0 Next State

q3 q21 1 q1 1 Present a=0 a=1


state state output state output
q40 q41 1 q3 0
→ q0 q3 0 q1 1
q41 q41 1 q3 0
q1 q1 1 q2 0
q2 q2 0 q3 0
•• The pair of states and outputs in the next state column can
be rearranged as: q3 q3 0 q0 0

Present
Next State Regular Languages
state a=0 a=1 output The set of regular languages over an alphabet Σ is defined
→ q1 q3 q20 1 recursively as below. Any language belonging to this set is a
q20 q1 q40 0 regular language over Σ.
q21 q1 q40 1 Definition of set of regular languages
q3 q21 q1 0 •• Basis clause: ∅, {ε}, {a} for any symbol a ∈ Σ, are regu-
q40 q41 q3 0 lar languages.
q41 q41 q3 1 •• Inductive clause: If Lr and Ls are regular languages, then
Lr ∪ Ls, Lr . Ls, Lr* are regular languages.
•• External clause: Nothing is a regular language, unless it is
Moore machine equivalent to Mealy machine obtained from above two clauses.
Let M1 = (Q, Σ, D, d, l, q0) be a Mealy machine. Then there
is a machine M2 equivalent to M1 Regular language: Any language represented by regular
Proof: Let M2 = (QXD, Σ, D, d1, l1, [q0, b0]), where b0 is an expression(s) is called a regular language.
arbitrary selected member of D. Ex: The regular expression a* denotes a language which has
That is, the states of M2 are pairs [q, b] consisting of a {e, a, aa, aaa, …}
state of M1 and output symbol, Define d1 ([q, b], a) = [d (q,
a), l, (q, a)] and l1 ([q, b]) = b. Regular expression
The second component of a state [q, b] of M2 is the out- •• Regular expressions are used to denote regular languages.
put made by M1 on some transition into state q. •• The set of regular expressions over an alphabet Σ is
Only the first components of M2’s states determine the defined recursively as below. Any element of that set is a
moves made by M2. regular expression.
Chapter 1  •  Finite Automata and Regular Languages  |  5.13

•• Basis clause: ∅, ∈, a are regular expression correspond- Example 16:  If r1 and r2 are regular expressions denoting
ing to languages ∅, {∈}, {a} respectively where a is an languages L1 and L2 respectively then which of following is
element of Σ. false?
•• Inductive clause: If r and s are regular expression corre- (A) (r1)| (r2) is regular expression denoting L1 ∪ L2.
sponding to languages Lr and Ls then (r + s), (rs) and (r*) (B) (r1) (r2) is regular expression denoting L1 . L2.
are regular expressions corresponding to the languages (C) ∅ is not a regular expression.
Lr ∪ Ls, Lr . Ls and Lr*respectively. (D) {r1}* is regular expression denoting L1*.
•• External clause: Nothing is a regular expression, unless it
Solution:  (C)
is obtained from above two clauses.
Closure property of regular expressions  The iteration or
closure of a regular expression R, written as R* is also a
regular expression.
Constructing FA for Given RE
Ex: ∑ = {a} then a* denotes the closure of ∑. •• Relationship between FA and RE.
a* = {e, a, aa, aaa, …}
Conventions on regular expressions
Regular NFA with NFA Minimal
1. The operation ‘*’ has highest precedence over concat- DFA
exp e-moves without e DFA
enation, which has precedence over union (+).
i.e., RE (a + (b(c*))) = a + bc* Identities:
2. The concatenation of K r’s, where r is a regular expres- Basis:
sion is written as rk. The language corresponding to rk
r=ε q1 ; // Initial state = Final state
is Lrk. Where Lr is language corresponding to regular
expression r i.e., rr = r2
3. r+ is a regular expression to represent Lr+ r = ∅⇒ q0 qf ; // Unreachable state
Note: A regular expression is not unique for a language
i.e., regular language corresponds to more than one regular a
r=a⇒ q0 qf
expression.
Example 15: Give regular expression for set of strings
Induction:
which either have ‘a’ followed by some b’s or all b’s also
containing ‘ε’. •• Union: L(r) = L (r1) + L (r2) i.e., L (M) = L (M1) ∪ L (M2)
(A) b* + ab* (B) a* + ba* Let M1 = (Q1, Σ1, δ1, q1, {f1}), M2 = (Q2, Σ2, δ2, q2, {f2}) with
(C) (ε) + (ε + a) b (D)
+
b* + ab* + ε L (M1) = L (r1) and L (M2) = L (r2), then M = (Q1 ∪ Q2 ∪ {q0,
f0}, Σ1 ∪ Σ2, δ, q0, {f0})
Solution:  (C)
The regular expression is, r = ab+ + b+ + ε = b+ (a + ε) + ε.
ε q 1 M1 f1 ε
Identity rules for regular expressions:
 1. ∅ + R = R q0 f0
 2. ∅ . R = R∅ = ∅ ε q 2 M 2 f2 ε
 3. εR = Rε = R
 4. ∅* = ε and ε* = ε •• Concatenation:
 5. R + R = R L(r) = L (r1) . L (r2) i.e., L (M) = L (M1) . L (M2)
 6. RR* = R* R = R+
 7. ε + RR* = R* and ε + R* R = R* q1 M1 f 1 ε q2 M 2 f2
 8. (R*)* = R*
 9. R* R* = R*
10. ε + R* = R* •• Closure:
11. (R + ε)* = R* L(r) = L(r)* i.e., L (M) = L (M1)*
12. R*(ε + R)* = (ε + R)* R* = R* Let M1 = (Q1, Σ1, δ1, q1, {f1}) then L (M) = (Q1 ∪ {q0, f0}, Σ1,
13. R* R + R = R* R δ, q0, {f0})
14. (P + Q)R = PQ + QR and R(P + Q) = RP + RQ
15. (P + Q)* = (P* Q*)* = (P* + Q*)* ε
16. (PQ)* P = P (QP)* ε ε
q0 q1 M 1 f 1 f0
17. R is given as, R = Q + RP has unique solution, R = QP*.
This is Arden’s theorem.
18. (P + Q)* = (P* + Q) = (P + Q*) ε
5.14 | Unit 5  •  Theory of Computation

Example 17: The regular expression generated by the (A) Regular


given FA. (B) Not regular
a (C) Cannot be determined
a
(D) None of these
q0 q1
b b
Solution:  (A)
Fix pumping length, K = 2
a
q2 q3 For every proper strings in L, (2n ≥ 2)
b
abbba . . . abb/bbaba . . . aaa
b
n n
(A) (a + ba*) b* (B) (aa*b + bb*) b*
(C) (b + ab*) a* (D) (ab + ba)* •• Split in x, y, z with desired properties.
Solution:  (B) z
y
q2 is final state which is obtained with input symbol only
abbba . . . abb|bbaba . . . aaa
‘b’. So, (C) or (D) is not true.
In (A) → ba* is not defined in given FA. Instead bb* is n n
defined. •• Let x = ε, y = first two symbols, z = rest.
y y
Pumping Lemma for Regular Sets ababbba . . . ab|bbbbaba . . . aaa → xy 2 z ∈L
Theorem  Let ‘L’ be an arbitrary regular language. Then Z
there exists a positive integer, P with following property: n+1 n+1
Given an arbitrary member, w of L having length at least •• xy3z:
P (i.e., |w|≥P), w can be divided into 3-parts, w = xyz ∃ y y y

•• |y| ≥ 1 (the middle part is non-empty) abababbba . . . a|bbbbbaba . . . aaa∈L


•• |xy| ≤ P (the first two parts have length atmost P) n+2 z n+2
•• For each, i ≥ 0, xyiz ∈ L (removing or repeating the middle
part produces member of L) •• xy z →
o

Proof  Let L be an arbitrary regular language. Then there is z


a FA, say M that decides L. bba . . . abb|aba . . . aaa∈L
Let P be the number of states of M.
n−1 n−1
Let w be an arbitrary member of L, having length ‘n’ with
n ≥ P. ∴ For every i ≥ 0, xy z ∈ L. Hence given language is regular.
i

Let q0, q1, … qn be states that M on input w. That is, for each
i, after reading the first i symbols of w, M is at qi. Closure Properties of
q0 is initial state of M. Also, since w ∈ L, qn is a final state Regular Sets
of M.
1. Union: If L and M are regular languages, LUM is reg-
Let x = w1 … wc, y = wc+4 … wd, z = wd+1 … wn. Then:
ular language closed under union.
•• |y| ≥ 1 2. Concatenation and Kleen closure: If L and M are
•• |xy| ≤ P regular languages, L.M is regular language and L* is
•• M transitions from q0 to qc on x. also regular.
•• M transitions from qc to qc on y. 3. Intersection: L ∩ M is regular, if L and M are regular
•• M transitions from qc to qn on z. languages.
4. Difference: L – M contains strings in ‘L’ but not M,
Thus, for every i ≥ 0, M transitions from q0 to qn on xyiz and
where L and M are regular languages.
so, xyiz is a member of L.
5. Complementation: The complement of language L is
Note: Σ*–L.
•• Pumping lemma is used to verify that given language is Note: Since Σ* is surely regular, the complement of a reg-
not regular. ular language is always regular. Where Σ* is a universal
•• Pumping lemma follows pigeon hole principle. language.
Example 18:  The language, L is defined as: 6. Homomorphism: If L is a regular language, h is
L = {w1w2 : w1, w2 ∈ {a, b}*, |w1| = |w2|}. Is the language homomorphism on its alphabet then h (L) = {h (w) |w
regular? is in L} is also a regular language.
Chapter 1  •  Finite Automata and Regular Languages  |  5.15

Regular grammar Type 1: Context-sensitive Grammar: (Linear bounded


•• Grammar: Generative description of a language. automaton) (LBA):
•• Automaton: Analytical description. Every production rule is of form, α→ β are in (V ∪ T)*
•• A grammar is a 4-tuple, G = (V, Σ, R, S) where V: alpha- and α ≠ ε and |β|≥|α| i.e., any strings of terminals and non-
bet (variable) (non-terminals) terminals and length of string that can appear on RHS of
production must be greater than or equal to length of string
Σ ⊆ V is set of terminal symbols.
that can appear on LHS of production.
R ⊆ (V+ × V*) is a finite set of production rules.
S ∈ V – Σ is start symbol. Type 2: Context-free grammar: (Push down automaton)
(PDA):
Notation Every production rule is of form, A→α where α is in
•• Elements of V – Σ: A, B, … (V ∪ T)* i.e., LHS of rule is single non-terminal and RHS
•• Elements of Σ: a, b … can be any string of terminals and non-terminals.
•• Rules (α , β ) ∈ R : α → β or α G
→β
Type 3: Regular grammar: (Finite automaton) (FA):
•• Start symbol is written as S.
Every production is of form, A→aB or A→a where A
•• Empty word: ε
and B ∈ V and a ∈ T. That is, LHS of rule is non-termi-
Example 19: The regular expression that describe the nal and RHS can be terminal (or) terminal followed by
language generated by grammar, G = ({S, A, B}, {a, b}, S, non-terminal.
{S → Aab, A → Aab|B, B → a}
Relationship between types of grammar:
(A) (ab) * a (B) aab(ab)*
(C) ab * aa (D) (a + ba)*
Type – 0
Solution:  (B)
S → Aab → Aab ab → A ab abab → Bababab Type – 1
→ aababab → aab(ab)* Type – 2
Union of two Regular languages:
If L1 and L2 are two languages then Type – 3
L1 ∪ L2 = {w/w ∈ L1 or w ∈ L2}
The union of two regular languages is also a regular language.
Let M1 = (Q1, ∑, d1, q1, f1)
M2 = (Q2, ∑, d2, q2, f2)
M = M1UM2 can be given as
M = (Q, ∑, d, q0, f). •• Regular sets are properly contained in CFL (Context Free
Where Q = {(r1, r2) | r1 ∈ Q1 and r2 ∈ Q2} Languages).
i.e., Q is the Cartesian product of sets Q1 and Q2. •• The CFL’s not containing empty string ε, are properly
∑ is the alphabet, is the same in M1 and M2. contained in CSL. (Context sensitive language).
∑ = ∑1 U ∑2. •• The CSL’s are properly contained in Recursively enumer-
d is the transition function given as: able languages.
d (r1, r2), a = (d1(r1, a) d2 (r2, a)). •• RG ⊂ CFG ⊂ CSL ⊂ REG
q0 is the pair (q1, q2).
F is the set of pairs in which either member is an accept Left-linear Grammar:
state of M1 or M2. All productions have form: A → Bx or A → x
F = {(r1, r2) | r1 ∈ F1 or r2 ∈ F2} Right-linear Grammar:
All productions have the form: A → xB or A → x.
Note:
Types of Grammars
•• The regular grammars characterize the regular sets i.e., a
•• Type 0: Unrestricted, recursively enumerable languages. language is regular if and only if it has a left-linear gram-
•• Type 1: Context-sensitive grammar. mar or if and only if it has a right-linear grammar.
•• Type 2: Context free grammar. •• If L has a regular grammar, then L is a regular set.
•• Type 3: Regular grammar. •• If L is a regular set, then L is generated by some left-linear
Type 0: Recursively enumerable grammar: (Turing grammar and by some right-linear grammar.
Machine) (TM): Arden’s theorem: Let P and Q be two regular expressions
Every production rule is of form: α → β, where α and β over ∑. If P does not contain ‘e’ then the following equation
are in (V ∪ T)*, i.e., there can be any strings of terminals and in R, namely R = Q + RP has a unique solution given by
non-terminals (no-restriction). R = QP*.
5.16 | Unit 5  •  Theory of Computation

Arden’s Theorem to obtain regular expression from (D) A→0A|1B|ε


given transition diagram: The following steps are used to B→1C
find the RE recognized by transition system. C→0A
The following assumptions are made regarding the tran-
sition system. Solution:  (A)
A→0B, A→1C, B→1A, C→0A
(i) The transition graph does not have e-moves
∴ A is final state, A → ε
(ii) It has only one initial state, qo.
(iii) The states in the transition diagram are qo, q1, q2, … qn.
∴ A → 0B|1C|ε A → 0B|1C
(iv) Qi, the regular expression represents the set of
B →1A (or) B → 1A|1
strings accepted by a system even though qi is the
final state. C → 0A C → 0A|0
(v) aij denotes the regular expression representing the set
of labels of edges from qi to qj. When there is no such Construction of FA from given regular grammar
edge aij = f.
Given a regular grammar, G; a regular expression specify-
We will get the following set of equations. ing L(G) can be obtained directly as follows:
Q1 = Q1 α11 + Q2 α12 + … Qn αn1 + e
•• Replace the ‘→’ symbol in productions of grammar by
Q2 = Q1 α12 + Q2 α22 + … Qn αn2
‘=’ symbol, to get set of equations.
:
•• Solve the set of equations obtained above to get the value
:
of variable, S, where S is start symbol of grammar, result
:
is regular expression specifying L(G).
Qn = Q1 α1n + Q2 α2n + … Qn αnn.
By Repeatedly applying substitutions and Arden’s theorem, Example 21: The Regular grammar and FA for given
we can express Qi in terms of αij’s. regular expression f*1*U (0f)* is ___
For getting the set of strings recognized by the transition
(A) S→0S|1S|0
system, we have to take the union of all Qi’s corresponding
T→1T|ε
to final states.
0, 1 1
Construction of Regular Grammar from FA 0
S T
Step I: Associate suitable variables like A, B, C … with
states of automata.
Step II: Obtain the productions of the grammar as: (B) S→1S|ε
If δ(A, a) = B then add production A → aB to list of
1
productions of grammar, if B is a final state, then
add either A → a or B → ε, to list of productions S
of grammar.
Step III: The variable associated with initial state of autom- (C) S→0T|1S|ε
ata is start symbol of grammar. T→0T|1U|ε
Example 20:  Regular grammar generating language accepted U→0T|1S
by below automata is
0 1
0 1
A B
1 0
S T U
1 0
C 0

1
(A) A→0B|1C|ε
B→1A (D) Cannot be determined
C→0A
(B) A→1B|0C|ε Solution:  (B)
B→1A ∅* 1* ∪ (0∅)* = ∅* . 1* ∪ ∅* = ε . 1* ∪ ε = 1*.
C→0A
(C) A→B|C|ε 1
B→1 S
C→0
Chapter 1  •  Finite Automata and Regular Languages  |  5.17

Exercises
Practice Problems 1 of b’s. The grammar L(G) for language L is defined
Directions for questions 1 to 15:  Select the correct alterna- with productions as:
tive from the given choices. (A) S→aBa
B→ε|bB
1. Find a regular expression for (B) S→aB
L = {uvu: u, v ∈ {a, b}*, |u| = 2} B→a|bB
(A) (ab)*a(ab)* (C) S→aT|bS
(B) (aa)*ab(aa)* T→aT|bT|a|b
(C) aa(a + b)*bb + bb(a + b)*aa (D) S→B|aSa
(D)  aa(a + b)*aa + ab(a + b)* ab + ba (a + b)* ba + bb B→ε|bB
(a + b)*bb 9. If the regular set A is represented by A = ((01)*1*)*. And
2. Consider the regular expression, R = 10 + (0 + 11)0* 1. the regular set B is represented by B = (01 + 1)*, which
The minimum number of states in any DFA accepting of the following is true?
this regular expression is: (A) A⊂ B
(A) 5 (B) 4 (B) B⊂ A
(C) 3 (D) 6 (C) A=B
3. The following DFA accepts the set of all strings over (D) A and B are incomparable
{a, b} that 10. The language, L that is generated over Σ = {0, 1} for
a a regular expression L(r) = (0 + 10)* 1 (1 + 10)*
b
(A) Any string whose number of 1’s length is greater
q0 q1 than or equal to 3.
b (B) Any string that has no substring 110.
b
(C) Any string that has no substring 00 after first 11.
q3 q2
b (D) Any string that has only one occurrence of sub-
a a string 010.
11. The R.E L(r) = (a+b*) U ε. Is the grammar with produc-
(A) Contains number of b’s divisible by 3. tions generated over non-terminals {S, A} ambiguous?
(B) Contain number of a’s and b’s divisible by 3 (A) Yes (B) No
(C) Contain number of b’s congruent to 3 modulo 4. (C) Can’t be determined (D) None
(D) Contain any number of a’s and b’s
12. The number of states in the obtained Moore machine
4. Consider the grammar, S → SS/a. To get string of n
while converting the given mealy to Moore are:
terminals, the number of productions to be used is
(A) n2 (B) n a/0 b/0
(C) 2n+1 (D) 2n–1
q1 q3
5. The language L is defined as, L = {ai bj c2j| i ≥ 0, j ≥ 0}. b/0
a/0
Is this language L regular? q0 a/1 a/0 a/0
(A) Yes (B) No b/0 q2 q4
(C) Cant be determined (D) None of these
6. The language, L is defined by set of strings over {a, b}* b/1
b/1
in which number of a’s is a perfect cube. What is the
nature of language, L?
(A) Regular (B) Non-regular (A) 5 (B) 6
(C) Cant be determined (D) None of these (C) 4 (D) 7
7. The language, L is defined over Σ = {0 – 7}. The string
13. The language L is defined as L = {0i1j/i ≠ j} over {0,
include 7, 16, 43, 61, 223, … The language generated 1, 2}, A = {0i 1j/i≥0, j≥0} and B = {0i 1j/i = j}. For
is: language, L to be non-regular. What should be relation
(A) Alternate odd and even numbers between A, B, L?
(B) Octal representation of a number (A) B = (A ∪ L) c (B) B=A∪L
(C) Divisible by 7. (C) B = A ∩ L (D) B = Ac
(D) Octal representation of a number divisible by 7. 14. Which of following grammars are unambiguous?
8. The language L, is defined as set of strings that start and (A) S→(S) S|[S] S|ε (B) S→S(S)S|ε
end with equal number of a’s and contain any number (C) S→aS|Sa|a (D) S→a|Sa|bSS|Ssb|SbS
5.18 | Unit 5  •  Theory of Computation

15. What will be number of final states obtained in DFA for (A) 2 (B) 1
language L = {w/w contains at least two 0’s and atmost (C) 3 (D) 4
one 1} over Σ = {0, 1}.

a
Practice Problems 2
Directions for questions 1 to 15:  Select the correct alterna- a b b
1 2 3 4
tive from the given choices.
a b a
1. Which of the following Regular expression is equal to a
given regular expression: (b + aa* b) + (b + aa*b) (a + b 5 6
b a
ba* b)* (a + ba* b)
(A) Ab (b + baa*) (B) a*b (a + ba* b)
(C) a* b (a + ba* b)* (D) ab (b + aa*b)*
(A) 4 (B) 6
2. The following DFA accepts set of all strings over {a, b} (C) 2 (D) 3
that contain
6. The minimal DFA given below is defined for language,
b
L = {w ∈ {a, b}*} over Σ = {a, b}. The ‘L’ is:

q0 b q1 b q2
2
a a
a aa a a a

q3 b q4 b q5
1 a b 3 a, b
b

(A) Number of a’s even and number of b’s odd. b b


(B) Consecutive a’s and b’s 3
(C) Contain bbb as substring
(D) Number of a’s even and number of b’s divisible by
three. (A) Strings that contain equal number of a’s and b’s
3. The regular language L(r) for the given FSM is: that have adjacent characters same.
(B) Contains adjacent characters same
1
(C) No two adjacent characters are same
q1 q2 1 (D) Starts and ends with same character that have ad-
0 0
jacent character same.
0
0, 1 7. The regular grammar L(G) contains productions, P
q0 q3
for language, L = {w ∈{a, b}*/ there is at least one a}
1 0 are:
1
q4 q5 (A) S→aS|bS|a|aT
0
T→aT|bT|a|b
1 (B) S→aS|bS|ε
(A) It can start with zero followed by any number of (C) S→aBb|bB
1’s but no two consecutive 0’s. B→a|b
(B) It can start with 1, followed by any number of 0’s (D) S→bB
but no two consecutive 1’s. B→b|ε
(C) It is a combination of 0’s and 1’s but no two con- 8. The regular expression for a language is defined as
secutive 0’s or 1’s. ((a* b)* (bc*)*). The total number of final states obtained
(D) Both (A) and (B). in both NFA and DFA are respectively:
4. The language, L is defined as a set of non-palindromes (A) 4, 2 (B) 1, 3
over {a, b}. Is L regular? (C) 1, 5 (D) 2,3
(A) Yes (B) No 9. The language, L is defined as {w/w has n occurrences
(C) Cannot be determined (D) None of above of 0’s where n mod 5 is 3} over Σ = {0, 1}. The number
5. The DFA, for language, L over Σ = {a, b} is given of final states obtained in the DFA for L is:
below. What will be number of states in minimized (A) 4 (B) 5
DFA. (C) 1 (D) 2
Chapter 1  •  Finite Automata and Regular Languages  |  5.19

10. Which of the following is an equivalent DFA for the 12. The following NFA contains ε-moves with 5, transi-
following NFA? tions. If this NFA with ε-moves is converted to NFA
0, 1 without ε-moves, what will be total number of transi-
1 0, 1 tions in obtained NFA?
A B C
0 1 2
0 1 0 1 ε ε
q0 q1 q2
(A) 1 0
A B C D
0
1 (A) 5 (B) 4
0 (C) 6 (D) 3
0
1
13. The regular expression, r = (a + b)*. One more regular
(B) 1 0,1
A B C
expression which represents same regular expression
‘r’ is:
0 0 1 (A) a* + b* (B) a * . b*
(C) 1 0 (C) a (ba )
* * *
(D) (a + b)* (a + b)
A B C
14. The Regular grammar, L(G) is defined for L with
0 productions as S→Aab, A→Aab|aB, B→a. What is
0 1 1 Language generated by L(G)?
(D)
1 0 0
(A) Containing alternative a’s and b’s
A B C D (B) Containing alternative a’s and b’s, begins with an
1
‘a’ and ends with a ‘b’.
(C) ‘aa’ followed by at least one set of alternating ab’s.
11. A regular grammar over alphabet Σ = {a, b, c, d} whose
(D) Consecutive aa’s followed by ‘b’.
language, is set of strings that contain exactly two b’s is:
15. The number of final states in DFA after converting the
(A) S→aS|bS|cS|dA NFA given below is:
A→aA|bA|cA|dA|ε
a
(B) S→aS|cS|dS|bB
B→aB|cB|dB|bC, 1
C → aC|cC|dC|ε b a, b
(C) S→aS|bS|cS|dA
A→aA|bB|cC 2
B→b
C→c (A) 4 (B) 2
(D) None of above (C) 3 (D) 1

Previous Years’ Questions


1. Match the following NFAs with the regular expres- (A) P-2, Q-1, R-3, S- 4
sions they correspond to [2008] (B) P-1, Q-3, R-2, S- 4
P. 1 Q. 1 (C) P-1, Q-2, R-3, S- 4
(D) P-3, Q-2, R-1, S- 4
1 0
0 0 0 1 2. Which of the following are regular sets?
0 0
I. {anb2m | n ≥ 0, m ≥ 0}
II. {anbm | n = 2m}
III. {anbm | n ≠ m}
R.   1 S.   1
IV. {xcy | x, y ∈ {a, b}*} [2008]
0 0 (A) I and IV only (B) I and III only
0 1 1
1 0 1 (C) I only (D) IV only
3. Which one of the following languages over the alpha-
bet {0, 1} is described by the regular expression:
(0 + 1)*0(0 + 1)*0(0 + 1)*? [2009]
1.  ∈ + 0(01*1 + 00)*01* (A) The set of all strings containing the substring 00.
2.  ∈ + 0(10*1 + 00)*0 (B) The set of all strings containing atmost two 0’s.
3.  ∈ + 0(10*1 + 10)*1 (C) The set of all strings containing at least two 0’s.
4.  ∈ + 0(10*1 + 10)*10*
5.20 | Unit 5  •  Theory of Computation

(D) The set of all strings that begin and end with ei- (A)
n-1 (B) n
ther 0 or 1. (C)
n+1 (D) 2n-1
4. Which one of the following is FALSE? [2009] 10. Let P be a regular language and Q be a context-free
(A) There is a unique minimal DFA for every regular
language such that Q ⊆ P (For example let P be the
language.
language represented by the regular expression p*q*
(B) Every NFA can be converted to an equivalent and Q be {pnqn} n ∈ N}, Then which of the following
PDA.
is ALWAYS regular? [2011]
(C) Complement of every context-free language is
(A) P ∩ Q (B) P-Q
recursive.
(C) S* - P (D) S* - Q
(D) Every non-deterministic PDA can be converted
to an equivalent deterministic PDA. 11. A deterministic finite automaton (DFA) D with alpha-
bet S = {a, b} is given below.
5. Match all items in Group 1 with correct options from
those given in Group 2. [2009] a, b

p b q b
Group 1 Group 2 r

P. Regular expression 1. Syntax analysis


a a, b a a, b
Q. Pushdown automata 2. Code generation
R. Dataflow analysis 3. Lexical analysis s t

S. Register allocation 4. Code optimization


Which of the following finite state machines is a valid
(A) P–4, Q–1, R–2, S–3 (B) P–3, Q–1, R–4, S–2
minimal DFA which accepts the same language as D?
(C) P–3, Q–4, R–1, S–2 (D) P–2, Q–1, R–4, S–3
 [2011]
6. a, b
1 p b q b
r
1 0
0 0 a a
(A)
1 s

The above DFA accepts the set of all strings over {0, a, b
1} that [2009] a, b
(A) Begin either with 0 or 1
s
(B) End with 0 (B) b a, b
(C) End with 00 a, b
p q r
(D) Contain the substring 00. a

7. Let L = {w ∈ (0 + 1)* | w has even number of 1’s}, a, b a, b


i.e., L is the set of all bit strings with even number (C)
p a, b q b
of 1’s. Which one of the regular expressions below r
represents L? [2010]
(A) (0*10*1)* (B) 0*(10*10*)* b
b
(C) 0*(10*1*)*0* (D) 0*1(10*1)*10* p q

8. Consider the languages L1 = {0i1j | i ≠ j}. L2 = {0i1j | (D) a a


i = j}, L3 = {0i1j | i = 2j + 1}. L4 = {0i1j | i ≠ 2j}. Which
one of the following statements is true? [2010] s
(A) Only L2 is context free a, b
(B) Only L2 and L3 are context free
(C) Only L1 and L2 are context free 12. Given the language L = {ab, aa, baa}, which of the
(D) All are context free following strings are in L*? [2012]
9. Let w be any string of length n in {0, 1} . Let L be the
*
(1) abaabaaabaa     (2) aaaabaaaa
set of all substrings of w. What is the minimum num- (3) baaaaabaaaab     (4) baaaaabaa
ber of states in a non-deterministic finite automaton that (A) 1, 2 and 3 (B) 2, 3 and 4
accepts L? [2010] (C) 1, 2 and 4 (D) 1, 3 and 4
Chapter 1  •  Finite Automata and Regular Languages  |  5.21

13. What is the complement of the language accepted by (D)


the NFA shown below? 00 01 10 11 q
a ε 00 1 0
01 1
ε 10 0
11 0
Assume S = {a} and e is the empty string.[2012]
(A) ∅ (B) {e}
15. Consider the languages L1 = Φ and L2 = {a}. Which
(C) a* (D) {a, e}
one of the following represents L1 L2*UL1*? [2013]
14. Consider the set of strings on {0, 1} in which, every
(A) {∈} (B) Φ
substring of 3 symbols has atmost two zeros. For (C) a* (D) {∈, a}
example, 001110 and 011001 are in the language, but
16. Consider the DFA A given below
100010 are not. All strings of length less than 3 are
also in the language. A partially completed DFA that 1
accepts this language is shown below. 1

00 0 0
0

0 1
01
0 0, 1
ε 0 1 q 0, 1
Which of the following are FALSE?
1 1. Complement of L (A) is context-free.
0
1 10
2. L(A) = L ((11*0 + 0) (0 + 1)*0*1*)
1 3. For the language accepted by A, A is the minimal
11 DFA.
1 4. A accepts all strings over {0, 1} of length at
least 2.  [2013]
The missing arcs in the DFA are  [2012] (A) 1 and 3 only (B) 2 and 4 only
(C) 2 and 3 only (D) 3 and 4 only
(A)
17. Consider the finite automaton in the following figure.
00 01 10 11 q  [2014]
00 1 0
0, 1 1
01 1
1 0, 1 0, 1
10 0 q0 q1 q2 q3

11 0
What is the set of reachable states for the input string
(B)
0011?
00 01 10 11 q (A) {q0, q1, q2} (B) {q0, q1}
00 0 1 (C) {q0, q1, q2, q3} (D) {q3}
01 1
18. If L1 = {an|n ≥ 0} and L2 = {bn|n ≥ 0}, consider the
10 0
statements [2014]
11 0
.
(I) L1 L2 is a regular language
(C) (II) L1 . L2 = {an bn|n ≥ 0}
00 01 10 11 q
Which one of the following is CORRECT?
00 1 0
(A) Only (I) (B) Only (II)
01 1 (C) Both (I) and (II) (D) Neither (I) nor (II)
10 0
19. Let L1 = {w ∈ {0, 1}*| w has at least as many occurrences
11 0
of (110)’s as (011)’s}. Let L2 = {w ∈{0, 1}*|w has at least
5.22 | Unit 5  •  Theory of Computation

as many occurrences of (000)’s as (111)’s}. Which one X0 = 1 X1


of the following is TRUE? [2014] X1 = 0 X1 + 1 X2
(A) L1 is regular but not L2
X2 = 0 X1 + {λ}
(B) L2 is regular but not L1
(C) Both L1 and L2 are regular Which one of the following choices precisely repre-
(D) Neither L1 nor L2 are regular sents the strings in X0? [2015]
20. The length of the shortest string NOT in the language (A) 10(0* + (10)*)1
(over S = {a, b}) of the following regular expression (B) 10(0* + (10)*)*1
is _____. [2014] (C) 1(0 + 10)*1
(D) 10(0 + 10)*1 + 110(0 + 10)*1
a b (ba) a
* * * *

21. Let S be finite non-empty alphabet and let 2Σ be


* 26. Let L be the language represented by the regular
Σ*
the power set of S . Which one of the following is expression Σ* 0011 Σ* where Σ = {0, 1}. What is the
TRUE?[2014] minimum number of states in a DFA that recognizes
*
L (complement of L)? [2015]
(A) Both 2∑ and Σ∗ are countable (A) 4 (B) 5
*
(B) 2Σ is countable and S* is uncountable (C) 6 (D) 8
*
(C) 2Σ is uncountable and S* is countable 27. Which of the following languages is generated by the
* given grammar? [2016]
(D) Both 2∑ and Σ∗ are uncountable S →aS | bS | ε]
1. e + 0 (01* 1 + 00)* 01* (A) {an bm | n, m ≥ 0}
2. e + 0 (10* 1 + 00)* 0 (B) {w ∈ {a, b} * | w has equal number of a’s and
b’s}
3. e + 0 (10* 1 + 10)* 1
(C) {an | n ≥ 0 } U {bn |n ≥ 0 } U {anbn | n ≥ 0}
4. e + 0 (10* 1 + 10)* 10* (D) {a, b}*
(A) P − 2, Q − 1, R − 3, S − 4
28. Which of the following decision problems are unde-
(B) P − 1, Q − 3, R − 2, S − 4
(C) P − 1, Q − 2, R − 3, S − 4 cidable? [2016]
(D) P − 3, Q − 2, R − 1, S − 4 I. Given NFAs N1 and N2, is
L (N1) ∩ L (N2)= Φ?
22. Consider the DFAs M and N given above. The number
II. Given a CFG G = (N, ∑, P,S) and a string x ∈ ∑*,
of states in a minimal DFA that accepts the language
does x ∈ L(G)?
L(M) ∩ L(N) is _______ [2015]
III. Given CFGs G1 and G2, is
b a a b L(G1) = L(G2)?
a b
M: N:
IV Given a TM M, is L(M) = Φ?
b a (A) I and IV only
23. The number of states in the minimal deterministic finite (B) II and III only
automaton corresponding to the regular expression (C) III and IV only
(0 + 1)*(10) is ______ [2015] (D) II and IV only
24. Which of the following languages is/are regular? 29. Which one of the following regular expressions repre-
 [2015] sents the language: the set of all binary strings having
L1: {wxwR |w1 x ∈ {a, b}* and |w|, |x| > 0}, wR is the two consecutive 0’s and two consecutive 1s? [2016]
reverse of string w (A) (0+1)* 0011 (0+1)* + (0+1)* 1100 (0+1)*
(B) (0+1)* (00(0+1)*11 + 11 (0+1)*00) (0+1)*
L2: {anbm|m ≠ n and m, n ≥ 0}
(C) (0+1)* 00 (0+1)* + (0+1)* 11 (0+1)*
L3: {a pbqcr| p, q, r ≥ 0} (D) 00 (0+1)* 11 + 11 (0+1)* 00
(A) L1 and L3 only (B) L2 only 30. The number of states in the minimum sized DFA that
(C) L2 and L3 only (D) L3 only accepts the language defined by the regular expression
25. Consider the alphabet Σ = {0, 1}, the null/empty (0+1)* (0+1) (0+1)* is ______ . [2016]
string λ and the sets of strings X0, X1 and X2 gener-
ated by the corresponding non-terminals of a regular 3 1. Language L1 is defined by the grammar: S1→aS1b∈
grammar. X0, X1 and X2 are related as follows Language L2 is defined by the grammar: S2→abS2∈
Chapter 1  •  Finite Automata and Regular Languages  |  5.23

Consider the following statements: δ ∈ a b


P:L1 is regular →q0 {q2} (q1} {q0}
Q:L2 is regular q1 {q2} {q2} {q3}
Which one of the following is TRUE? [2016] q2 {q0} Ø Ø
(A) Both P and Q are true
q3 Ø Ø (q2}
(B) P is true and Q is false
(C) P is false and Q is true Then d̂ (q2, aba) is [2017]
(D) Both P and Q are false
(A) Ø (B) {q0, q1, q3}
32. Consider the following two statements: (C) {q0, q1, q2} (D) {q0, q2, q3}
I.  If all states of an NFA are accepting states then 36. Let N be an NFA with n states. Let k be the num-
the language accepted by the NFA is S*. ber of states of a minimal DFA which is equivalent
II. There exists a regular language A such that for all to N. Which one of the following is necessarily true?
languages B, A ∩ B is regular.  [2018]
Which one of the following is CORRECT? [2016] (A) k ≥ 2n (B) k≥n
(A) Only I is true (C) k ≤ n2 (D) k ≤ 2n
(B) Only II is true 37. Given a language L, define Li as follows:
(C) Both I and II are true L0 = {ε}
(D) Both I and II are false
Li = Li–1. L for all i > 0
33. Consider the language L given by the regular expres-
The order of a language L is defined as the smallest
sion (a + b)*b (a + b) over the alphabet {a, b}. The
k such that Lk = Lk+1. Consider the language L1 (over
smallest number of states needed in a deterministic
alphabet 0) accepted by the following automaton.
finite-state automaton (DFA) accepting L is ________.
 [2017] 0
34. The minimum possible number of states of a deter- 0
ministic finite automaton that accepts the regular lan- 0
guage L = {w1aw2| w1, w2 ∈ {a, b}*, |w1| = 2, |w2| ≥ 3}
is __________. [2017] The order of L1 is ______. [2018]
35. Let δ denote the transition function and d̂ denote
the extended transition function of the ∈-NFA whose
transition table is given below:

Answer Keys
Exercises
Practice Problems 1
1. D 2. B 3. C 4. D 5. B 6. B 7. D 8. D 9. C 10. C
11. A 12. D 13. C 14. A 15. A

Practice Problems 2
1. C 2. D 3. D 4. B 5. B 6. C 7. A 8. C 9. C 10. A
11. B 12. C 13. C 14. C 15. B

Previous Years’ Questions


1. C 2. A 3. C 4. D 5. B 6. C 7. B 8. D 9. C 10. C
11. A 12. C 13. B 14. D 15. A 16. D 17. A 18. A 19. A 20. C
21. C 22. 1 23. 3 24. A 25. C 26. B 27. D 28. C 29. B 30. 2
31. C 32. B 33. 4 34. 8 35. C 36. D 37. 2

You might also like