VOOZH about

URL: https://www.geeksforgeeks.org/theory-of-computation/design-finite-automata-from-regular-expressions/

⇱ Design finite automata from regular expressions - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Design finite automata from regular expressions

Last Updated : 23 Jul, 2025

Prerequisite -  , ,

In this article, we will see some popular regular expressions and how we can convert them to finite automata (NFA and DFA). Let's discuss it one by one.

Overview :
Let a and b are input symbols and r is the regular expression. Now we have to design NFA as well as DFA for each regular expression.

Design finite automata from the regular expression :
Here, we will discuss the Design of finite automata from regular expression as follows.

Case-1 : 
When r = Φ, then FA will be as follows.

👁 Image

Case-2 : 
When r = ε, then FA will be as follows.

👁 Image

Case-3 : 
When r = a, then FA will be as follows.

👁 Image

Case-4 : 
When r = a+b , then FA will be as follows.

👁 Image

Case-5 : 
When r = r = a, then FA will be as follows.
 

👁 Image

Case-6 : 
When r = a* + b*, then FA will be as follows.

👁 Image

Case-7 : 
When r = (ab)*, then FA will be as follows.

👁 Image

Case-8 : 
When r = (ab)*b, then FA will be as follows.

👁 Image

Case-9 : 
When r = (ab)*a, then FA will be as follows.

👁 Image

Case-10 : 
When r = a*b*, then FA will be as follows.

👁 Image

Case-11 : 
When r = (a+b)*, then FA will be as follows.

👁 Image

Unary Design :
Let a is the input symbol and r is the regular expression. For each regular expression, we will design finite automata.

Case-1 : r = a* 

👁 Image

Case-2 : r = (aa)*

👁 Image

Case-3 : r = (aa)*a

👁 Image

Case-4 : r = aaaa*

👁 Image

Case-5 : r= (aa + aaa)*

👁 Image

Case-6 : r=( aaa+aaaaa)*

👁 Image

Case-7 : r=(aa + aaaaaa)*
It is a multiple of 1 term i.e. aa, so it can be reduced to r=(aa)*.
 

👁 Image
L= {an | n = 7x+12, x € Z, x >=0 }
👁 Image

General Methods :
Here, we will discuss some general methods as follows.

Method-1 :

L = { aK1n+K2 ; n>=0 }

If K1>K2, No. of states = K1
If K1<K2, No. of states = K2 +1
If K1=K2, No. of states = K1 +1 = k2 +1

Method-2 :

L = { aKn ; n>0 , K is a fixed integer }

   = { aKn  ; n>=1. K is an integer}
No. of states = K +1 

Method-3 :

L = { aKn ; n>=0 , K is a fixed integer }

Here, residue i.e. K2=0,  K1>K2. Therefore, No. of states =

Comment

Explore