Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
49 views60 pages

Finite Automata & Regular Expressions

Uploaded by

taetaechim02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views60 pages

Finite Automata & Regular Expressions

Uploaded by

taetaechim02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 60

UNIT- I

Finite Automata and Regular Expressions: Formal Languages and Regular expressions,
Deterministic and Non-Deterministic Finite Automata, Finite Automata with ε-moves,
Equivalence of NFA and DFA, Minimization of finite automata, Two-way finite automata,
Moore and Mealy machines, Applications of finite automata.

2 MARKS

1. What is meant by Computations?


Computation is executing an algorithm (i.e.) it involves taking some inputs and performing required
operation on it to produce an output.

Input x Function f Output y=f(x)

 Computation is the sequence of steps that can be performed by computer.


 The computer which performs computation is not actual computers they are “abstract machines”. It
can be defined mathematically.
2. Give example of abstract machines?
 Turing Machine (Powerful as real Computers)
 Finite Automata (Simple)
3. What is a formal language?
Language is a set of valid strings from some alphabet. The set may be empty, finite or infinite. L(M) is the
language defined by machine M and L(G) is the language defined by context free grammar. The two
notations for specifying formal languages are:
 Grammar or regular expression (Generative approach)
 Automaton (Recognition approach)
4. What is theory of computations?
The theory of computation is the branch that deals with how efficiently problems can be solved on a
model of computation, using an algorithm.
The field is divided into three major branches:
1. automata theory,
2. computability theory, and
3. computational complexity theory
5. What is Automata Theory?
 Automata theory is the study of abstract machines (or abstract 'mathematical' machines or systems)
and the computational problems that can be solved using these machines. These abstract machines
are called automata.
 Automata which means that something is doing something by itself. Automata theory is also closely
related to formal language theory, as the automata are often classified by the class of formal
languages they are able to recognize. An automaton can be a finite representation of a formal
language that may be an infinite set.
6. Why are switching circuits called as finite state systems?
A switching circuit consists of a finite number of gates, each of which can be in any one of the two
conditions 0 or 1. Although the voltages assume infinite set of values, the electronic circuitry is designed
so that the voltages corresponding to 0 or 1 are stable and all others adjust to these values. Thus control
unit of a computer is a finite state system.
7. What are the Operations on strings?
 Length of string
 Empty or null string
 Concatenation of string
 Reverse of a string
 Powers of an alphabet
 Substring
 Reversal
 Kleene Closure
8. Define alphabets in automata?
An alphabet is a finite, non-empty set no of symbols. It is denoted by Σ.
Example:
 Σ = {a, b}, an alphabet of 2 symbols a and b.
 Σ = {0, 1, 2} an alphabet of 3 symbols 0, 1, and 2.
9. Define strings with examples?
A String or Word is a finite sequence of symbols from Σ. The group of characters also referred as a String.
Example:
 a, b, and c are symbols and abcb is a string.
 If Σ = {a,b} then abab,aabbb,aaabb,…… are all strings over the alphabet Σ ={a,b}.
 0, 1, 11, 00, and 01101 are strings over {0, 1}.
10. What is substring with example?
Let x and y be strings over an alphabet Σ.
The string x is a substring of y if there exist strings w and z over Σ such that y = w x z.
 ε is a substring of every string.
 For every string x, x is a substring of x itself.
Example:
 ε, comput and computation are substrings of computation.
11. What is Reversal with example?
Let x be a string over an alphabet N.The reversal of the string x, denoted by x r, is a string such that
 if x is ε, then xr is ε.
 If a is in Σ, y is in Σ* and x = a y, then xr = yr a.
(automata)r =
= (utomata)r a
= (tomata)r ua
= (omata)r tua
= (mata)r otua
= (ata)r motua
= (ta)r amotua
= (a)r tamotua
= (ε)r atamotua
 = atamotua The set of strings created from any number (0 or 1 or …) of symbols in an alphabet Σ
is denoted by Σ*.
12. Explain the following a. Length of string b. Empty or null string?
a. Length of string
Let w is a string. Length of the string is |w|=> number of symbols composing the string.
Example:
1) If w=abcd then |w|=4
2) If x=01010110 the |x|=8
3) If y= 0101 the |y|=4
4) If |Є| = 0
b. Empty or null string
The string consisting of zero symbols. It is denoted by Є.
Example:
{Є}=0.
13. Define Concatenation of string and Reverse of a string?
Concatenation of string
Appending the strings (2) referred as concatenation of strings.
i.e w=a1,a2,….am
v=b1,b2,b3,……bn
then wv=a1,a2,….am b1,b2,…..bn
Example:
1. x=00 y=1
xy=001, yx=100
x=AL y=GOL
xy=ALGOL
2. Empty string is the identity element for concatenation operator. i.e
w Є= Єw=w
Reverse of a string
The reverse of a string is obtained by writing the symbols in reverse order.
Let w is the string
Reverse is wR
i.e w=a1,a2,……am
wR=am,……a2,a1
Example:
Let u=010111
uR=1101010
14. What is meant by Powers of an alphabet?
Let Σ be the alphabet
Σ * is the set of all strings over alphabet Σ.
Σ m denotes the set of all strings over alphabet Σ of length m.
Example:
Σ = {0, 1}
Σ0= {Є} empty string of length 0.
Σ1= {0, 1} is the set of all strings of length one over Σ = {0, 1}
Σ2= {00, 01, 10, 11} is the set of all strings of length two over Σ = {0, 1}.
15. Define Kleen Closure?
Let Σ be the alphabet
“ Kleen Closure”-> Σ* denotes the set of all strings (Σ) over the alphabet
Example:
If Σ ={a} the Σ*={ Є,a,aa,aaa,………}
If Σ ={0,1} the Σ*={ Є,0,1,00,10,10,………………..}
Σ0={ Є}
Σ1={a}
Σ2={aa}
Therefore Σ*= Σ0U Σ1U Σ2,……………..
16. Define a language.
An alphabet is a finite set of symbols. A language is a set of strings of symbols from someone alphabet.
e.g. If Σ = {0,1},then Σ*={ Є,0,1,01,11,10,111,………}
17. List the applications of Computations?
 Analysis of algorithms
 Complexity Theory
 Cryptography
 Compiler Design
 Circuit design
 Robotics
 Artificial Intelligence
 Knowledge Engineering
18. Define Finite Automata. (NOV’15)
 A finite automaton (FA) consists of a finite set of states and a set of transitions from state to state
that occur on input symbols chosen from an alphabet Σ.
 Each input symbol there is exactly one transition out of each state (possibly back to the state itself).
 One State, usually q0, is the initial state, in which the automaton starts.
 Some states are designated as final or accepting states.
19. How does an FA work?
 At the beginning,
 an FA is in the start state (initial state)
 its tape head points at the first cell
 For each move, FA
 reads the symbol under its tape head
 changes its state (according to the transition function) to the next state determined by the
symbol read from the tape and its current state
 move its tape head to the right one cell
20. Give the purpose of transition diagram? (APR 2014)
A directed graph, called a transition diagram, is associated with an FA as follows:
 The vertices of the graph correspond to the states of the FA.
 If there is a transition from state q to state p on input a, then there is an arc labeled a from state q to
state p in the transition diagram.
 The FA accepts a string x if the sequence of transitions corresponding to the symbols of x leads from
the start state to an accepting state.
21. What is Transition Table?
The transition table is the tabular representation of the transition function “delta (∂)” with the rows
denoting states and columns denoting input symbol.
22. Write the DFA Specifications? (APR 2014, NOV 2012)
Deterministic Finite Automata (DFA) is generally specified by a 5 tuples (Q, Σ, δ, q0, F)
where
1. Q is a finite set of states
2. Σ is a finite input alphabet
3. q0 in Q is the start state or initial state
4. F⊆Q is the set of final states
5. δ is the transition function mapping δ: QX ΣQ.(i.e.) δ(q,a) is a state for each state q and
input symbol a.
23. Explain Working of DFA?
1. Initialisation
 Reader (read head) should be over the leftmost symbol.
 Finite Control is in start state.
