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

Generating regular expression from Finite Automata

Last Updated : 06 Sep, 2022
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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
Two important computational models in automata theory that are used to identify various language kinds are Pushdown Automata (PDA) and Finite Automata (FA). Both automata process strings as input and switch between states according to pre-established rules. Still, their memory capacities account for the majority of the variance. Pushdown Automata h
5 min read
Theory of Computation | Regular languages and finite automata | Question 2
What is the complement of the language accepted by the NFA shown below? (A) A (B) B (C) C (D) D Answer: (B) Explanation: Quiz of this QuestionPlease comment below if you find anything wrong in the above post
1 min read
Design finite automata from regular expressions
Prerequisite - Finite automata, Regular expressions, grammar, and language. 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 eac
3 min read
Proving elements of a finite group is finite
To Prove : The order of every element of a finite group is finite and is less than or equal to the order of the group. Proof : Suppose G is a finite group, the composition being denoted multiplicatively. Suppose a ∈ G, consider all positive integral powers of a i.e., a, a2, a3, ...... All these are elements of G, by closure axiom. Since G has a fin
2 min read
Regular Expressions, Regular Grammar and Regular Languages
As discussed in Chomsky Hierarchy, Regular Languages are the most restricted types of languages and are accepted by finite automata. Regular Expressions Regular Expressions are used to denote regular languages. An expression is regular if: ? is a regular expression for regular language ?. ? is a regular expression for regular language {?}. If a ? ?
7 min read
Practice problems on finite automata
Que-1: Draw a deterministic and non-deterministic finite automate which accept 00 and 11 at the end of a string containing 0, 1 in it, e.g., 01010100 but not 000111010. Explanation - Design a DFA and NFA of a same string if input value reaches the final state then it is acceptable otherwise it is not acceptable. NFA of the given string is as follow
2 min read
Practice problems on finite automata | Set 2
Que-1: Draw a deterministic and non-deterministic finite automate which either starts with 01 or end with 01 of a string containing 0, 1 in it, e.g., 01010100 but not 000111010. Explanation - Draw a DFA and NFA of same language whose strings only reach to the final state containing either 01 at start or at the end. If anything else is come then com
3 min read
Finite Automata with Output (Set 6)
Prerequisite: Mealy and Moore Machines, Difference between Mealy machine and Moore machine In this article, we will see some designing of Finite Automata with Output, i.e., Moore and Mealy machines. Problem: Construction of the machines that take set of all string over {0, 1} as input and produce 'A' as output if the input contains '101' as the sub
2 min read
Finite Automata with Output (Set 5)
Prerequisite: Mealy and Moore Machines, Difference between Mealy machine and Moore machine In this article, we will see some designing of Finite Automata with Output i.e, Moore and Mealy machines. Problem: Construction of the machines that take set of all string over {0, 1} as input and produce 'A' as output if the input contains '1' as the substri
2 min read
Designing Deterministic Finite Automata (Set 5)
Prerequisite: Designing finite automata In this article, we will see some designing of Deterministic Finite Automata (DFA). Problem-1: Construction of a minimal DFA accepting set of strings over {a, b} in which every 'a' is followed by a 'bb'. Explanation: The desired language will be like: L1 = {ε, abb, abbabb, bbbbabb, abbabbabbabbabbbb,
3 min read
Designing Deterministic Finite Automata (Set 9)
Prerequisite: Designing finite automata In this article, we will see some designing of Deterministic Finite Automata (DFA). Problem-1: Construction of a minimal DFA accepting a set of strings over {a, b} in which {abwa / wε{a, b}*}. Here 'w' is the substring containing alphabets over any number of 'a' and 'b' ranging from zero to infinity.
4 min read
Designing Deterministic Finite Automata (Set 6)
Prerequisite: Designing finite automata In this article, we will see some designing of Deterministic Finite Automata (DFA). Problem-1: Construction of a minimal DFA accepting set of strings over {a, b} in which anbm, where n and m is greater than or equal to 1. Explanation: The desired language will be like: L1 = {ab, aab, abb, aabb, aaabbb, aaabbb
3 min read
Finite Automata with Output (Set 3)
Prerequisite: Mealy and Moore Machines, Difference between Mealy machine and Moore machine In this article, we will see some designing of Finite Automata with Output i.e, Moore and Mealy machines. Problem: Construction of the machines that take set of all string over {a, b} as input and count number of substring 'a'. That is here we have, Ε
2 min read
Finite Automata with Output (Set 11)
Prerequisite: Mealy and Moore Machines, Difference between Mealy machine and Moore machine In this article, we will see some designing of Finite Automata with Output i.e, Moore and Mealy machines. Problem: Construction of the machines that take the binary number {0, 1} as input and produce 1's complement of that number as output. Here the assumptio
4 min read
Compound Finite Automata (FA)
Prerequisite - Finite Automata (FA) Compound FA is the resultant DFA formed after performing operation (∪, ∩, -) on given DFAs D1 and D2. D1 = (Q1, ∑, δ, q1, F1) and D2 = (Q2, ∑, δ, q2, F2) Where, Q1 and Q2: Set of finite states of DFA D1 and D2 respectively. ∑: Input alphabet contain finite number of input symbols.
2 min read
Equivalence Of F.S.A (Finite State Automata)
An Automaton is a machine that has a finite number of states. Any Two Automaton is said to be equivalent if both accept exactly the same set of input strings. Two Automaton are equivalent if they satisfy the following conditions : 1. The initial and final states of both the automatons must be same.2. Every pair of states chosen is from a different
3 min read
Designing finite automata for various operations like 1's complement, 2's complement
Transducers in Finite Automata(FA) means FA with Output.There are two types of Machines for FA with Output. 1. Mealy Machine : It is FA in which output is associated with each transition. (that means output depends on state and input).2. Moore Machine : It is FA in which output is associated with each state. (that means output depends on state only
4 min read
Designing Deterministic Finite Automata (Set 7)
Prerequisite: Designing finite automata In this article, we will see some designing of Deterministic Finite Automata (DFA). Problem-1: Construction of a minimal DFA accepting set of strings over {a, b} in which a n b m c l , where n, m and l is greater than or equal to 0. Explanation: The desired language will be like: L1 = {Îĩ, a, aa, aaa, b, bb, b
6 min read
Designing Deterministic Finite Automata (Set 2)
Prerequisite - Designing finite automata, previous article: Designing Deterministic Finite Automata (Set 1) In this article, we will see some designing of Deterministic Finite Automata (DFA). Problem-1: Construction of a DFA for the set of string over {a, b} such that length of the string |w| is divisible by 2 i.e, |w| mod 2 = 0. Explanation - The
7 min read
Designing Non-Deterministic Finite Automata (Set 4)
Prerequisite: Finite Automata Introduction In this article, we will see some designing of Non-Deterministic Finite Automata (NFA). Problem-1: Construction of a minimal NFA accepting a set of strings over {a, b} in which each string of the language contain 'a' as the substring. Explanation: The desired language will be like: L1 = {ab, abba, abaa, ..
4 min read
Designing Deterministic Finite Automata (Set 4)
Prerequisite: Designing finite automata , Designing Deterministic Finite Automata (Set 3) In this article, we will see some designing of Deterministic Finite Automata (DFA). Problem-1: Construction of a minimal DFA accepting set of strings over {a, b} in which every 'a' is followed by a 'b'. Explanation: The desired language will be like: L1 = {Îĩ,
6 min read
three90RightbarBannerImg