The Wayback Machine - https://web.archive.org/web/20240607080331/https://www.geeksforgeeks.org/generating-regular-expression-from-finite-automata/
Open In App

Generating regular expression from Finite Automata

Last Updated : 06 Sep, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Prerequisite – Introduction of FA, Regular expressions, grammar and language, Designing FA from Regular Expression There are two methods to convert FA to the regular expression:

1. State Elimination Method:

  • Step 1 – If the start state is an accepting state or has transitions in, add a new non-accepting start state and add an €-transition between the new start state and the former start state.
  • Step 2 – If there is more than one accepting state or if the single accepting state has transitions out, add a new accepting state, make all other states non-accepting, and add an €-transition from each former accepting state to the new accepting state.
  • Step 3 – For each non-start non-accepting state in turn, eliminate the state and update transitions accordingly.

Example :- 

Solution:

      

2. Arden’s Theorem: 

Let P and Q be 2 regular expressions. If P does not contain null string, then the following equation in R, viz R = Q + RP, Has a unique solution by R = QP* Assumptions –

  • The transition diagram should not have €-moves.
  • It must have only one initial state.

Using Arden’s Theorem to find Regular Expression of Deterministic Finite automata –

  1. For getting the regular expression for the automata we first create equations of the given form for all the states q1 = q1w11 +q2w21 +…+qnwn1 +€ (q1 is the initial state) q2 = q1w12 +q2w22 +…+qnwn2 . . . qn = q1w1n +q2w2n +…+qnwnn wij is the regular expression representing the set of labels of edges from qi to qj Note – For parallel edges there will be that many expressions for that state in the expression.
  2. Then we solve these equations to get the equation for qi in terms of wij and that expression is the required solution, where qi is a final state.

Example :- Solution :- Here the initial state is q1 and the final state is q1. The equations for the three states q1, q2, and q3 are as follows ? q1 = q1a + q3a + € ( € move is because q1 is the initial state) q2 = q1b + q2b + q3b q3 = q2a Now, we will solve these three equations ? q2 = q1b + q2b + q3b = q1b + q2b + (q2a)b (Substituting value of q3) = q1b + q2(b + ab) = q1b (b + ab)* (Applying Arden’s Theorem) q1 = q1a + q3a + € = q1a + q2aa + € (Substituting value of q3) = q1a + q1b(b + ab*)aa + € (Substituting value of q2) = q1(a + b(b + ab)*aa) + € = € (a+ b(b + ab)*aa)* = (a + b(b + ab)*aa)* Hence, the regular expression is (a + b(b + ab)*aa)*. GATE CS Corner Questions Practicing the following questions will help you test your knowledge. All questions have been asked in GATE in previous years or in GATE Mock Tests. It is highly recommended that you practice them.

  1. GATE CS 2008, Question 52
  2. GATE CS 2007, Question 74
  3. GATE CS 2014 (Set-1), Question 25
  4. GATE CS 2014 (Set-1), Question 65
  5. GATE IT 2006, Question 5
  6. GATE CS 2013, Question 33
  7. GATE CS 2012, Question 12

Previous Article
Next Article

Similar Reads

Designing Finite Automata from Regular Expression (Set 6)
Prerequisite: Finite automata, Regular expressions, grammar and language, Designing finite automata from Regular expression (Set 5) In the below article, we shall see some Designing of Finite Automata form the given Regular Expression- Regular Expression 1: Regular language, L1 = a(a+b)* The language of the given RE is, {aaa, aba, baa, bba} Strings
3 min read
Designing Finite Automata from Regular Expression (Set 2)
Prerequisite: Finite automata, Regular expressions, grammar and language. Designing finite automata from Regular expression In the below article, we shall see some Designing of Finite Automata form the given Regular Expression- Regular Expression 1: Φ (Phi). The language of the given RE is L1 = {} i.e, empty string. Its finite automata will be
3 min read
Designing Finite Automata from Regular Expression (Set 3)
Prerequisite: Finite automata, Regular expressions, grammar and language, Designing finite automata from Regular expression (Set 2) In the below article, we shall see some Designing of Finite Automata form the given Regular Expression. Regular Expression 1: 'ab*' ('a' followed by any number of 'b'). The language of the given RE is, L1 = {a, ab, abb
3 min read
Designing Finite Automata from Regular Expression (Set 4)
Prerequisite: Finite automata, Regular expressions, grammar and language, Designing finite automata from Regular expression (Set 3) In the below article, we shall see some Designing of Finite Automata form the given Regular Expression- Regular Expression 1: Regular language, L1 = (a+b)(a+b) The language of the given RE is, {aa, ab, ba, bb} Length o
3 min read
Designing Finite Automata from Regular Expression (Set 5)
Prerequisite: Finite automata, Regular expressions, grammar and language, Designing finite automata from Regular expression (Set 4) In the below article, we shall see some Designing of Non-deterministic Finite Automata form the given Regular Expression- As NFA can be changed to corresponding DFA. Regular Expression 1: Regular language, L1 = ((a+b)(
3 min read
Designing Finite Automata from Regular Expression (Set 7)
Prerequisite: Finite automata, Regular expressions, grammar and language, Designing finite automata from Regular expression (Set 6) In the below article, we shall see some Designing of Finite Automata form the given Regular Expression- Regular Expression 1: Regular language, L1 = b*aa(a+b)*+b*ab*aa(a+b*) The language of the given RE is- {aaa, baa,
3 min read
Designing Finite Automata from Regular Expression (Set 8)
Prerequisite: Finite automata, Regular expressions, grammar and language, Designing finite automata from Regular expression (Set 7) In the below article, we shall see some Designing of Finite Automata form the given Regular Expression- Regular Expression 1: Regular language, L1 = {an | n≥ 1} The language of the given RE is- {a, aa, aaa, ........
2 min read
Conversion of Regular Expression to Finite Automata
As the regular expressions can be constructed from Finite Automata using the State Elimination Method, the reverse method, state decomposition method can be used to construct Finite Automata from the given regular expressions. Note: This method will construct NFA (with or without ε-transitions, depending on the expression) for the given regular exp
3 min read
Designing Finite Automata from Regular Expression (Set 1)
In this article, we will see some popular regular expressions and how we can convert them to finite automata. Even number of a's : The regular expression for even number of a's is (b|ab*ab*)*. We can construct a finite automata as shown in Figure 1. The above automata will accept all strings which have even number of a’s. For zero a’s, it will be i
3 min read
Difference between Pushdown Automata and Finite Automata
Pushdown Automata: A Pushdown automata (PDA) is a finite state machine with an added stack storage. Additional stack is used in making the decision for transitions apart from input symbols and current state. It contains the following 7 tuples: Finite Automata: A Finite Automata is a mathematical model of any machine by which we can calculate the tr
2 min read