2. Single Step
 Reader moves to the next symbol to the right.
 Control enters a new state that (deterministically) depends on current state and current
symbol. There may be no desired next state, Machine will stop.
 The machine repeats this action.
3. No current symbol
 All Symbols have been read.
 If control is in final state, the input string is accepted.
 Otherwise, the input string is not accepted.
24. What are the Applications of DFA?
 Compiler Design
 Design of Lexical Analyser
 Text Editor
 Pattern Matching
 File searching Program
 Text Processing
25. Define NFA. (APR 2012, 2013)
Non-Deterministic Finite Automata (NFA) is generally specified by a 5 tuples (Q, Σ, δ, q0, F) where
1. Q is a finite set of states
2. Σ is a finite input alphabet
3. q0 in Q is the start state or initial state
4. F⊆Q is the set of final states
5. δ is the transition function mapping δ  Q x Σ* to 2 Q.
On receiving same inputs it goes to many states
 the machine can move without consuming any symbols and sometimes there are possible moves and
sometimes there are move then one possible moves.
 the state is only partially determined by the current state and i/p symbol.
26. What are the difference between NFA and DFA? (MAY’15, NOV’15 , NOV’17)

DFA NFA
i. For each and every state and for each and i. For each and every state and for each and every input
every input symbol there exists at most one symbol there exists more than one transition.
transition. ii. The transition mapping for NFA is Q × (Σ U {ε}) 2 Q.
ii. The transition mapping for DFA is Q×ΣQ. iii. The language accepted by NFA is denoted by L(M’).
iii. The language accepted by DFA is denoted iv. Epsilon transition is possible.
as L(M).
iv. Epsilon transition is not possible.

27. What are Transition Function and give their properties?


Changing from one state to another state on applying the inputs
Properties of Transition function:
1. δ (q, ε)=q
This means the state of the system can be changed only by an input symbol else remains in original
state.
2. For all strings w and input symbol a δ(q,aw)= δ(δ(q,a),w)
Similarly δ(q,wa)= δ(δ(q,w),a)
3. The transition function δ can be extended to δ or δ that operates on states and strings.
Basis: δ(q, ε)=q
Induction: δ (q,xa)= δ(δ(q,x),a)
28. Define finite automata with ε moves?
 The Non deterministic finite automaton with ε moves to be a quintuple (Q, Σ, δ, q0, F) with all
components as before, but δ, the transition function, maps δ: Q × (Σ U {ε})  2Q.
 The intention is that δ(q,a) will consists of all states p such that there is a transition labeled a from q
to p, where a is either ε or a symbol in Σ.
ε- closure (q)  denotes the set of all vertices P such that there is path from q to P labeled ε.

29. Define regular expressions? (NOV’14)


The languages accepted by finite automata are easily described by simple expressions called regular
expression.
Let Σ be an alphabet. The regular expression over Σ and the sets that they denote are defined
recursively as follows:
1. Ф is a regular expression and denotes the empty set.
2. ε is a regular expression and denotes the set { ε }.
3. For each a ϵ Σ, ‘a’ is a regular expression and denotes the set {a}.
4. If r and s are regular expressions denoting the languages R and S respectively then (r+s), (rs),
and (r)* are regular expressions that denotes the sets RUS, RS and R* respectively.
30. What is Kleene and positive closure?
 The Kleene closure of L, denoted L*, is the set
L* Li
 The positive closure of L, denoted L+, is the set
L+ Li
31. What are the Identities for Regular Expression?
1. Ф + R = R
2. ФR = R Ф = Ф
3. λR = R λ = R
4. λ* = λ and Ф* = λ
5. R + R = R
6. R* R* = R*
7. RR* = R*R
8. (R*)* = R*
9. λ+ RR* = R* = λ+R*R
10. (PQ)* P = P(QP)*
11. (P + Q)* = (P* Q*)* = (P* + Q*)*
12. (P + Q)R = PR + QR and R(P +Q ) = RP + RQ
32. Define two way finite automata (2DFA)? (APR 2012, NOV 2013)
 A finite automata is a control unit that reads a tape, moving one square right at each move.
 A two-way finite automaton is an extension of one- way finite automaton which has the ability to
allow the tape head to move left as well as right.
 Two-way finite automata accepts the input string if it moves the tape head, off the right end of the
tape at the same time, entering an accepting state.
 A two-way deterministic finite automata (2DFA) is a quintuple M= (Q, Σ, , q0, F)
Where  is a map from Q X Σ Q X {L, R}
33. Write the Formal Definition of 2DFA?
A two-way finite deterministic automata (2DFA) is a quintuple M= (Q, Σ,, q0, F)
Where
1. Q is a finite set (the states)
2. Σ is a finite set (the input alphabet)
3. q0 in Q is the start state or initial state
4. F⊆Q is the set of final states
5.  is a map from Q X Σ  Q X {L, R}
34. Define Instantaneous Description (ID) of 2DFA?
 Instantaneous Description of 2DFA describes the input string, current state, and current position of
input head.
 The relation ├ M on Id’s such that I1 ├ M I2 if and only if M can go from instantaneous description I1 to
I2 in one move.
 An ID of M is a string in Σ*Q Σ*. The ID wqx, where w and x are in Σ* and q is a state in Q, represent
the facts that
1. wx is the input string
2. q is the current state and
3. Input head is scanning the first symbol of x.
35. What is crossing sequences in 2DFA?
The list of states below each boundary between square is termed a crossing sequence.
36. What is meant by behavior of 2DFA?
In 2DFA consists of the input, the path followed by the head and the state each time the boundary
between two tape squares is crossed, with the assumption that the controls enters its new state prior to
moving the head.

37. Define Moore and mealy machine?


 In Moore machine the output depends upon the states.
 In Mealy machine the output depends on transition and current state.
38. Write the specifications of Moore machine?

A Moore machine is a 6 tuple (Q, Σ, Δ,  , λ ,q0),


Where
1. Q is a finite set of states
2. Σ is a finite input alphabet
3. Δ is the output alphabet
4. λ is the mapping from Q to Δ giving the output associated with each state
5. δ is the transition function
6. q0 in Q is the start state or initial state
In Moore machine where the output alphabet is {0, 1} and state “accepting“ if only if λ(q)=1.
39. Write the specifications of Mealy machine?

A Mealy machine is a 6 tuple M= (Q, ∑, Δ,  , λ ,q0),


Where
1. Q is a finite set of states
2. Σ is a finite input alphabet
3. Δ is the output alphabet
4. λ is the mapping from Q X ∑  Δ (i.e.) λ(q,a) gives the output associated with the
transition from state q on input a.
5. δ is the transition function
6. q0 in Q is the start state or initial state
40. State the difference between Mealy and Moore machine?
MEALY MACHINE MOORE MACHINE
i. For each and every transition there will be an i. For each and every state there will be an
output. output.
ii. An automaton in which the output depends on ii. An automaton in which the output depends
the state as well as on the input at any instant of on the states of the states of the machine is
time is called a Mealy machine. called Moore machine.
iii. The transition mapping is given by, λ:Q×ΣΔ iii. The transition mapping is given by, λ:QΔ
41. Give the applications of finite automata? (NOV 2012,NOV’14, NOV’17)
Lexical Analyzers
 Tokens of a programming language are regular sets.
 Example: ALGOL identifiers, which are upper-or lower-case letters followed by any sequence of
letters and digits with no limit on length, expressed as,
(letter)(letter + digit)*
where
 letter stands for A + B + …… + Z + a + b + …… + z and
 digit stands for 0 + 1 + ….. +9
Text Editors
 Certain text editor and similar programs permits substitution of string for any string matching given
regular expression.
 For example: the UNIX text editor allows a command such as
