Finite Automata & Regular Expressions
Finite Automata & Regular Expressions
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
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.
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}
δ (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)
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
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, …..}
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
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
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
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’
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]
q1q2
q0q1q2
q0 q2
q1
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.
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
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.
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 ε.
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.
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
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’).
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
Transition Table
δ a b
q0 {q0,q1} {q1}
q1 {q2} {q1,q2}
q2 φ {q2}
Converting to DFA
where
Q´=2Q
Σ= {a, b}
q0=q0
δ 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’
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
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).
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
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).
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
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)