DFA to Regular Expression

Introduction

The two popular methods for converting a DFA to its regular expression are:
Introduction

  • Arden's Method
  • State Elimination Method

State Elimination Method

This method involves the following steps in finding the regular expression for any given DFA
Step 1:

Thumb Rule

The initial state of the DFA must not have any incoming edge.

If there exists any incoming edge to the initial state, then create a new initial state having no incoming edge to it.
Example:State Elimination Method

Step 2: 

Thumb Rule

There must exist only one final state in the DFA.

If there exists multiple final states in the DFA, then convert all the final states into non-final states and create a new single final state.
Example:

State Elimination Method

Step 3:

Thumb Rule

The final state of the DFA must not have any outgoing edge.

Example:State Elimination Method

Step 4:

  •  Eliminate all the intermediate states one by one.
  • These states may be eliminated in any order.

 In the end,

  • Only an initial state going to the final state will be left.
  • The cost of this transition is the required regular expression.

Note: The state elimination method can be applied to any finite automata.
(NFA, ∈-NFA, DFA etc)

Practice Problems Based on Converting DFA to Regular Expression


Problem 1: Find regular expression for the following DFA
Practice Problems Based on Converting DFA to Regular Expression

Solution:
Step 1:

  • Initial state A has an incoming edge.
  • So, we create a new initial state qi.

 The resulting DFA is
Practice Problems Based on Converting DFA to Regular Expression

Step 2:

  • Final state B has an outgoing edge.
  • So, we create a new final state qf.

The resulting DFA is
Practice Problems Based on Converting DFA to Regular Expression

Step 3: Now, we start eliminating the intermediate states.
First, let us eliminate state A.

  • There is a path going from state qi to state B via state A.
  • So, after eliminating state A, we put a direct path from state qi to state B having cost ∈.0 = 0
  • There is a loop on state B using state A.
  • So, after eliminating state A, we put a direct loop on state B having cost 1.0 = 10.

Eliminating state A, we get

Practice Problems Based on Converting DFA to Regular Expression

Step 4: Now, let us eliminate state B.

  • There is a path going from state qi to state qf via state B.
  • So, after eliminating state B, we put a direct path from state qi to state qf having cost 0.(10)*.∈ = 0(10)*

Eliminating state B, we get

Practice Problems Based on Converting DFA to Regular Expression

From here,

Regular Expression = 0(10)*

Note: In the above question,

  • If we first eliminate state B and then state A, then regular expression would be = (01)*0.
  • This is also the same and correct.

Problem 2: Find regular expression for the following DFA

Practice Problems Based on Converting DFA to Regular Expression

Solution:

Step 1:

  •  There exist multiple final states.
  • So, we convert them into a single final state.

The resulting DFA is
Practice Problems Based on Converting DFA to Regular Expression

Step 2: Now, we start eliminating the intermediate states.

First, let us eliminate state q4.

  • There is a path going from state q2 to state qf via state q4.
  • So, after eliminating state q4 , we put a direct path from state qto state qf having cost b.∈ = b.
    Practice Problems Based on Converting DFA to Regular Expression

Step 3: Now, let us eliminate state q3.

  • There is a path going from state q2 to state qf via state q3.
  • So, after eliminating state q3 , we put a direct path from state qto state qf having cost c.∈ = c.
    Practice Problems Based on Converting DFA to Regular Expression

Step 4: Now, let us eliminate state q5.

  • There is a path going from state q2 to state qf via state q5.
  • So, after eliminating state q5 , we put a direct path from state q2 to state qf having cost d.∈ = d.
    Practice Problems Based on Converting DFA to Regular Expression

Step 5: Now, let us eliminate state q2.

  • There is a path going from state q1 to state qf via state q2.
  • So, after eliminating state q2 , we put a direct path from state q1 to state qf having cost a.(b+c+d).
    Practice Problems Based on Converting DFA to Regular Expression

From here,

Regular Expression = a(b+c+d)

The document DFA to Regular Expression is a part of the Computer Science Engineering (CSE) Course Theory of Computation.
All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)
Explore Courses for Computer Science Engineering (CSE) exam
Get EduRev Notes directly in your Google search
Related Searches
mock tests for examination, DFA to Regular Expression, Summary, Objective type Questions, Viva Questions, pdf , study material, Extra Questions, DFA to Regular Expression, past year papers, Exam, Sample Paper, video lectures, Previous Year Questions with Solutions, Free, Semester Notes, DFA to Regular Expression, practice quizzes, ppt, Important questions, shortcuts and tricks, MCQs;