s /bbb*/b*
that substitutes a single blank for the first string of two or more blanks found in a given line.
Let “any” represents expression a1+a2+…..+an.
where ai are computer characters except “newline “character.
42. Define FORTRAN identifiers?
 FORTRAN identifiers, with length should limited of six and letters restricted to uppercase and
symbol $, may be expressed as
(letter)( + letter + digit)*
Where, letter stands for ($ + A + B +……. + Z)
43. Define the SNOBOL?
 SNOBOL arithmetic constants(do not permit the exponential notation) may be expressed as
( + -)(digit+ (.digit* + ) +.digit+)
 Lexical analyzers takes input as sequence of regular expressions describing the tokens and produce
a single finite automaton recognizing the any token.
 Usually Regular expression to NFA with  moves to NFA without  moves and to DFA.
44. Construct DFA that accepts input stings of 0’s and 1’s that end with 11.

0 0 1
Start
q0 q1
00 q2
00

The language accepted by this automaton is L = {11, 011, 01011, and 000111}
1. Machine will be in start state qo.
2. It will remain unchanged until it sees the input symbol ‘1’.
3. On getting ‘1’ goes to q1.
4. From q1, on input symbol ‘0’ goes to qo. From q1, one i/p symbol ’1’ goes to q2 (acceptance state).
5. From q2, any number of 1 is accepted and if any 0 comes it goes to start state.
45. Check whether given input string 0111 is accepted or not?
Transition table
Input
States
0 1
* q0 {q0} {q1}
q1 {q0} {q2}
q2 {q2} {q1}

M= ({q0, q1, q2}, {0, 1}, {q1}, δ)


Solution
Let M be the Machine. It consists of the following attributes or tuples.
M= (Q, Σ, δ, S, F)
Q= {q0, q1, q2}
Σ = {0, 1}
S=q0
F= {q0}
Transition Diagram

δ (q0, 0) = {q0}
δ (q0, 1) = {q1}
δ (q1, 1) = {q2}
δ (q2, 1) = {q1}
Here {q1} is the final state. Hence the given input string 0111 is accepted by DFA.
46. Define Equivalence Relation? (NOV 2013)
A relation R that is reflexive, symmetric, and transitive is said to be an equivalence relation. An
important property of an equivalence relation R on a set S is that R partitions S into disjoint non-empty
equivalence classes. That is S=S1 ∪ S2 ∪…, where for each i and j, with i≠j:
1. Si Sj=𝜑
2. For each a and b: n Si, aRb is true;
3. For each a in Si and b is Sj,aRb is false.
The Si’s are called equivalence classes.
47. What are the applications of automata theory?
1. In compiler construction.
2. In switching theory and design of digital circuits.
3. To verify the correctness of a program.
4. Design and analysis of complex software and hardware systems.
5. To design finite state machines such as Moore and mealy machines.
48. Construct NFA equivalent to the regular expression: (0+1)01. (APR 2015)

The NFA equivalent for the given Regular Expression is (0+1) 01


11 MARKS

1. Explain the Operations on strings or Formal Languages or Finite Automata or Automata Theory ?
(11 marks)
The operations on Strings are
i. Length of string
ii. Empty or null string
iii. Concatenation of string
iv. Reverse of a string
v. Powers of an alphabet
vi. Substring
vii. Reversal
viii. Kleene Closure

Alphabets:
An alphabet is a finite, non-empty set no of symbols. It is denoted by Σ.
Example:
 Σ = {a, b}, an alphabet of 2 symbols a and b.
 Σ = {0, 1, 2} an alphabet of 3 symbols 0, 1, and 2.

Strings:
A String or Word is a finite sequence of symbols from Σ. The group of characters also referred as a String.
Example:
 a, b, and c are symbols and abcb is a string.
 If Σ = {a,b} then abab,aabbb,aaabb,…… are all strings over the alphabet Σ ={a,b}.
 0, 1, 11, 00, and 01101 are strings over {0, 1}.

Substring:
Let x and y be strings over an alphabet Σ.
The string x is a substring of y if there exist strings w and z over Σ such that y = w x z.
 ε is a substring of every string.
 For every string x, x is a substring of x itself.
Example:
 ε, compute and computation are substrings of computation.

Reversal:
Let x be a string over an alphabet N.The reversal of the string x, denoted by x r, is a string such that
 if x is ε, then xr is ε.
 If a is in Σ, y is in Σ* and x = a y, then xr = yr a.
(automata)r =
= (utomata)r a
= (tomata)r ua
= (omata)r tua
= (mata)r otua
= (ata)r motua
= (ta)r amotua
= (a)r tamotua
= (ε)r atamotua
 = atamotua The set of strings created from any number (0 or 1 or …) of symbols in an alphabet Σ
is denoted by Σ*.

Length of string:
Let w is a string. Length of the string is |w|=> number of symbols composing the string.
Example:
1) If w=abcd then |w|=4
2) If x=01010110 the |x|=8
3) If y= 0101 the |y|=4
4) If |Є| = 0

Empty or null string:


The string consisting of zero symbols. It is denoted by Є.
Example:
{Є}=0.

Concatenation of string
Appending the strings (2) referred as concatenation of strings.
i.e w=a1,a2,….am
v=b1,b2,b3,……bn
then wv=a1,a2,….am b1,b2,…..bn

Example:
1. x=00 y=1
xy=001, yx=100
x=AL y=GOL
xy=ALGOL
Reverse of a string
The reverse of a string is obtained by writing the symbols in reverse order.
Let w is the string
Reverse is wR
i.e w=a1,a2,……am
wR=am,……a2,a1
Example:
Let u=010111
uR=1101010
Powers of an alphabet:
Let Σ be the alphabet
Σ * is the set of all strings over alphabet Σ.
Σ m denotes the set of all strings over alphabet Σ of length m.

Example:
 Σ = {0, 1}
 Σ0= {Є} empty string of length 0.
 Σ1= {0, 1} is the set of all strings of length one over Σ = {0, 1}
 Σ2= {00, 01, 10, 11} is the set of all strings of length two over Σ = {0, 1}.

Kleen Closure:
Let Σ be the alphabet
“ Kleen Closure”-> Σ* denotes the set of all strings (Σ) over the alphabet

Example:
If Σ ={a} the Σ*={ Є,a,aa,aaa,………}
If Σ ={0,1} the Σ*={ Є,0,1,00,10,10,………………..}
Σ0={ Є}
Σ1={a}
Σ2={aa}
Therefore Σ*= Σ0U Σ1U Σ2,……………..
2. Explain in detail Regular Expressions? (11 marks) (NOV 2013,MAY’15)
 The languages accepted by finite automata are easily described by simple expressions called regular
expressions.
 Let Σ be a finite set of symbols and let L, L1, and L2 be sets of strings from Σ*.
The operations of regular expressions are
1. Concatenation
2. Kleene closure
3. Positive closure
 The concatenation of L1 and L2, denoted L1L2, is the set {xy | x is in L1 and y is in L2}.That is, the
strings in L1L2 are formed by choosing a string L1 and following it by a string in L2.
 The Kleene closure of L, denoted L*, is the set
L* Li
L*={ €, a, aa, aaa, …..}

 The positive closure of L, denoted L+, is the set


L+ Li
L+ ={ a, aa, aaa, …..}
Let Σ be an alphabet. The regular expression over Σ and the sets that they denote are defined
recursively as follows:
1. Ф is a regular expression and denotes the empty set.
2. ε is a regular expression and denotes the set { ε }.
3. For each a ϵ Σ, ‘a’ is a regular expression and denotes the set {a}.
4. If r and s are regular expressions denoting the languages R and S respectively then (r+s), (rs),
and (r)* are regular expressions that denotes the sets RUS, RS and R* respectively.

Equivalence of finite automata and regular expressions:


The language accepted by finite automata are precisely the languages denoted by regular expressions.
This equivalence for calling finite automaton languages regular sets.

