Theory of Computation: Unit II: Regular Expressions and Languages

Conversion of Finite Automata to Regular Expressions

Regular Expressions and Languages - Theory of Computation

The Arden's theorem is useful for checking the equivalence of two regular expression as well as in conversion of DFA to r.e.

Conversion of Finite Automata to Regular Expressions

AU Dec.-03,04,05,09,11,13,16,19, May-05,06,07,08, 12, Marks 16

The Arden's theorem is useful for checking the equivalence of two regular expression as well as in conversion of DFA to r.e. Let us see its use in conversion of DFA to r.e.

Following algorithm is used to build the r.e. from given DFA.

1. Let q1 be the initial state.

2. There are q2, q3, q4, ...qn number of states. The final state may be some qj where j ≤ n.

3. Let αji represents the transition from qj to qi

4. Calculate qj such that

qi = αji qj

If qi is a start state

to qi

qi = αji qj + ε

5. Similarly compute the final state which ultimately gives the regular expression r.

Let us solve few examples based on this algorithm.

Example 2.4.1 Construct r.e. from given DFA.

Solution: Let us write down the equations state on

q1 = q1 a + ε

Since q1 is a start state ε will be added and the input a is coming to q1 from q1 hence we write

State = Input coming to it × Source state of input

Similarly q2 = q1 a + q2 b

Let us simplify q1 first

q1 = q1 a + ε

We can re-write it as

q1 = ε + q1 a

which is similar to R = Q + RP which further gets reduced to R = QP*.

Assuming R = q1, Q = ε, p = a

We get

q1 = ε . a*

q1 = a*

ε R = R

Substituting value of q1 in q2 we get

q2 = q1 b + q2 b

q2 = a * b + q2 b

We can compare this equation with R = Q + R P assuming R = q2, Q = a*b, P = b which gets reduced to R = QP*.

q2 = a*b.b*

As R R* = R+

q2 = a*.b+

From the given DFA, if we want to find out the regular expression, we normally calculate the equation for final state. Since in the given DFA q2 is a final state and q2 = a*b+. We can conclude as the DFA represents a as regular expression.

Example 2.4.2 Represent the language accepted by following DFA.

Solution: Since there is only one state in the finite automata let us solve for q0 only.

q0 = q00 + q01 + ε

q0 = q0 (0+1) + ε

= ε . (0+1)*      R = Q + R P

q0 = (0+1)*

Since q0 is a final state, q0 represents the final r.e. as

r = (0 + 1)*

L (r) = {ε, 0,00,1,11,10,....}

L (r) = {any combination of 0 and 1}

Example 2.4.3 Construct r.e. for the given DFA. AU May-07, Marks 6

Solution: Let us build the regular expression for each state.

q1 = q10 + ε

q2 = q11 + q21

q3 = q20 + q3 (0 + 1)

Since final states are q1 and q2, we are interested in solving q1 and q2 only.

Let us see q1 first

q1 = ε + q10

Which is R = Q + R P equivalent so we can write

q1 = ε .(0)*

q1 = 0*

ε. R = R

Substituting this value into q2, we will get

q2 = 0*1 + q21

q2 = 0*1 (1)*     R = Q + R P Q P*

The regular expression is given by

r = q1 + q2 =0* + 0* 1. 1*

r = 0* + 0* 1+             1.1* = 1+

Example 2.4.4 Convert the following NFA into a regular expression. AU: Dec.-13, Marks 8


Solution: We will obtain regular expression using Arden's method.

The equations for each state are -

A = A0 + A1 + ε = A(0 + 1) + ε

B = A1

C = B (0+1)

D = C (0+1)

We will solve equation (1)

A = A (0+1) + ε

i) R = RP + Q gives R = QP* ii) εR* = R*

A = ε(0+1)* = (0+1)*

A = (0+1)* … (5)

Equation (2) becomes

B = A1 = (0+1)* 1 … (6)

Now by using equation (6) we get equation (3) as

C = B (0+1)

C = (0+1)* 1 (0+1) … (7)

Using equation (7), we get equation (4) as

D = C (0+1)

= (0+1)* 1 (0+1) (0+1) … (8)

As state C and D are final states equation (7) and equation (8) represent final regular expression.

r.e. [(0+1)* 1 (0 + 1)] + [(0+1)* 1 (0 + 1) (0 + 1)]

Example 2.4.5 Construct the regular expression corresponding to the state diagram given in the following Fig. 2.4.5. AU: May-05, Marks 10; May-08, Marks 16, Dec.-19, Marks 2

Solution: We will obtain the regular expression for the given state diagram using Arden's theorem. Let us write equations for each state.

q1 = q10 + q30 + ε being a start state, add ɛ.

q2 = q11 + q21 + q31

q3 = q20

Consider q2 first.

q2 = q11 + q21 + q31

q2 = q11 + q21 + q201      q3 = q20

q2 = q2 (1+01) + q11

R = Q + RP gives R = QP*

R = q2, Q = q11, P = (1 + 01)

q2 = q11 (1+01)*

Then put value of q2 in q3 and we get,

q3 = q11 (1+01)* 0

Now substitute value of q3 in q1

q1 = q10 + q30 + ε

q1 = q10 + q11 (1+01)* 00 + ε

q1 = q1 [0+1 (1+01)* 00] + ε

R = Q + RP gives R = QP*

R = q1, Q = ε, P = 0+1 (1+01)* 00 we get

q1 = ε [0+1 (1+01)* 00]*

q1 = (0+1 (1+01)* 00)*             ε R = R

State q1 is a final state. Hence an equation for final state becomes a regular expression for given state diagram.

The r.e. = (0+1 (1+01)* 00)*

Example 2.4.6 Obtain the regular expression for the finite automata. AU: May-12, Marks 8

Solution: We will write the equations for each state,

q1 = q1 a + ε … (1)

q2 = q2a + q1b … (2)

q3 = q2b … (3)

Solving equation (1)

q1 = q1 a + ε

q1 = ε a* = a*

R = Q + RP

gives R = QP*

and ε R* = R*

Solving equation (2) using q1 = a* we get,

q2 = q2 a + a* b

q2 = a* b a*

Solving q3 by putting q2 = a* b a*

we get

q3 = q2 b

q3 = a* ba* b

As q3 represents the final state, the equation for state q3 represents the regular expression. Hence regular expression = a* ba* b.

Review Questions

1. State and explain the conversion of DFA into regular expression using Arden's theorem. Illustrate with an example. AU: Dec.-11, Marks 16

2. Discuss the basic approach to convert from NFA to regular expression. Illustrate with an example. AU Dec.-16, Marks 16

Theory of Computation: Unit II: Regular Expressions and Languages : Tag: : Regular Expressions and Languages - Theory of Computation - Conversion of Finite Automata to Regular Expressions