In any type of regular expression there are only three cases possible.1. Union 2. Concatenation 3. Closure
Equivalence of NFA and Regular Expression
AU:
May-04,06,09,10,11,12,14,16,17, Dec.-10,14,15,19, Marks 10
Theorem
1:
Let r be a regular expression, then there exists a NFA with ε transitions that
accepts L (r).
Proof:
This theorem can be proved by induction method.
The
basis of induction will be by considering r has zero operators.
Basis
(zero operators) - Now, since r has zero operators, means r can be either ε or ϕ
or a for some a in input set Σ.
The
finite automata for the same can be written as
Induction:
This theorem can be true for n number of operators. The n is greater than or
equal to 1. The regular expression contains equal to or more than one operators.
In
any type of regular expression there are only three cases possible.
1.
Union 2. Concatenation 3. Closure
Let
us see each,
Case
1: Union case
Let
r = r1 + r2 where r1 and r2 be the
regular expressions.
There
exists two NFA's M1 = (Q1, Σ1, δ1,
{f 1})
and
M2 = (Q2, Σ2, δ2,{f2})
L
(M1) = L(r1) means the language states by regular
expression r1 is same which is represented by M1.
Similarly L (M2) = L (r2).
Q1
represents the set of all the states in machine M1.
Q2
represents the set of all the states in machine M2.
We
assume that Q1 and Q2 are totally different i.e. Q1
and Q2 are disjoint.
Let
q0 be new initial state and f0 be the new final state we
will form
M
= ((Q1 U Q2 U {q0, f0}), (Σ1
U Σ2), δ, q0 {f0})
The
δ is denoted by,
i)
δ (q0, ε) (q1, q2}
ii)
δ (q, a) = δ1 (q, a) for q in Q1 - {f1} and a
in Σ1 U {E}.
iii)
δ (q, a) = δ2 (q, a) for q in Q2 -{f2} and a
in Σ2 U {E}.
iv)
δ (f1, ε) = δ1 (f2, ε) = {f0}
All
the moves are now present in machine M which is as shown Fig. 2.3.2.
The
construction of machine M is shows the transition from q0 to f0
must begin by going to q1 or q2 on ε. If the path goes to
q1, then it follows the path in machine M1 and goes to
the state f1 and then to f0 on ε. Similarly, if the path
goes to q2, then it follows the path in machine M2
and goes to state f2 and then to f0 on ε. Thus the L (M)
= L (M1) U L (M2). That means either the path in machine
M1 or M2 will be followed.
Case
2: Concatenation case
Let,
r = r1 r2 where г1 and r2 are two
regular expressions. The M1 and M2 denotes the two
machines such that L (M1) = L (r1) and L (M2)
= L (r2).
The
construction of machine M will be
M
= (Q1 U Q2, Σ1 U Σ2, δ,{q1},
{f2})
The
mapping function δ will be given as
i)
δ (q, a) = δ1 (q, a) for q in
Q1
- {f1} and α in Σ1 U{ε}
ii)
δ (f1, ε) = {q2}.
iii)
δ (q, a) = δ2 (q, a) for q in
Q2
and a in Σ1 U {ε}
The
machine M is shown in the Fig. 2.3.3.
The
initial state is q1 by some input a the next state will be f1.
And on receiving ε the transition will be from f1 to q2
and the final state will be f2. The transition from q2 to
f2 will be on receiving some input b.
Thus
L (M) = ab
That
is a is in L (M1) and b is in L (M2).
Hence
we can prove L (M) = L (M1) L (M2).
Case
3: Closure case
Let
r = r1 where r1 be a regular expression.
The
machine M1 is such that L(M1)=L(r1).
Then
construct M = (Q1 U {q0, f0}, Σ1, δ,
q0, {f0}).
The mapping function δ is given
by,
i)
δ (q0, ε) = δ (f1, ε) = {q1, f0}
ii)
δ (q, a) = δ1 (q, a) for q in
Q1
- {f1} and a in Σ1 U {ε}
The
machine M will be
The
machine M1 shows that from q0 to q1 there is a
transition on receiving ε similarly, from q0 to f0 on
& there is a path. The path exists from f1 to q1, a
back path. Similarly a transition from f1 to f0 final
state, on receiving ε. The total recursion is possible. Thus one can derive ɛ,
a, aa, aaa, .... for the input a.
Thus
L (M) = L (M1)* is proved.
Now
based on this proof let us solve some examples. These examples illustrate how
to convert given regular expression to NFA with ɛ moves.
Example
2.3.1 Construct an NFA equivalent to the following
regular expression
((10)
+ (0+1)*) 01. AU: May-06, Marks 10
Solution:
Consider
r.e.
= (r1 + r2) r3
where
r1
= 10
r2
= (0+1)*
r3
= 01
We
will build NFA for each r1, r2 and r3.
r1
= 10
r2
= (0+1)*
r3
= 01
Now
we will design the final NFA for r. (See Fig. 2.3.8 on next page)
(I+00) (1+0) = 97
Example
2.3.2 Construct a NFA equivalent to (0 + 1)* (00 + 11). AU
May-04, Marks 8
Solution:
Consider
r.e.
= (0 + 1)* (00 + 11)
r1
= (0 + 1)
r2
= (00 + 11)
The
NFA for r1 can be drawn as follows.
The
NFA for r2 can be
The
NFA for the given regular expression can be (See Fig. 2.3.11 on next page).
Example
2.3.3 Construct NFA with epsilon for the RE = (a|b)* ab
and convert into DFA and further find the minimized DFA. AU May-17, Marks 16
Solution:
The
NFA with ɛ can be constructed as follows
The
above NFA can be converted to DFA as follows -
ε
- closure (q0) = {q0, q1, q2, q4,
q7} = Call it as A
δ'
(A, a) = ε - closure (δ (q0, q1, q2, q4,
q7), a)
=
ε - closure (q3, q8)
=
{q1, q2, q3, q4, q6, q7,
q8}
δ'
(A, a) = Call it as state B
δ'
(A, a) = B
δ'
(A, b) = ε - closure (δ (q0, q1, q2, q4,
q7), b)
=
ε - closure (q5)
=
{q1, q2, q4, q5, q6, q7}
Call it as C
δ'
(A, b) = C
δ'
(B, a) = ε - closure (δ (q1, q2, q3, q4,
q6, q7, q8), a)
=
ε - closure (q3, q8)
δ'
(B, a) = B
δ'
(B, b) = ε - closure (δ (q1, q2, q3, q4,
q6, q7, q8), b)
=
ε - closure (q5, q9)
=
{q1, q2, q4, q5, q6, q7,
q9} Call it as D
δ'
(B, b) = D
δ'
(C, a) = ε - closure (δ (q1, q2, q4, q5,
q6, q7), a)
=
ε - closure (q3, q8)
δ'
(C, a) = B
δ'
(C, b) = ε - closure (δ (q1, q2, q4, q5,
q6, q7), b)
=
ε - closure (q5)
δ'
(C, b) = C
δ'
(D, a) = - closure (δ (q1, q2, q4, q5,
q6, q7, q9), a)
=
ε - closure (q3, q8)
δ'
(D, a) = B
δ'
(D, b) = δ - closure (δ (q1, q2, q4, q5,
q6, q7, q9), b)
=
ε - closure (q5, q9)
δ'
(D, b) = D
As
no new state is getting generated the transition table will be
The
δ transition of state B and state D is same but B is a non final state while D
is a final state. So we can not merge them. We can merge state A and state C.
Then the minimized DFA will be
Direct Method for Conversion of RE to FA
1.
State Elimination Method
This
is the simplest method of obtaining regular expression. We will use following
rules to obtain r.e. by eliminating states
1.
Eliminate all the states except final state and start state.
2.
Reduce the given finite automata and obtain the generalised transition graph
with (start and end states as follows
The
regular expression for this finite automata will be –
3.
If we reduce the finite automaton to only one state graph by state eliminating
method then -
4.
After eliminating the sufficient number of states we can obtain r.e. as sum of
the expressions derived from the reduced automata. Let us understand this
method of obtaining regular expression with the help of some examples.
Example
2.3.4 Obtain method r.e. from given FA by state
elimination method.
Solution:
In above given FA state q3 is
a dead state. Hence we will eliminate state q3. Thus the FA now
becomes
This
FA resembles the generic finite automata with two state (as given in Fig.
2.3.15)
Hence
required r.e. will be
a*bb*
As q2 is a final state we get
i.e. r.e. = a*b+
Example
2.3.5 Represent the language given by the following DFA,
by obtaining r.e. by state elimination method.
Solution:
In
above transition graph state q1 is a dead state. We can not reach to
final state from this state, hence we will eliminate state q1. The
FA then becomes as –
The
state q2 can be written as (a + b) *. Hence the required r.e. is
a(a+b)*. This regular expression specifies a language which starts with letter
a and it is followed by any number of a's and b's.
Example
2.3.6 Construct Finite automaton to accept the regular
expression
(0+1)*(00
+ 11)(0+1)*. AU: May-14, Marks 8, May-11, Marks 6
Solution:
The
FA for r.e. =(0+1) (00 + 11) (0+1)* as follows –
Example
2.3.7 Construct Finite Automata equivalent to the regular
expression (ab +a)*. AU: Dec.-15, Marks 6
Solution:
First of all we will construct NFA for given regular expression.
The
NFA without ε is
Example
2.3.8 Draw a non-deterministic automata to accept string
containing the substring 0101. AU May-16, Marks 2
Solution:
The regular expression is
(0+1)*
0101 (0+1)*
The
non-deterministric finite automata is
Example
2.3.9 Construct a finite automata for the regular
expression 10 + (0+11)0*1 AU Dec.-19,
Marks 6
Solution
:
Review Question
1.
Let r be a regular expression. Then prove that there exists a NFA with &
transition that accept L(r).
Theory of Computation: Unit II: Regular Expressions and Languages : Tag: : Regular Expressions and Languages - Theory of Computation - Equivalence of NFA and Regular Expression
Theory of Computation
CS3452 4th Semester CSE Dept | 2021 Regulation | 4th Semester CSE Dept 2021 Regulation