Regular Expression to NFA with €: or Prove that for every regular expression there is an equivalent
NFA: ( NOV 2013)
3. Explain Deterministic Finite Automata (DFA) with an example? (11 marks) (NOV 2013)
FINITE STATE SYSTEMS:
 Finite Automata is a mathematical model of a system that represents discrete number of inputs and
outputs.
 The system can be in any one of a finite number of internal configurations or states.
 The state of the system summarizes the information concerning past inputs that is needed to
determine the behavior of the system on subsequent inputs.
 The control mechanism of an elevator is a good example of a Finite State Machine (FSM).
 The commonly used programs such as text editors and the lexical analyzers found in most compilers
are often designed as finite state systems.
 For example, a lexical analyzer scans the symbols of a computer programs to locate the string of
characters corresponding to identifiers, numerical constants, reserved words etc.

FINITE AUTOMATA:
 A finite automaton (FA) consists of a finite set of states and a set of transitions from state to state that
occur on input symbols chosen from an alphabet Σ.
 DEFINITION:
M=( Q, Σ, δ,q,F)
Where Q= set of finite state
Σ= set of input alphabet
δ= transition function from Q* Σ -> Q
q0 = start state
F = set of final state
 Each input symbol there is exactly one transition out of each state (possibly back to the state itself).
 One State, usually q0, is the initial state, in which the automaton starts.
 Some states are designated as final or accepting 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.
Components ( Model )of Finite Automata:
1. Input tape: divided into number of cells. Each cell is capable of holding one cell.
2. Read Head: reads one cell at time and moves ahead
3. Finite Control: it acts like CPU. Depending on current state and input symbol read from tape, it
changes state.
How does an FA work?
 At the beginning,
 an FA is in the start state (initial state)
 its tape head points at the first cell
 For each move, FA
 reads the symbol under its tape head
 changes its state (according to the transition function) to the next state determined by
the symbol read from the tape and its current state
 move its tape head to the right one cell
Two way of representation of Finite Automata:
1. Transition diagram
2. Transition table
Transition diagram:
A directed graph, called a transition diagram, is associated with an FA as follows:
 The vertices of the graph correspond to the states of the FA.
 If there is a transition from state q to state p on input a, then there is an arc labeled a from state q to
state p in the transition diagram.
 The FA accepts a string x if the sequence of transitions corresponding to the symbols of x leads from
the start state to an accepting state.

Transition table:
It is the tabular listing of the transition function which by implication tells us set of states and an input
alphabet.
Input / State a b
q0 q1 q0
q1 - q2

The finite automata are of two types;


1. Deterministic Finite Automata (DFA)
2. Non-Deterministic Automata (NFA)
DETERMINISTIC FINITE AUTOMATA (DFA):
Deterministic Finite Automata (DFA) is generally specified by a 5 tuples (Q, Σ, δ, q0, F)
where
1. Q is a finite set of states
2. Σ is a finite input alphabet
3. q0 in Q is the start state or initial state
4. F⊆Q is the set of final states
5. δ is the transition function mapping δ: QX ΣQ.(i.e.) δ(q,a) is a state for each state q and
input symbol a. (i.e.) δ(q,a) is a state for each state q and input symbol a.
 An FA as finite control, which is in some state from Q, reading a sequence of symbols from Σ
written on tape.
0 1 1 0 0 1 0 1

Finite Control

A finite automaton as a machine can also be thought of as the device shown below consisting of a tape and a
control circuit which satisfy the following conditions:
1. The tape has the left end and extends to the right without an end.
2. The tape is divide into squares in each of which a symbol can be written prior to the start of the
operation of the automaton.
3. The tape has a read only head.
4. The head is always at the leftmost square at the beginning of the operation.
5. The head moves to the right one square every time it reads a symbol.
It never moves to the left. When it sees no symbol, it stops and the automaton terminates its
operation.
6. There is a finite control which determines the state of the automaton and also controls the
movement of the head.

 A string x is said to be accepted by a finite automaton M= (Q, Σ, δ, q0, F) if δ (q, x) =p for some p in F.
 The language accepted by M, designated L (M), is the set {x| δ (q0, x) is in F}.
 A language is a regular set if it’s the accepted by some finite automaton.
Example:
Consider the formal notation this FA is denoted M= (Q, Σ, δ, q0, F), where Q= {q0, q1, q2, q3}, Σ= {0, 1},
F= {q0} and δ is shown as

Transition Diagram:
Transition Table:

Inputs
States
0 1
* q0 q2 q1
q1 q3 q0
q2 q0 q3
q3 q1 q2

Check whether given input string 110101 are accepted or not.

Solution:
The given input string is 110101 to machine M. We denote that
δ (q0, 1) = {q1}
δ (q1, 1) = {q0}
δ (q0, 0) = {q2}
δ (q2, 1) = {q3}
δ (q3, 0) = {q1}
δ (q1, 1) = {q0}
Therefore q0 is the accepting or final state.
Hence the given input string 110101 is accepted by DFA.
4. Explain Non-Deterministic Finite Automata (NFA) with an example? (11 marks)(APR 2014)
 Consider modifying the finite automaton model to allow zero, one, or more transitions from a state
on the same input symbol. This new model is called a Non-Deterministic Finite Automata (NFA).
 Non-deterministic finite automaton is a useful concept in proving theorems.
 NFA plays a central role in both the theory of languages and the theory of computation.
 Any set accepted by a NFA can also accepted by a DFA.
NFA Mathematical Specification:
Non-Deterministic Finite Automata (NFA) is generally specified by a 5 tuples (Q, Σ, δ, q0, F) where
1. Q is a finite set of states
2. Σ is a finite input alphabet
3. q0 in Q is the start state or initial state
4. F⊆Q is the set of final states
5. δ is the transition function mapping δ  Q x Σ* to 2 Q.
On receiving same inputs it goes to many states
 The machine can move without consuming any symbols and sometimes there are possible moves
and sometimes there are move then one possible moves.
 The state is only partially determined by the current state and i/p symbol.
Examples:
Consider the given NFA to check whether the string is accepted or not W=01001.
Transition diagram:

Solution :
In Non-Deterministic Finite Automata (NFA), Consider a machine M= (Q, Σ, δ, q0, F),
where,
Q = {q0, q1, q2, q3, q4}
Σ = {0, 1}
{q0}=initial state
{q2, q4}=Final state
Transition table:
Input
States
0 1
 q0 {q0,q3} {q0,q1}
q1 Ф {q2}
* q2 {q2} {q2}
q3 {q4} Ф
* q4 {q4} {q4}

Method1:
The given input string is 01001

δ (q0, 0) = {q0, q3}

δ (q0, 01) = δ (δ (q0, 0), 1)


= δ ({q0, q3}, 1)
= δ (q0, 1) U δ (q3, 1)
= {q0, q1} U {Ф}
= {q0, q1}
δ (q0, 010) = δ (δ (q0, 01), 0)
= δ ({q0, q1}, 0)
= δ (q0, 0) U δ (q1, 0)
= {q0, q3} U {Φ}
= {q0, q3}
δ (q0, 0100) = δ (δ (q0, 010), 0)
= δ ({q0, q3}, 0)
= δ (q0, 0) U δ (q3, 0)
= {q0, q3} U {q4}
= {q0, q3, q4}
δ (q0, 01001) = δ (δ (q0, 0100), 1)
= δ ({q0, q3, q4}, 1)
= δ (q0, 1) U δ (q3, 1) U δ (q4, 1)
= {q0, q1} U {Φ} U {q4}
= {q0, q1, q4}
The given input string 010001 is accepted by machine. Therefore q4 is the final state or accepting state.
5. Explain about Finite Automata with Epsilon (ε ) – moves with an example? (11 marks)
 In our model of the non-deterministic finite automaton to include transitions on the empty input ε.
 The transition diagram for NFA accepting the language consisting of any number (including zero) of
0’s followed by any number of 1’s followed by any number of 2’s.
 NFA with ε move is defined as
