Professional Documents
Culture Documents
Finite Automata
and Regular Languages
LEARNING OBJECTIVES
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
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
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
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
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
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
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
(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
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
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
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
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
(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
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
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
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