1 - Module 1.2 - Equivalence of RE and FA
1 - Module 1.2 - Equivalence of RE and FA
BY
Mrs Charusheela Nehete
Assistant Professor,
IT Department ,
VESIT
1
Contents
● Regular Expressions
● Finite Automata
● Kleene’s Theorem
● RE to NFA - ε conversion
● NFA – ε to DFA Conversion
● NFA – ε to NFA without ε- moves Conversion
Introduction
● Regular expressions and finite automata have equivalent expressive power:
● For every regular expression R, there is a corresponding FA that accepts
the set of strings generated by R.
● For every FA A there is a corresponding regular expression that
generates the set of strings accepted by A.
Kleene’s Theorem
RE to DFA conversion
RE to FA conversion
● 3 steps
*
RE to NFA - ε moves
(a) NFA With Epsilon moves for (a+b)
(b) NFA With Epsilon moves for (a+b)*
(b) NFA With Epsilon moves for a.(a+b)*
Example 2
• Step 1: We will take the ε-closure for the starting state of NFA as a starting state of
DFA.
• Step 2: Find the states for each input symbol that can be traversed from the present.
That means the union of transition value and their closures for each state of NFA
present in the current state of DFA.
• Step 3: If we found a new state, take it as current state and repeat step 2.
• Step 4: Repeat Step 2 and Step 3 until there is no new state present in the transition
table of DFA.
• Step 5: Mark the states of DFA as a final state which contains the final state of NFA.
30
Example 1
Convert the following NFA with ε into its equivalent DFA.
δE 0 1
ε
q0 Ø Ø {q1,q2}
q1 {q3} Ø Ø
q2 Ø {q3} Ø
q3 Ø {q4} Ø
*q4 Ø Ø Ø 31
Example 1
q1 {q3 Ø Ø {q1}
• ε-closure {q1} = {q1}
}
• ε-closure {q2} = {q2}
q2 Ø {q3} Ø {q2}
• ε-closure {q3} = {q3}
q3 Ø {q4} Ø {q3}
• ε-closure {q4} = {q4}
*q4 Ø Ø Ø {q4}
32
Example 2
Steps for converting NFA with ε to DFA:
Partial DFA will look
like this:
q1 {q3 Ø Ø {q1}
}
q2 Ø {q3} Ø {q2}
q3 Ø {q4} Ø {q3}
*q4 Ø Ø Ø {q4}
33
Final DFA
δE 0 1 ε ε-closure
q1 {q3} Ø Ø {q1}
q2 Ø {q3} Ø {q2}
q3 Ø {q4} Ø {q3}
*q4 Ø Ø Ø {q4}
34
EXAMPLE 2
35
Example 3
Convert the given NFA - ε into its equivalent DFA.
δE 0 1 2 ε ε-closure
36
Example 3
Convert the given NFA - ε into its equivalent DFA
• Now we will obtain δ' transition.
Let ε-closure(q0) = {q0, q1, q2}
call it as state A.
δE 0 1 2 ε ε-closure
37
Example 3
Convert the given NFA - ε into its equivalent DFA
• Now we will obtain δ' transition.
Let ε-closure(q0) = {q0, q1, q2}
call it as state A.
δE 0 1 2 ε ε-closure
38
The Partial DFA will be
39
Example 3
Convert the given NFA - ε into its equivalent DFA
• State B = {q1,q2}
δE 0 1 2 ε ε-closure
40
Example 3
Convert the given NFA - ε into its equivalent DFA
δE 0 1 2 ε ε-closure
• State C = {q2}
q0 {q0} Ø Ø {q1,q2} {q0, q1, q2}
41
Final DFA will be as follows:
42
Exercises
*2 1 Ø Ø {2}
3 2 {2,3} Ø {3}
43
Convert NFA with ε transition to equivalent DFA
Exercises
δE a b ε ε-closure
Let us obtain ε-closure of each
state.
ε-closure {1} = {1,2} call this as
1 {3} Ø {2} {1,2} state A
ε-closure {2} = {2}
*2 {1} Ø Ø {2} ε-closure {3} = {3}
44
Convert NFA with ε transition to equivalent DFA
Exercises
δE a b ε ε-closure
Let us obtain ε-closure of each
state.
ε-closure {1} = {1,2} call this
1 {3} Ø {2} {1,2} as state A
ε-closure {2} = {2}
*2 {1} Ø Ø {2} ε-closure {3} = {3}
*C A C
45
Final DFA
δ' a b
a
*A Ø
B
*B B C
A B
*C A C
b
a
46
Exercises
Convert NFA with ε
transition to
equivalent DFA
47
Exercise
48
DFA TO RE
(Writing a RE for the given DFA)
1. Obtain the RE that denotes the language accepted by
following FA?
r = (a + b) (a + b) *
2. Obtain the RE that denotes the language accepted by
following FA?
r = (a + b) *
3. Obtain the RE that denotes the language accepted by
following FA?
r = a.(a + b) *
4. Obtain the RE that denotes the language accepted by following FA?
4. Obtain the RE that denotes the
language accepted by following FA?
5. Obtain the RE that denotes the language accepted by
following FA?
6. Obtain the RE that denotes the language accepted by
following FA?
r=
Exercises
1. L := {w ∈ {a, b}∗ | |w| divisible by 3}
((a + b) · (a + b) · (a + b))∗
4. L := {w ∈ {0, 1}∗ | starts with 0 and has odd length, or starts with 1 and
has even length }
0((0+1) (0+1))* + 1(0+1)((0+1)(0+1))*