(Q, Σ, δ, q0, F) where
 Q is a finite set of states
 Σ is a finite input alphabet
 q0 in Q is the start state or initial state
 F⊆Q is the set of final states
 δ is the transition function mapping δ  Q x Σ U Σ to 2 Q.
 An NFA accepts a string ω if there is some path labeled ω from the initial state to a final state.
 The edges labeled ε may be included in the path, although the ε’s do not appear explicitly in ω.
1. EPSILON CLOSURE
2. EXTENDED TRANSITION FUNCTION
3. LANGUAGE ACCEPTED BY NFA WITH ε MOVE
4. ELIMINATING ε TRANSITIONS
5. EQUIVALANCE OF NFA WITH ε MOVES TO DFA
6. Construct a DFA equivalent to NFA, where M = ({q0, q1, q2}, {0, 1, 2}, δ, q0, {q0, q1, q2}).
The Transition is given by the transition diagram and transition table. (11 marks)
Transition Table:

Inputs
States
0 1 2
* q0 {q0,q1,q2} {q1,q2} {q2}
* q1 {φ} {q1,q2} {q2}
* q2 {φ} {φ} {q2}

Transition Diagram:

CONSTRUCTING DFA:
Solution:
The equivalent DFA is M’ = (Q, {0, 1, 2}, δ’, S’, F’)
Q = {q0, q1, q2}
∑ = {0, 1, 2}
Q' = 2Q
S’= [q0] Є Q’

All subsets = { [φ],[q0],[q1],[q2],[q0,q1,q2],[q0q1],[q0q2],[q1q2][q0q1q2]}

Transition Function:

δ'(q0,0) = [q0q1q2]
δ'(q0,1) = [q1q2]
δ'(q0,2) = [q2]
δ'(q1,0) = [φ]
δ'(q1,1) = [q1q2]
δ'(q1,2) = [q2]
δ'(q2,0) = [φ]
δ'(q2,1) = [φ]
δ'(q2,2) = [q2]
δ'(q0q1,0) = δ'(q0,0) U δ'(q1,0)
= [q0, q1, q2] U {φ}
= [q0, q1, q2]
δ'(q0q1,1) = δ'(q0,1) U δ'(q1,1)
= [1q2] U [q1q2]
= [q1, q2]
δ'(q0q1,2) = δ'(q0,2) U δ'(q1,2)
= [q2] U [q2]
= [q2]
δ'(q0q2,0) = δ'(q0,0) U δ'(q2,0)
= [q0q1q2] U {φ}
= [q0q1q2]
δ'(q0q2,1) = δ'(q0,1) U δ'(q2,1)
= [q1q2] U {φ}
= [q1q2]
δ'(q0q2,2) = δ'(q0,2) U δ'(q2,2)
= [q2] U [q2]
= [q2]
δ'(q1q2,0) = δ'(q1,0) U δ'(q2,0)
= {φ} U {φ}
= [φ]
δ'(q1q2,1) = δ'(q1,1) U δ'(q2,1)
= [q1q2] U {φ}
= [q1q2]
δ'(q1q2,2) = δ'(q1,2) U δ'(q2,2)
= [q2] U [q2]
= [q2]
δ'(q0q1q2,0) = δ'(q0,0) U δ'(q1,0) U δ' (q2,0)
= {q0q1q2} U {φ} U {φ}
= [q0q1q2]
δ (q0q1q2,1) = δ'(q0,1) U δ'(q1,1) U δ' (q2,1)
= [q1q2] U [q1q2] U {φ}
= [q1q2]
δ'(q0q1q2,2) = δ'(q0,2) U δ'(q1,2) U δ' (q2,2)
= [q2] U [q2] U [q2]
= [q2]
Transition Table for DFA:

Inputs
States
0 1 2
[q0] [q0q1q2] [q1q2] [q2]
[q1] φ [q1q2] [q2]
[q2] φ φ [q2]
[q0q1] [q0q1q2] [q1q2] [q2]
[q0q2] [q0q1q2] [q1q2] [q2]
[q1q2] φ [q1q2] [q2]
[q0q1q2] [q0q1q2] [q1q2] [q2]

Final States are {[q2], [q1q2], and [q0q1q2]}


Transition Diagram:

q1q2

q0q1q2
q0 q2

q1

q0q1q2 q0q2 q0q1q2


q1q2
q1q2

7. Explain the Equivalence of NFA and DFA


8. Explain Minimization of Finite Automata with an example? (11 marks)
DFA minimization is the task of transforming a given Deterministic Finite Automaton (DFA) into an
equivalent DFA that has a minimum number of states. Here, two DFAs are called equivalent if they
recognize the same regular language. Several different algorithms accomplishing this task are known
and described in standard textbooks on automata theory.
A DFA can recognize a unit language. It is possible to construct a new DFA where it contains only
minimal number of states. The central idea in minimizing the DFA, partition the states into blocks such
that all the states in the block are equivalent. No two states chosen from two different blocks are
equivalent.
Property of Equivalent States:
A= (Q, Σ, δ, q0, F)
Equivalent states are transitive
P&Q equivalent A&Bequivalent
Q&Requivalent B&Cequivalent
(P&R equivalent i.e. PR) (A&B equivalent i.e. AB)
Partitioning:
 Split Q into two parts or sets, the first set containing the final state and the second set containing the
non-final state.
If we create for each state
1. q [DFA], a block consisting of q, then the different blocks of stated form a partition of set of states.
2. Each state is in exactly one block.
Example:
Construct a minimized DFA from the equivalent the given DFA.

Given
Let Q = {1, 2, 3, 4, 5}
Σ = {a, b}
S = {1}
F = {3}

Split Q into two parts or sets, the first set containing the final state and the second set containing the non-
final state.

Let A = {3}
B = {1, 2, 4, 5}
Then the list containing non-final state and according to the output of each transition, gives the set
representation.
Then consider the set with a larger number of states
A = {3}
B = {1,4} equivalent
C = {2,5} non-equivalent

Transition for A

Transition for B

Transition for C

Transition Table:

STATES INPUTS

a b

A C A

B C B

C B A

Transition Diagram:
9. Explain two – way finite automata with an example? (11 marks) (APR 2012)
 A finite automaton is a control unit that reads a tape, moving one square right at each move. Two
way finite automatons is an extension of one- way finite automaton which has the ability to allow the
tape head to move left as well as right. Such a finite automaton is called a two-way finite automaton.
 Two ways finite automaton accepts the input state if it moves the tape head, off the right end of the
tape, at the same time, entering an accepting state.
 A two-way finite deterministic automaton (2DFA) is a quintuple M= (Q, Σ, δ, q0, F)
Where
1. Q is a finite set (the states)
2. Σ is a finite set (the input alphabet)
3. q0 in Q is the start state or initial state
4. F⊆Q is the set of final states
5.  is a map from Q X Σ  Q X {L, R}.

 If δ(q,a)=(p,L), then in state q, scanning input symbol a, the 2DFA enters state p and moves its head
left one square.
 If δ(q,a)=(p,R), then in state q, scanning input symbol a, the 2DFA enters state p and moves its head
right one square.

Instantaneous Description (ID):


 Instantaneous Description of 2DFA, which describes
 the input string,
 current state, and
 current position of input head
 The relation ├ M on ID’s such that I1 ├ M I2 if and only if M can go from instantaneous description I1 to
I2 in one move.
 An ID of M is a string in Σ*Q Σ*. The ID wqx, where w and x are in Σ* and q is a state in Q, represent
the facts that
1. wx is the input string
2. q is the current state and
3. the input head is scanning the first symbol of x.
If x= ε, the input head has moved off the right end of the input.

Example:
Consider 2DFA as follows M=({q0,q1,q2},{0,1},,q0,{q0,q1,q2}).Show that the string w=101001 is
accepted or not. The transition table is given by

Inputs
States
0 1
q0 {q0,R} {q1,R}
q1 {q1,R} {q2,L}
q2 {q0,R} {q2,L}

