Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Regular Expression or Regular Language to Finite Automata [Part-02]

Conversion of RE/RL to FA

To convert the RE to FA, we are going to use a method called the subset method. This method is
used to obtain FA from the given regular expression. This method is given below:

Step 1: Design a transition diagram for given regular expression, using NFA with ε moves.

Step 2: Convert this NFA with ε to NFA without ε.

Step 3: Convert the obtained NFA to equivalent DFA.

Some basic RA expressions are the following –

Regular Expression 1: Φ (Phi).


The language of the given RE is L1 = {} i.e, empty string. Its finite automata will be like below-

In the above transition diagram, as we can see that state ‘X’ is not accepting any alphabet.

Regular Expression 2: ‘a’ (Alphabet ‘a’).


The language of the given RE is L2 = {a} i.e, a language containing only ‘a’ as the string.
Its finite automata will be like below-

In the above transition diagram, as we can see that state ‘X’ on getting ‘a’ as the alphabet it transits
to a state ‘Y’. Thus, it accepts only ‘a’ as the alphabet.

Regular Expression 3: ‘a+b’ (Union process of two alphabets ‘a’ and ‘b’).
The language of the given RE is L3 = {a, b} i.e, a language containing ‘a’ and ‘b’ as the string.
Its finite automata will be like below-

Md Mohibullah, Assistant Professor, Department of CSE, Comilla University


1
Regular Expression or Regular Language to Finite Automata [Part-02]

In the above transition diagram, as we can see that state ‘X’ on getting either ‘a’ or ‘b’ as the alphabet
it transits to a state ‘Y’. Thus, it accepts the desired language’s strings.

Regular Expression 4: ‘a.b’ (Concatenation of two alphabets ‘a’ and ‘b’).


The language of the given RE is L4 = {ab} i.e, a language containing ‘ab’ as the string only.
Its finite automata will be like below-

In the above transition diagram, as we can see that state ‘X’ on getting ‘a’ as the alphabet it transits
to state ‘Y’ and the state ‘Y’ on getting ‘b’ as the input string it transits to the final state ‘Z’. Thus, it
accepts the desired language’s string.

Regular Expression 5: ‘ab*’ (‘a’ followed by any number of ‘b’). The language of the given RE is,
L1 = {a, ab, abb, abbb, .........}
Its finite automata will be like below-

In the above transition diagram, as we can see that state ‘X’ on getting ‘a’ as the input it transits to a
final state ‘Y’ which on getting ‘b’ as the input it remains in the state of itself. Thus, this FA accepting
all the strings of the given RE language.

Regular Expression 6: ‘(ab)*’ (‘a’ followed by ‘b’ but substring ‘ab’ can be repeated any number
of times). The language of the given RE is,
L2 = {ε, ab, abab, ababab, .........}
Its finite automata will be like below-

Md Mohibullah, Assistant Professor, Department of CSE, Comilla University


2
Regular Expression or Regular Language to Finite Automata [Part-02]

In the above transition diagram, as we can see that initial and final state ‘X’ on getting ‘a’ as the
input it transits to a final state ‘Y’ which on getting ‘b’ as the input it comes back to the state ‘X’.
Thus, this FA accepting all the strings of the given RE language.

Regular Expression 7: ‘(a+b)*’ (‘a’ union ‘b’ but substring ‘a+b’ can be repeated any number of
times). The language of the given RE is,
L3 = {ε, a, b, aa, aaab, bbbbb, ba, .......}
The language containing ε and any number of ‘a’ or ‘b’ or both combined.
Its finite automata will be like below-

In the above transition diagram, as we can see that state ‘X’ on getting ‘a’ as the input it remains in
the state of itself and on getting ‘b’ as the input it transits to another final state ‘Y’ which on getting
‘b’ or ‘a’ as the input it remains in the state of itself. Thus, this FA accepting all the strings of the
given RE language.

Note – The minimal DFA of regular expression (a+b)* will have only single state, which is both
starting and final state. This will contain only loop of alphabet ‘a’ and ‘b’.

In the above transition diagram, as we can see that initial and final state ‘Z’ on getting either ‘a’
or ‘b’ as the input it remains in the state of itself. Thus, this FA accepting all the strings of the
given RE language.

Md Mohibullah, Assistant Professor, Department of CSE, Comilla University


3
Regular Expression or Regular Language to Finite Automata [Part-02]

Note: The below REs are equivalent to each other-

= (a+b)*

= (a*+b*)*

= (a*b*)*

= (a*+b)*

= (a+b*)*

= a*(ba*)*

= b*(ab*)*

Regular Expression 8: ‘a+’ (Any number of ‘a’ excluding ε).


The language of the given RE is
L5 = {a, aa, aaa, aaaa, .........}
Its finite automata will be like below-

In the above transition diagram, initial state ‘X’ on getting ‘a’ as the input it transits to a final state
‘Y’ which on getting ‘a’ as the input it remains in the state of itself. Thus, this FA accepting all the
strings of the given RE language.

Md Mohibullah, Assistant Professor, Department of CSE, Comilla University


4
Regular Expression or Regular Language to Finite Automata [Part-02]

More Examples

Example 1

Convert the following REs to FAs

Md Mohibullah, Assistant Professor, Department of CSE, Comilla University


5
Regular Expression or Regular Language to Finite Automata [Part-02]

Example 2

RE= ‘(ab+ba)*’ (‘ab’ union ‘ba’ but substring ‘ab+ba’ can be repeated any number of times). The
language of the given RE is,
L4 = {ε, ab, abab, abba, ba, baba, ........ }
The language containing ε and any number of ‘ab’ or ‘ba’ or both combined.
Its finite automata will be like below-

In the above transition diagram, the initial and final state ‘X’ on getting ‘a’ as input it go to a state
‘Y’ and on getting ‘b’ as the input it goes to another state ‘Z’ and so on for the remaining states.
Thus, this FA accepting all the strings of the given RE language.

Example 3

Regular language L = ab*c


The language of the given RE is {ac, abc, abbc, ...........}
Its finite automata will be like below-

In the above transition diagram, as we can see that initial state ‘X’ on getting ‘a’ as the input it
transits to another state ‘Y’ and the state ‘Y’ on getting ‘b’ as the input it remains in the state of
itself and so on for the remaining states. Thus, this FA accepting all the strings of the given RE
language.

Md Mohibullah, Assistant Professor, Department of CSE, Comilla University


6
Regular Expression or Regular Language to Finite Automata [Part-02]

Example 4
Regular language L = 0(10)*
The language of the given RE is {0, 010, 01010, 0101010, ..........}
Its finite automata will be like below-

In the above transition diagram, as we can see that initial state ‘Y’ on getting ‘0’ as the input it
transits to a final state ‘Z’ and so on for the remaining states. Thus, this FA accepting all the strings
of the given RE language.

Md Mohibullah, Assistant Professor, Department of CSE, Comilla University


7

You might also like