You are on page 1of 23

Basic RE to DFA

 For regular expression “a”

a
X Y

 For regular expression “ab”


a b
X Y Z

 For regular expression “a+b”


a
X Y a,b
X Y
b
Basic RE to DFA
 For regular expression “a*”

 For regular expression “(a+b)*”

a a,b
Example
 Construct DFA for a*bc

b c
X Y Z

a,b
c a,b,c

T
Example
 Construct DFA for a+bc

a b c
W X Y Z

a,b
b,c c a,b,c

T
Example
 Construct DFA for (ab)*b

b
A B

a b b

C D
a
Example
1) Construct DFA for Even number of a’s, when Σ ={a,b}.

RE ➔ ( b + ab*ab* ) *

DFA➔ a

A a
B

b b
Exercise
2) Construct DFA for string with “ab” as substring , when
Σ ={a,b}.
(a+b)* ab (a+b)*
RE ➔

b a a, b
DFA ➔
a b
X Y Z
Procedure: State Elimination(Reduction) Method

1) Remove the trap state from the finite automata


2) At each state, reduce by removing the intermediate
states considering all the paths.
3) Step 2 to be repeated till one of the standard form is
obtained and then generalize the regular expression

Note: If more than one Final state exists, then they can
be merged by considering all the paths without
changing the language

16-05-2022 10
Generalized Transition Graph:
It is the transition graph which allows regular expression
as the label on the directed edges.
Note: DFA allows only input symbol on the edge
NFA allows both input symbol and λ or ϵ on the edge
Case 1: Single state with final state
r RE = r*

Case 2: Initial state and one final state


r1 r2 r3
X Y
RE = r1* r2 r3*

Case 3: Initial state and one final state (with back edge)
r1 r2 r3 RE = r1* r2 ( r3 + r4 r1* r2) *
X Y
r4 11
FA to RE
 State elimination method –
 Remove all intermediate states
 Remove all the trap states and thus solve
a b RE = ab
X Y Z

a
RE = a+b
X Y
b

b
a b*a RE = b*a
X Y X Y
Example-1
a a a,b

b b
1 2 3

a a+b

b a*b
1 2 3

a a+b

ba*b
1 3

a*ba*b(a+b)* RE= a*ba*b(a+b)*


1 3
Example-2
a d
c
1 2
b

c d

1 2
a*b
d

1 a*b 2

ca*b

RE = a*b(d + ca*b)*
Example-3 0
0
A B
1 A B
0 1 Removing trap state
0 1 0
0 1
C 1 D
C 1 D
0
A B A 01 A 01 A 01 + 10
1
0 1 0 1
10
C C
RE = (01+10)*
Example-4
0 1 0,1

1 0
q0 q1 q2

0 1 0,1

1 0
q0 q1 q2

0 1 0*1*

1
q0 q1 q0

RE= 0* + 0*11* RE = 0*1*


= 0*(λ + 11*)
Example-5
1 1 0,1
0
1
q0 q1 q2

0
1 0,1 1 0,1
1*0
1*1 01*1
q0 q1 q2 q0 q2

0
0+1 01*0
1+01*0

01*1
q0 q2 RE= (1+01*0)*01*1(0+1)*
Example-6 a λ

a,b a b bb
1 2 3 4

a
a λ a ab

a+b ab bb (a+b)ab bb
1 2 4 1 4

a a

1 a*(a+b)ab 4 ab+bb
1 a*(a+b)ab 4 ab+bb

aa*(a+b)ab
a

RE= a*(a+b)ab ( (ab+bb) + (aa*(a+b)ab) )*


Example-7 aa aa
a bb ab(bb)*ba
00 10 00 ab 00
a
ba 11
b b b b b b b b a(bb)*ba
a
a ab(bb)*a
01 11 01 a 01
a

aa a(bb)*a
ab(bb)*ba
00

b+a(bb)*ba
ab(bb)*a+b
01
RE = (aa+ab(bb)*ba)* (ab(bb)*a+b)
( a(bb)*a +
a(bb)*a (b+a(bb)*ba) (aa+ab(bb)*ba)* (ab(bb)*a+b) )*
Example-8
a a+b a+b*
a a+b
0 1 2

a*b+c
a a+b* a a+b*
a (a+b)*(a+b) a(a+b)*(a+b)
0 1 2 0 2

a*b+c a*b+c
a a+b*
(a*b+c)+(a(a+b)+ ) a*(a*b+c)+(a(a+b)+ )(a+b*)*
0 2 0 2

RE = a*(a*b+c)+(a(a+b)+ )(a+b*)*
Exercise
3) Construct DFA for the string with regular expression
(111 + 11111)*
Strings accepted are 3 (111), 5 (11111),6 (111 twice), 8 (111 once and 11111 once),
9 (111 trice),10 (11111 twice), Count of 1 afterwards
1 1 1 1 1 1 1

1
1
OR
Exercise
4) Construct DFA for the strings of 0’s and 1’s without
any consecutive ones
(10+0)* (1+ λ)
0,1

3 OR

0 0
1

1 0
0 1 2

1
Assignment
RE to DFA:
1) String with a divisible by 3, when Σ ={a,b}.
2) Odd number of a’s, when Σ ={a,b}.
3) Construct DFA for :
1) (a+b)ba
2) (a+b)*ba
3) (a*b*)*
FA to RE: a e b
1. 0 1 2
d c

You might also like