Solution:

q0101001 ├ 1 q1 01001

├ 10 q1 1001

├ 1 q2 01001

├ 1 0 q0 1001

├ 101 q1 001

├ 1010 q1 01

├ 1010 0 q1 1

├ 1010 q2 01

├ 1010 0 q0 1

├ 1010 01 q1

Here q1 is final state. So the given input string 01001 is accepted.

Crossing Sequences:
In 2DFA consists of the input, the path followed by the head and the state each time the boundary
between two tape squares is crossed, with the assumption that the controls enters its new state prior to
moving the head.
The list of states below each boundary between square is termed a crossing sequence. If a 2DFA
accepts its input, no crossing sequence may have a repeated state with the head moving in the same
direction, otherwise the 2DFA being deterministic, would be in a loop and thus could never fall off the right
end.
In crossing sequences is that the first time a boundary is crossed, the head must be moving right.
Subsequent crossings must be in alternate directions. Thus odd-numbered elements of a crossing sequence
represent right moves and even-numbered elements represent left moves. If the input is accepted, it follows
that all crossing sequences are of odd length.
A crossing sequence q1, q2… qk is said to be valid if it’s of odd length, and no two odd and no two
even-numbered elements are identical. A 2DFA with s states can have valid crossing sequence of length at
most 2s, so the number of valid crossing sequence is finite.

10. Explain Moore and Mealy machines with an example? (11 marks) (NOV 2012,MAY’15)
The finite automaton defined that its output is limited to a binary signal: “accept/don’t accept”. There
are two different approaches are
1. Moore Machine
2. Mealy Machine
MOORE MACHINE:
 Moore Machines was developed by E.F.Moore in the year 1956.
 In Moore machine the output depends upon the states.
 It can be represented by transition tables and transition diagram.
A Moore machine is a 6 tuple (Q, Σ, Δ,  , λ ,q0),
Where
1. Q is a finite set of states
2. Σ is a finite input alphabet
3. Δ is the output alphabet
4. λ is the mapping from Q to Δ giving the output associated with each state
5. δ is the transition function
6. q0 in Q is the start state or initial state
 The output of M in response to input a1 a2… an, n≥0, is λ(q0) λ(q1).. λ(qn) where q0,q1, … qn is the
sequence of states such that δ(qi-1,ai)=qi for 1 ≤ i ≤n.
 Any Moore machine gives output λ(q0) in response to input n.
 The DFA as a special case of a Moore machine where the output alphabet is {0, 1} and state
“accepting “ if only if λ(q)=1.
 In a Mealy machine, the outputs are a function of the present state and the value of the inputs as shown
in Figure 1.
 Accordingly, the outputs may change asynchronously in response to any change in the inputs.

Figure 1: Mealy Type Machine


 In a Moore machine the outputs depend only on the present state as shown in Figure 2.
 A combinational logic block maps the inputs and the current state into the necessary flip-flop inputs to
store the appropriate next state just like Mealy machine.
 However, the outputs are computed by a combinational logic block whose inputs are only the flip-flops
state outputs.
 The outputs change synchronously with the state transition triggered by the active clock edge.

Figure 2: Moore Type Machine


MEALY MACHINE:
 Mealy Machine was developed by G.H.Mealy.
 In Mealy machine the output depends on transition and current state.
 The output is fixed for particular input symbols.
 It can be represented by transition tables and transition diagram.
A Mealy machine is a 6 tuple M= (Q, ∑, Δ,  , λ ,q0),
where
1. Q is a finite set of states
2. Σ is a finite input alphabet
3. Δ is the output alphabet
4. λ is the mapping from Q X ∑ to Δ (i.e.) λ(q,a) gives the output associated with the
transition from state q on input a.
5. δ is the transition function
6. q0 in Q is the start state or initial state

 The output of M in response to input a1 a2… an is λ(q0,a1) λ(q1,a2).. λ(qn-1,ai) where q0,q1, … ,qn is the
sequence of states such that δ(qi-1,ai)=qi for 1 ≤ i ≤n.
 In this sequence has length n rather than length n+1 as for the Moore machine, and on input ε a
Mealy machine gives output ε.

Comparison of the Moore and Mealy Machine:


 Consider a finite state machine that checks for a pattern of ‘10’ and asserts logic high when it is
detected.
 The state diagram representations for the Mealy and Moore machines are shown in figure below.
 The state diagram of the Moore machine lists the inputs with their associated outputs on state
transitions arcs.
 The value stated on the arrows for Mealy machine is of the form Zi/Xi where Zi represents input
value and Xi represents output value.
 A Mealy machine produces a unique output for every state irrespective of inputs.
 Accordingly the state diagram of the Moore machine associates the output with the state in the form
state-notation/output-value.
 The state transition arrows of Moore machine are labeled with the input value that triggers such
transition.
 Since a Mealy machine associates outputs with transitions, an output sequence can be generated in
fewer states using Mealy machine as compared to Moore machine. This was illustrated in the
previous example.
11. Give applications of finite automata? (6 marks)
There are a variety of software design problems that are simplified by automatic conversion of regular
expression notation to an efficient computer implementation of the corresponding finite automaton.
The two applications are
1. Lexical analyzers
2. Text editors

LEXICAL ANALYZERS:
 Tokens of a programming language are regular sets.
 For example: ALGOL identifiers, which are upper-or lower-case letters followed by any sequence of
letters and digits with no limit on length, expressed as,
(letter)(letter + digit)*
where
 “letter“ stands for A + B + …… + Z + a + b + …… + z and
 “digit“ stands for 0 + 1 + ….. + 9
 FORTRAN identifiers, with length should limited of six and letters restricted to uppercase and
symbol $, may be expressed as
(letter)( + letter + digit)*
where, “letter” stands for ($ + A + B + ……. + Z).
 A number of lexical analyzers takes input as sequence of regular expressions describing the tokens
and produce a single finite automaton recognizing the any token.
 Usually, they convert the regular expression to an NFA with -transitions and then construct subset
of states to produce a DFA directly rather than first eliminating -transitions.
 Each final state indicates the particular token found, so the automaton is really a Moore Machine.
 The transition function of the FA is encoded in one of several ways to take less space than the
transition table represented as a two-dimensional array.
 The lexical analyzer produced by the generator is a fixed program that interprets coded tables,
together with the particular table that represents the FA recognizing the tokens.
 This lexical analyzer can be used as a module in a compiler.
TEXT EDITORS:
 Certain text editor and similar programs permits substitution of string for any string matching given
regular expression.

 For example: the UNIX text editor allows a command such as
s/bbb*/b/

that substitutes a single blank for the first string of two or more blanks found in a given line.

 Let “any” represents expression a1+a2+…..+an, where ai’s are computer characters except the

“newline “character.

 We could convert a regular expression r to a DFA that accepts any *r.



 The presence of any* allows to recognize a member of L(r) beginning anywhere in the line.
 The conversion of a regular expression to a DFA takes more time than it takes to scan a single sort
line using the DFA and the DFA have a number of states that is an exponential function of the length
of the regular expression.
 In UNIX text editor is that Regular expression of any*r converted to an NFA with -transitions and
NFA is then simulated directly.
However once a column has been constructed listing all the states the NFA can enter on a particular prefix of
the input, the previous column is no longer needed and is thrown away to save space.
Deterministic finite automata have many practical applications:
1. Almost all compilers and other language-processing systems use DFA-like code to divide an input
program into tokens like identifiers, constants, and keywords and to remove comments and white
space.
2. For many applications that accept typed commands, the command language is quite complex, almost
like a little programming language. Such applications use DFA-like code to process the input command.
3. Text processors often use DFA-like code to search a text fi le for strings that match a given pattern.
This includes most versions of UNIX tools like awk, egrep, and Procmail, along with a number of
platform-independent systems such as MySQL.
4. Speech-processing and other signal-processing systems often use a DFA-like technique to transform
an incoming signal.
5. Controllers use DFA-like techniques to track the current state of a wide variety of finite-state systems,
from industrial processes to video games. They can be implemented in hardware or in software.
6. Sometimes, the DFA-like code in such applications is generated automatically by special tools such as
lex.
12.With a suitable transition diagram differentiate DFA and NFA (MAY’15 APR’16)

S.NO DFA NFA


1 “DFA” stands for “Deterministic Finite “NFA” stands for “Nondeterministic Finite
Automata” Automata.”

2 Both are transition functions of automata. In In NFA each pair of state and input symbol can
DFA the next possible state is distinctly set have many possible next states.

3 DFA cannot use empty string transition. NFA can use empty string transition

4 it is more difficult to construct DFA. NFA is easier to construct

5 Backtracking is allowed in DFA In NFA it may or may not be allowed.

6 DFA requires more space NFA requires less space.

7 DFA can be understood as one machine and a NFA can be understood as several little machines
DFA machine can be constructed for every that compute together, and there is no possibility of
input and output, constructing an NFA machine for every input and
output.
Steps: The method of converting NFA to its equivalent DFA. Let M = (Q, Σ, δ, q0, F) is a NFA which accepts
the language L(M). There should be equivalent DFA denoted by M’= (Q’, Σ’, δ’, q0’, F’) such that L (M) =L (M’).

The conversion method will follow following steps:

1. The start state of NFA M will be the start for DFA M’. Hence add q0 of NFA(start state) to Q’. Then find
the transitions from this start state.
2. For each state [q1,q2..qi] in Q the transition for each input symbol Σ can be obtained as,
 δ'([q1,q2...qi],a) = δ(q1,a)U δ(q1,a)U ...........δ(qi,a) =[q1,q2....qk] may be some state.

 Add the state [q1,q2....qk] to DFA if it is not already added in Q’.

 Then find out the transition for every input symbol from Σ for state[q1,q2....qk]. if we get some state
[q1,q2....qn] which is not in Q’ of DFA then add this state to Q’.

 If there is no new state generating then stop the process after finding all the transitions.

3. For the state [q1,q2.....qn] є Q’ of DFA if any one state qi is a final state of NFA then [q1,q2,,,,,qn] becomes
a final state. Thus the set of all the final states є F’ of DFA.
Example
Consider a NFA with the transition diagram

The NFA is given by


Q= {q0, q1, q2}
Σ= {a, b}
q0= {q0}
F= {q2}

Transition Table

δ a b
q0 {q0,q1} {q1}
q1 {q2} {q1,q2}
q2 φ {q2}

Converting to DFA

The DFA can be expressed during conversion M´ = (Q, Σ, δ ´, q0, F´)

where

Q´=2Q

Σ= {a, b}

q0=q0

F´= {{q2}, {q1, q2}, {q0, q2}, {q0, q1, q2}}


Transition table for DFA

δ a b
{q0} {q0,q1} {q1}
{q1} {q2} {q1,q2}
{q2} φ {q2}
{q0,q1} {q0,q1,q2} {q1,q2}
{q1,q2} {q2} {q1,q2}
{q0,q1,q2} {q0,q1,q2} {q1,q2}
Transition diagram for DFA

13. Construct a DFA equivalent to NFA, where M = ({q0, q1, q2}, {0, 1, 2}, δ, q0, {q0, q1, q2}).
The Transition is given by the transition diagram and transition table.

Transition Table:

Inputs
States
0 1 2
* q0 {q0,q1,q2} {q1,q2} {q2}
* q1 {φ} {q1,q2} {q2}
* q2 {φ} {φ} {q2}
Transition Diagram:

CONSTRUCTING DFA:
Solution:
The equivalent DFA is M’ = (Q, {0, 1, 2}, δ’, S’, F’)
Q = {q0, q1, q2}
∑ = {0, 1, 2}
Q' = 2Q
S’= [q0] Є Q’

All subsets = { [φ],[q0],[q1],[q2],[q0,q1,q2],[q0q1],[q0q2],[q1q2][q0q1q2]}

Transition Function:

δ'(q0,0) = [q0q1q2]
δ'(q0,1) = [q1q2]
δ'(q0,2) = [q2]
δ'(q1,0) = [φ]
δ'(q1,1) = [q1q2]
δ'(q1,2) = [q2]
δ'(q2,0) = [φ]
δ'(q2,1) = [φ]
δ'(q2,2) = [q2]
δ'(q0q1,0) = δ'(q0,0) U δ'(q1,0)
= [q0, q1, q2] U {φ}
= [q0, q1, q2]
δ'(q0q1,1) = δ'(q0,1) U δ'(q1,1)
= [1q2] U [q1q2]
= [q1, q2]
δ'(q0q1,2) = δ'(q0,2) U δ'(q1,2)
= [q2] U [q2]
= [q2]
δ'(q0q2,0) = δ'(q0,0) U δ'(q2,0)
= [q0q1q2] U {φ}
= [q0q1q2]
δ'(q0q2,1) = δ'(q0,1) U δ'(q2,1)
= [q1q2] U {φ}
= [q1q2]
δ'(q0q2,2) = δ'(q0,2) U δ'(q2,2)
= [q2] U [q2]
= [q2]
δ'(q1q2,0) = δ'(q1,0) U δ'(q2,0)
= {φ} U {φ}
= [φ]
δ'(q1q2,1) = δ'(q1,1) U δ'(q2,1)
= [q1q2] U {φ}
= [q1q2]
δ'(q1q2,2) = δ'(q1,2) U δ'(q2,2)
= [q2] U [q2]
= [q2]
δ'(q0q1q2,0) = δ'(q0,0) U δ'(q1,0) U δ' (q2,0)
= {q0q1q2} U {φ} U {φ}
= [q0q1q2]
δ (q0q1q2,1) = δ'(q0,1) U δ'(q1,1) U δ' (q2,1)
= [q1q2] U [q1q2] U {φ}
= [q1q2]
δ'(q0q1q2,2) = δ'(q0,2) U δ'(q1,2) U δ' (q2,2)
= [q2] U [q2] U [q2]
= [q2]
Transition Table for DFA:
Inputs
States
0 1 2
[q0] [q0q1q2] [q1q2] [q2]
[q1] φ [q1q2] [q2]
[q2] φ φ [q2]
[q0q1] [q0q1q2] [q1q2] [q2]
[q0q2] [q0q1q2] [q1q2] [q2]
[q1q2] φ [q1q2] [q2]
[q0q1q2] [q0q1q2] [q1q2] [q2]
Final States are {[q2], [q1q2], and [q0q1q2]}

Transition Diagram:

q1q2

q0q1q2
q0 q2

q1

q0q1q2 q0q2 q0q1q2


q1q2
q1q2

14. Prove that for every regular expression there is an equivalent NFA? (11 MARKS)
Statement:
Let r be a regular expression. Then there exists an NFA with ε-transitions that accepts L(r).

Proof:
We prove by induction on the number of operators in the regular expression r that there is an NFA M that
there is an NFA M with ε-transition, having one final state and no transitions out of this final state, such
that L(M)= L(r).

Basis Step (Zero operators):


The expression ‘r’ must be ε (epsilon), Ф or ‘a’ for some a ϵ Σ. Then the equivalent NFA’s are (a), (b) and (c)
clearly satisfy the conditions.

Induction (One or more operators):

Assume that the theorem is true for regular expressions with fewer than i operators, i≥1. Let r have i
operators. There are three cases depending on the form of ‘r’.
Case (1):
Let r= r1+ r2. Both r1 and r2 must have fewer than i operators.
Thus there are NFA’s,
M1 = (Q1, Σ1, δ1, q1, {f1}) and M2 = (Q2, Σ2, δ2, q2, {f2}) with L(M1)= L(r1) and L(M2)= L(r2).
Assume Q1 and Q2 are disjoint. Let q0 be a new initial and f0 a new final state.
Construct M = (Q1  Q2  {q0, f0}, Σ1  Σ2, δ, {q0}, {f0}), where δ is defined by

1. δ(q0, ε) = {q1, q2}


2. δ(q, a) = δ1(q, a) if q ϵ Q1 {f1}, a ϵ Σ1  { ε }
3. δ(q1, a) = δ2(q, a) if q ϵ Q2  {f1}, a ϵ Σ2 U { ε }
4. δ1(f1, ε)= {f0}.

All the moves of M1 and M2 are present in M any path in the transition diagram of M from q0 to f0 must
begin by going to either Q1 or Q2 on ε. If the path goes to Q1, it may follow any path in M1 to f1 and go to f0
on ε. Similarly paths begins by going to Q2 may follow any path in M2 to f2 and then go to f0 on ε. These are
the only paths from g0 to f0. If there is a path labeled ‘x’ in M1, from Q1 to f1 or a path in M2 from q2 to f2.
Hence L(M)= L(M1)  L(M2).

Case (2):
Let r= r1r2.
Let M1 = (Q1, Σ1, δ1, q1, {f1}) and M2 = (Q2, Σ2, δ2, q2, {f2}) with L(M1) = L(r1) and L(M2) = L(r2).

Construct M = (Q1 Q2, Σ1  Σ2, δ, {q1}, {f2}),


where δ is defined as,
1. δ(q, a) = δ1(q, a) for q in Q1 {f1}, a in Σ { ε}
2. δ(f1, ε) = {q2}
3. δ(q, a) = δ(q, a) for q in Q2 and a in Σ2  { ε}
Every path in M< from q1 to f2 is a path labeled by some string ‘x’ from q1 to f1, followed by some string ‘y’
from q2 to f2. Thus L(M) = {xy | x is in L(M2) and y is in L(M2)}. And L(M)= L(M1)L(M2).
Case (3):
Let r= r*. Let M1= (Q1, Σ1, δ1, q1, {f1}) and L(M1) = r1.
Construct M= (Q1 {f0}, Σ1, δ1, q0, {f0})

Where δ is given by
1. δ(q0, ε) = δ(f1, ε) = {q1, f0}
2. δ(q, a) = δ1(q, a) for q in Q1  {f1} and a in Σ1 { ε}.

Any path from q0 to f0 consists either of a path from q0 to f0 or a path from q0 to q1 on ε followed by
same no. of paths from q1 to f1, then back to q1 on ε. There is a path in M from q0 to f0 labeled ‘x’ if we
write
x= x1, x2, ……xj for some j≥ 0 such that each xi belongs to L(M1). Hence L(M)= L(M1*).

15. Prove: A language L is accepted by some ε-NFA if and only if L is accepted by some DFA. (APR ,15)

To Prove:
The Language accepted by NFA is equal to the language set
accepted by DFA. i.e. L(M)=L(M´) ,
Where M is the NFA and M´ is the DFA.
Proof:
Let M= (Q, Σ, δ, q0, F) be an NFA, accepting L and we can
define a DFA M´ = (Q, Σ, δ´, q0, F´) as follows.
The states of M´ are all the subsets of the set
of states of M. That is, Q´ = 2Q
M´ will keep track in its states of all the states M could be in at any given time. F´ is the set all
the states in Q´ containing the final state of M. An element of Q´ will be denoted by [q1, q2,
q3....qi] are in Q.
Observe that, [q1, q2, q3....qi] is a single state of DFA corresponding to the
states of the NFA. Note q0´= [q0]
We define
δ´([q1 ,q2, q3.... qi], a)= [P1, P2, P3 .... Pj]
if and only if
δ([q1, q2, q3....qi], a)= [P1, P2, P3 .... Pj]
that is
δ´ applied to an element [q1, q2, q3 ....qi] of Q´ is computed by applying δ to each state of Q represented
by [q1, q2, q3 .... qi] in applying δ to each of [q1, q2, q3 .... qi] and taking “union” we get some new set of
states P1, P2, P3 .... Pj. This new set of states has a representative P1, P2, P3.... Pj in Q´ and that element is
the value of δ´([q1, q2, q3 .... qi], a).

It is easy to show by induction for the length of the input string x, that
δ´( q0´, x) =[q1, q2, q3 .... qi]
if and only if,
δ( q0, x) ={q1, q2, q3 .... .qi}

Basis
Consider |x|=0 then x must be since q0´= [q0]
Then
δ´( q0, ε )=( q0)
if and only if
δ( q0, ε )= { q0}
Hence the result is trivial.
Induction
Let us assume that the hypothesis is true for inputs of length m, Let xa be a string of length m+1 with a in
Σ, then
δ´( q0’,xa ) = δ´( δ´( q0’,x),a)
By the inductive hypothesis,
δ´( q0’, x) = [P1, P2, P3. ... Pj]
If and only if ,
δ( q0, x) = {P1, P2, P3 .... Pj}.
But by the definition of δ´,
δ´[(P1, P2, P3 .... Pi), a] = [r1, r2, r3 .... rk]
If and only if,
δ({P1, P2, P3 .... Pi}, a) = [r1 ,r2, r3 .... rk]
Thus,
δ´( q0, xa)= [r1, r2, r3 .... rk]
If and only if,
δ(q0, xa )= [r1, r2, r3 .... rk]
Which establishes the inductive hypothesis,
To complete the proof, we have only to add that δ´( q0’,x) is in F´ exactly when δ( q0 ) contains a state of Q
that is F.
Thus, L(M)=L(M´)
PONDICHERRY UNIVERSITY QUESTIONS
2 MARKS

1. Give the purpose of transition diagram? (APR 2014)(Ref.Qn.No.20, Pg.no.8)


2. Write the DFA Specifications? (APR 2014, NOV 2012) (Ref.Qn.No.22, Pg.no.9)
3. Define NFA. (APR 2012, 2013)(Ref.Qn.No.25, Pg.no.10)
4. Define two way finite automata (2DFA)? (APR 2012, NOV 2013) (Ref.Qn.No.32, Pg.no.12)
5. Give the applications of finite automata? (NOV 2012,NOV’14) (Ref.Qn.No.41, Pg.no.14)
6. Define Equivalence Relation? (NOV 2013) (Ref.Qn.No.46, Pg.no.16)
7. What are the difference between NFA and DFA? ( MAY ’15,NOV’15) (Ref.Qn.No.26, Pg.no.10)
8. Define regular expressions? (NOV’14) (Ref.Qn.No.29, Pg.no.11)
9. Define Finite Automata. (NOV’15) (Ref.Qn.No.18, Pg.no.8)

11 MARKS
1. Explain Non-Deterministic Finite Automata (NFA) with an example? (APR 2014) (Ref.Qn.No.4,
Pg.no.24)
2. Explain about converting DFA’s to regular expression by eliminating states. (APR 2014)
3. Let r be a regular expression. Then there exists an NFA with ε-transitions that accepts L(r).
(NOV 2013) (Ref.Qn.No.11, Pg.no.43)
4. If L is accepted by a 2DFA, then L is regular set. (NOV 2013)
5. Explain the DFA with example? (APR 2013) (Ref.Qn.No.3, Pg.no.21)
6. Explain about Regular Expressions with an example? (APR 2013, APR 2012,MAY’15)
(Ref.Qn.No.2, Pg.no.19)
7. Describe in detail about two-way automation with an example. (APR 2012) (Ref.Qn.No.8,
Pg.no.36)
8. Define the Moore and Mealy Machine. State the configuration and illustrate the same with an
example. (NOV 2012,MAY’15) (Ref.Qn.No.9 Pg.no.38)
9. Define Regular expression. Write a r.e. denote a language L which accepts all the strings which begin
or end with either 00 or11. (NOV 2012)
10. With a suitable transition diagram differentiate DFA and NFA (MAY’15) ) (Ref.Qn.No.12 Pg.no.45)

You might also like