0% found this document useful (0 votes)
50 views

Unit-Ii Regular Expressions and Languages Definition

Regular expressions provide a concise way to describe the languages accepted by finite state automata. There are three main operators used in regular expressions: union, concatenation, and closure. A regular expression can be converted to a non-deterministic finite automaton (NFA) that accepts the same language. The construction of an NFA from a regular expression involves separate cases for each operator in the regular expression.

Uploaded by

Ganesh Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

Unit-Ii Regular Expressions and Languages Definition

Regular expressions provide a concise way to describe the languages accepted by finite state automata. There are three main operators used in regular expressions: union, concatenation, and closure. A regular expression can be converted to a non-deterministic finite automaton (NFA) that accepts the same language. The construction of an NFA from a regular expression involves separate cases for each operator in the regular expression.

Uploaded by

Ganesh Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

UNIT-II

REGULAR EXPRESSIONS AND LANGUAGES

Definition:

A method of representing language as expression is known as “regular


expression”. That is, the language accepted by finite state automata is easily described by
simple expressions.

The operators of Regular Expressions:

 Let ∑ be a finite set of symbols.


 Let L1,L2 be set of strings in ∑*
1. Union:
 The union of two languages L and M denoted L∪M is the set of strings
that are in either L or M or both.
 For example if L={001,10,111} and M = {ε,001} then
L∪M = {ε, 10,001,111}
2. Concatenation:
 The concatenation of languages L and M is the set of strings that can be
formed by taking any string in L and concatenating it with any string in M.
 Example1: If L={001,10,111} and M={ε,001}, then L.M =
{001,10,111,001001,10001,1110001}
 Example 2: If L1={10,01} and L2 = {11,00}, then L1.L2 =
{1011,1000,0111,0100}.
3. Closure:
 Kleenex Closure or Closure of L:Li
L* = ⋃∞ 𝑖=0 Li
 Example: If L1={0,11} then
L*= L0∪L1∪L2∪...
L0={ε}
L1={0,11}
L2={00,011,110,1111}
L3={000,0110,1100,11110,1100,11011,11110,111111}
 Positive Closure of L
L+ = ⋃∞ 𝑖=0 𝐿𝑖
= L - L0
+

= L+ - {ε}
Definition:
Let ∑ be an alphabet. The regular expressions over ∑ and the sets that they denote
are defined recursively as follows:
i. ϕ is a regular expression and denotes the empty set.
ii. ε is a regular expression and denotes the set {ε}.
iii. For each a ϵ ∑, ‘a’ is a regular expression and denotes the set {a}.
iv. If r and s are regular expressions denoting the language R and S
respectively then (r+s), (rs), (r)* are regular expressions that denotes the
sets R∪S, RS and R respectively.

Example 1:

Write a regular expression for the language accepting all combination of a’s over
the set ∑ = {a}.

Solution:

 All combinations of a’s means a may be single, double, triple and so on.
 There may be the case that ‘a’ is appearing for zero times, which means a
null string. So L={ε,a,aa,aaa,aaaa,...}.
R=a*

Example 2:
Design the regular expression for the language accepting all combinations of a’s
except the null string over ∑={a}.
Solution:
R=a+
Example 3:
Design the regular expression for the language containing all the strings
containing any number of a’s and b’s.
Solution:
R = (a+b)*
Example 4:
Construct the regular expression for the language accepting all the strings which
are ending with 00 over the set ∑={0,1}.
Solution:
R = (0+1)*00
Example 5:
Write the regular expression for the language accepting the string which are
starting with 1 and ending with 0 over the set ∑={0,1}.
Solution:

R = 1(0+1)*0

Example 6:

Describe in simple English the language represented by the following regular


expression r= (a+ab)*

Solution:

L(r) = {a,ab,aab,abab,.....}

Identities for Regular Expressions:

I1 : ϕ+R=R

I2 : ϕR =Rϕ = R

I3 : λR = Rλ =R

I4 : λ* = λ

I5 : R+R=R

I6 : R*R* = R*

I7 : RR* = R*R

I8 : (R*)* = R*

I9 : λ + RR* = R* = λ + R*R

I10 : (PQ)*P = P(QP)*

I11 : (P+Q)* = (P*Q*)* = (P*+Q*)*

I12 : (P+Q)R = PR + QR and R(P+Q) = RP +RQ


Finite Automata and Regular Expressions:

Regular Expressions

Can be Can be
converted to converted to

Deterministic Finite NFA with ε-moves


Automata

Can be
Can be converted
NFA without ε-
converted to
moves
to

Equivalence of NFA and Regular Expressions:

Theorem:

Let r be a regular expression, then there exists a NFA with ε transition that accepts
L(r).

Proof:

1. Basis : (Zero Operator)


 r has zero operators means, r can be either ε or ϕ or ‘a’ for some ‘a’ in input
set ∑.
 If r= ε, then

q0

 If r= ϕ, then

q0 q1
 If r = a, then

a
q0 q1

2. Induction:
 This theorem can be true for n number of operators.
 The regular expression contains equal to or more than one operator.
 In any type of regular expression there are only three cases possible.
o Union
o Concatenation
o Closure
 Star
 Positive

Case 1: Union Case

 Let r = r1+r2 where r1, r2 be the regular expressions.


 There exists two NFA’s
M1= (Q1,∑1,δ1,q0,{F1})
M1= (Q2,∑2,δ2,q0,{F2})
 L(M1) = L(r1) means the language states by regular expression r1 is same
which is represented by M1. Similarly L(M2) =L(r2)
 Q1 represents the set of all the states in Machine M1.
 Q2 represents the set of all the states in Machine M2.
 We assure that Q1 and Q2 are totally different, that is Q1 and Q2 are disjoint.
 Let q0 be new initial state and f0 be the new final state, then we will have
M = ((Q1∪ Q2∪{ q0, f0}),(∑1∪∑2), δ, q0,{ f0})

The δ is denoted by

i. δ(q0,ε) = {Q1,Q2}
ii. δ(q0,a) = δ1(q,a) for q in Q1 – {f1} and a in ∑1 ∪ {ε}.
iii. δ(q,a) = δ2(q,a) for q in Q2 – {f2} and a in ∑2 ∪ {ε}.
iv. δ(f,ε) = δ1(f2,ε) = {f0}.
q1 M1 f1
ε
ε
Start
f0
q0

ε
ε
q2 M2 f2

Case 2: Concatenation case

 Let r = r1r2 where r1 and r2 are two regular expressions.


 The M1 and M2 denotes the two machines such that L(M1) = L(r1) and
L(M2) = L(r2).
 The construction of machine M will be M = (Q1∪Q2,∑1∪∑2,δ1,{q1},{f2}).
 The mapping function δ will be given as
o δ(q,a) = δ1(q,a) for q in Q1-{f1} and Q in ∑1∪{ε}
o δ(f1,ε) = {q2}
o δ(q,a) = δ2(q,a) for q in Q2 and a in ∑1∪{ε}

Start ε
q1 M1 f1 q2 M2 f2

 The initial state q1 by some input a, the next state will be f1.
 And on receiving ε, the transitions will be from f1 to q2 and the final state
will be f2.
 The transition from q2 to f2 will be on receiving some input b.
 Thus L(M) = ab
i.e) a is in L(M1), b is in L(M2).

Hence we prove L(M) = L(M1) . L(M2).

Case 3: Closure Case

 Let r= r1*, where r1 be a regular expression.


 The machine M1 is such that L(M1) = L(r1).
 Then construct M = (Q1∪{q0,f0},∑1,δ,q0,f0).
 The mapping function δ is given by
i. δ(q0,ε) = δ(f1,ε) = {q1,f0}
ii. δ(q,a) = δ1(q,a) for q in Q1-{f1} and a is in ∑∪{ε}.
 The machine M will be
ε

Start ε ε
q0 q1 M1 f1 f0

ε
 The machine M1 shows that from q0 to q1, there is a transition on receiving
ε.
 Similarly from q0 to f0 on ε, there is a path.
 The path exists from f1 to q1 a back path.
 Similarly a transition from f1 to f0 final state on receiving ε.
 Thus one can derive ε,a,aa,aaa,... for the input a.
Thus L(M) = L(M1)* is proved.

Construction of NFA from Regular expression


Example 1:
Construct a NFA for the regular expression 01.

Start 0 1
q0 q1 q2

Example 2:

Construct a NFA for the regular expression a*

ε
Start
q0 q1 q2 q3
ε a ε

ε
Example 3:

Construct a NFA for the regular expression a+.

Start
q0 q1 q2 q3
ε a ε

Example 4:

Construct a NFA for the regular expression ba+.


ε

Start ε b
q0 q1 q2 q3 q4 q5
ε a ε

Example 5:

Construct a NFA for the regular expression ba*.


ε

Start b ε ε
q0 q1 q2 q3 q4
a

Example 6:

Construct a NFA for the regular expression b+ba*.

b ε
q1 q2
ε
ε
Start ε ε
q6 q7 q8 q9
q0 q5
a

ε ε ε
q3 q4
b
Example 7:

Construct a NFA for the regular expression (0+1)*.

0
q2 q3 ε
ε
Start ε ε
q0 q1 q6 q7
ε ε
1
q4 q5

Exercise Problems:

Construct a NFA for the following regular expressions:

i. R = (01+10)*
ii. R = 0(00)*
iii. R = (01+2*)1
iv. R = (a(aa)*b+ab*a)*

Conversion of Finite Automata to Regular Expressions:

Theorem:

The regular expression can also be represented by its equivalent Deterministic


Finite Automata.

Formula:

The formula for getting the language rijk is given by the regular expression:

rijk = (rikk-1)( rkkk-1)*( rkjk-1)+( rijk-1)


Problems based on Finite Automata to Regular Expression Conversion:

Example 1:

Construct the regular expression for the automata given below:

Start 0
q0 q1

Solution:

rijk = (rikk-1)( rkkk-1)*( rkjk-1)+( rijk-1)

k=0

r11(0) = ε

r12(0) = 0

r21(0) = ϕ

r22(0) = ε

k=1 i=j=k=1

r11(1) = r11(0) (r11(0))*( r11(0))+( r11(0))

= ε (ε)* ε + ε

= ε+ε

r11(1) = ε

r12(1) = r11(0) (r11(0))*( r12(0))+( r12(0))

= ε (ε)* 0 + 0

= 0+0

r12(1) = 0

r21(1) = r21(0) (r11(0))*( r12(0))+( r22(0))

= ϕ. ε*. ε + ε
= ϕ+ϕ

r21(1) = ϕ

r22(1) = r21(0) (r11(0))* ( r12(0)) + ( r22(0))

= ϕ. ε*.0 + ε

= ϕ.0 + ε

= ϕ+ε

r22(1) = ε

 Now let us compute for final state which denotes the regular expression.
 R12(2) will be computed, because there are total 2 states and final state is q2,
whose start state is q1.
r21 (2) = (r12 (1)) (r22 (1))*(r22 (1)) + (r12 (1))
= 0. (ε)*. ε + 0
= 0+0
(2)
r21 = 0 which is a final regular expression.
Example 2:

Construct the regular expression from the given automata:

Start 0
q1 q2

Solution:

rijk = (rikk-1)( rkkk-1)*( rkjk-1)+( rijk-1)

k=0

r11 (0) = ε

r12 (0) = 0

r21 (0) = ϕ

r22 (0) = 1+ε


k=1 i=j=k=1

r11 (1) = r11(0)( r11(0))*( r11(0)) + (r11(0))

= ε (ε*) ε + ε

r11 (1) = ε

= r11 (0) (r11 (0))* (r12 (0)) + (r12 (0))

= ε (ε*) 0 + 0

= ε. 0 + 0

= 0+0

r12 (1) = 0

r21 (1) = r21 (0) (r11 (0))* (r11 (0)) + (r21 (0))

= ϕ (ε)* ε + ϕ

= ϕ+ϕ

r21 (1) = ϕ

r22 (1) = r21 (0) (r11 (0))* (r12 (0)) + (r22 (0))

= ϕ (ε)*. 0 + (1+ε)

= ϕ + (1+ε)

r22 (1) = 1+ε

 Now let us compute for final state, which denotes the regular expression.
 Here
o Start state i = 1
o Final state j = 2 (q2)
o Total number of states, k = 2. (q1,q2)

r12 (2) = (r21 (1)) (r22 (1))* (r22 (1)) + (r21 (1))

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

= 0.1* + 0

r12 (2) = 01* + 0

This is a final regular expression. This is a language beginning with 0 and followed by
any number of 1’s.

Exercise Problem:

Start 0 1
q1 q2 q3

0,1

Conversion of ε-NFA into DFA:

Steps:

Step 1:

Find the ε-closure of the state q0 from the constructed ε-NFA that is, from state
q0, ε-transition to other states is identified as well as ε-transitions from other states are
identified and combined as one set (new state).

Step 2:

Perform the following steps until there are no more new state has been
constructed.

i. Find the transition of the given regular expression symbols over ∑ from the
new state, that is move(new state, symbol)
ii. Find the ε-closure of move(new state, symbol)

Example:

Construct the DFA for the regular expression (a/b)*ab.

Solution:
ε regular expression is as follows:
Equivalent ε-NFA for the given

a
3 4 ε
ε
Start ε ε a b
1 2 7 8 9 10
9
ε
ε
5 6
b

ε -closure (1) = {1, 2, 3, 5, 8} ----------------- A

Move (A,a) = {4,9}

Move (A,b) = {6}

ε -closure ({4, 9}) = {4, 7, 8, 2, 3, 5, 9} = {2, 3, 4, 5, 7, 8, 9} ------------- B

Move (B,a) = {4,9}

Move (B,b) = {6,10}

ε -closure ({6}) = {6,7,8,2,3,5} = {2,3,5,6,7,8} ---------------- C

Move (C,a) = {4,9}

Move(C,b) = {6}

ε -closure ({6, 10}) = {6,7,8,2,3,5,10} = {2,3,5,6,7,8,10} ----------------- D

Move (D,a) = {4,9}

Move (D,b) = (6)

Transition Table:

State Input
a b
->A B C
B B D
C B C
*D B C
Equivalent DFA is
a

Start a b
A B C

a
a

b
b
D

Examples:

1. (aa* | bb*)
2. (a|b) (a|b) (a|b)
3. (a|b)*abb(a|b)*
4. 011(0|1)*
5. 4(0|123)*
6. (12|543)11
7. (a|b)* (a|b)*
8. (0|1)011(0|1)*
Basic formula on regular expression:
1. (ε+1)* = 1*
2. 1*(ε+1) = 1*
3. (ε+1)+1* = 1*
4. 0+1*0 = 1*0
5. 0+01* = 01* = 0(ε+1*)
6. ε+00* = 0*
ε+0+ = 0*
7. (1+0)* = (1*0*)*
8. ϕ 0 = ϕ
9. ϕ + 0 = 0
10. ϕ* = ε
11. 11* ≠ 1*
12. 1*1 ≠ 1*
13. (01)* ≠ 0*1*
14. ε0 = 0
15. (01)*0 = 0(10)*
16. (0*1*)0* = (0+1)*
17. RR* = R+
18. ε+R+ = R*
19. 00* = 0* (0+) 00*=0+
20. RR* = R*

Convert the given DFA to Regular Expression:

Start 0 1
q1 q2 q3

0,1

Solution:

i = initial state = q1 = 1

j = final state q2, q3 = 2, 3

k = number of states = 3

Rij (k) = (Rikk-1)( Rkkk-1)*( Rkjk-1)+( Rijk-1)

The result of the regular expression is

R12(3) + R13(3)

k = 0:

R11 (0) = ε
R12 (0) = 0

R13 (0) = 1

R21 (0) = 0

R22 (0) = ε

R23 (0) = 1

R31 (0) = ϕ

R32 (0) = 0+1

R33 (0) = ε

k = 1:

Rij (k) = (Rikk-1)( Rkkk-1)*( Rkjk-1)+( Rijk-1)

R11 (1) = R11 (0) + R11 (0) (R11 (0))* R11 (0)

= ε + ε ε* ε

R11 (1) = ε

R12 (1) = R12 (0) + R11 (0)( R11 (0))* R12 (0)

= 0+εε*0

= 0+0

R12 (1) = 0

R13 (1) = R13 (0)+ R11 (0) (R11 (0)) *R13 (0)

= 1 + ε ε*1 = 1 + 1

R13 (1) = 1

R21 (1) = R21 (0)+ R21 (0) (R11 (0))* R11 (0)

= 0 + 0 ε* ε = 0+ 0

R21 (1) = 0

R22 (1) = R22 (0)+ R21 (0)( R11 (0))* R12 (0)
= ε + 0 ε* 0 = ε + 00

R22 (1) = 00

R23 (1) = R23 (0)+ R21 (0)( R11 (0))* R13 (0)

= 1 + 0 ε* 1 = 1 + 01

R23 (1) = 1 + 01

R31 (1) = R31 (0)+ R31 (0)( R11 (0))* R11 (0)

= ϕ + ϕ ε* ε = ϕ + ϕ

R31 (1) = ϕ

R32 (1) = R32 (0)+ R31 (0)( R11 (0))* R12 (0)

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

R32 (1) = 0 +1

R33 (1) = R33 (0)+ R31 (0)( R11 (0))* R13 (0)

= ε + ϕ ε* 1 = ε + ϕ

R33 (1) = ε

k=2:

R11 (2) = R11 (1) + R12 (1) (R22 (1))* R22 (1)

= ε +0(00)*0 = ε + (00)* [∴RR* = R*]

R11 (2) = (00)*

R12 (2) = R12 (1) + R12 (1) (R22 (1))* R22 (1)

= 0 + 0 (00)* 00

= 0 + 0 (00)* [∴R+RR* = RR*]

R12 (2) = 0(00)*

R13 (2) = R13 (1) + R12 (1) (R22 (1))* R23 (1)

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

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

= 1 + 0(00)*01

= 1 + 00(00)* 1

= 1 + (00)*1 [∴(ε + 0*0) = 0*, 1(ε + (00)* = 1(00)*]

= 1+ (ε + 00*)

R13 (2) = 100*

R21 (2) = R21 (1)+ R22 (1) (R22 (1) )* R21 (1)

= 0 + 00 (00)* 0

= 0 + (00)* 0

= 0 (ε + (00)*)

R21 (2) = 0 (00)*

R22 (2) = R22 (1)+ R22 (1)( R22 (1))* R22 (1)

= 00 + 00 (00)* 00

= 00 (ε + 00 (00)*)

= 00 (ε + 00)*) = 00(ε + (00)*)

= 00 (00)*

R22 (2) = (00)*

R23 (2) = R23 (1)+ R22 (1)( R22 (1))* R23 (1)

= (1+01) + 00 (00)* (1 + 01)

= (1+01) + (00)* (1 + 01)

= (1+01) (00)*

= 1 (ε + 0) (00)*

= 10(00)*
= 1(00)*

R23 (2) = 10*

R31 (2) = R31 (1)+ R32 (1)( R22 (1))* R21 (1)

= ϕ + (0+1)(00)* 0

R31 (2) = (0+1)(00)* 0

R32 (2) = R32 (1)+ R32 (1)( R22 (1))* R22 (1)

= (0 +1) + (0+1) (00)* 00

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

R32 (2) = (0 +1) + (00)*

R33 (2) = R33 (1)+ R32 (1)( R22 (1))* R23 (1)

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

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

R33 (2) = ε +(0+1)(00)*10

Now the result of the regular expression is

R = R12 (3)+ R13 (3)

R13 (3) = R13 (2)+ R13 (2)( R33 (2))* R33 (2)

= 10* + 10* ((0 + 1) 0*1)*((0+1)0*1)

= 10* + 10* ((0 + 1) 0*1)*

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

R13 (3) = 10*((0 + 1) 0*1)*

R12 (3) = R12 (2) + R13 (2) ( R33 (2))* R32 (2)

= 0(00)* + 10 ((0+1)0*1)((0+1)(00)*)

= 0(00)* + 10 ((0+1)0*1)*((0+1)(00)*)

R12 (3) = 0(00)* + 10* ((0+1)0*1)*((0+1)(00)*)


R = R12 (3)+ R13 (3)

R = 0(00)* + 10* ((0+1)0*1)*((0+1)(00)*) + 10*((0 + 1) 0*1)*

R = 0(00)* + 10*[((0+1)0*1)*((0+1)(00)*)]

Theorem:

The regular expression can also be represented by its equivalent deterministic


finite automata.

Proof:

 Let L be the set of the language accepts by the DFA.


 The DFA can be denote by M = ({q1,q2,...qn},Σ,δ,q,F)
 Let
 rijk denotes the set of the string x such that δ(qi,x) = qj.
 The qi and qj indicates some state to target state respectively.
 The inputs are going through the states of finite automata means that with
some input entering into the states and coming out of it.
 The value of k is always less than i or

 The rijk is denoted by


rijk = rikk-1 (rkkk-1)* rkjk-1 ∪ rijk-1
𝛼 | 𝛿 (𝑞𝑖, 𝑎) = 𝑞𝑗, 𝑖𝑓 𝑖 ≠ 𝑗
rijk = {
𝛼 | 𝛿 (𝑞𝑖, 𝑎) = 𝑞𝑗 ∪ {ɛ}, 𝑖𝑓 𝑖 = 𝑗
 We have to show that for each i,j,k there exists a regular expression rijk denoting
the language rijk .
 Proof by induction:
Basis:
k=0
 The rij0 is a set of strings each of which is either ɛ or a sin gle
symbol.
 The rij0 is based on δ(qi,a) = qj.
 The rij0 denotes the set of such a's if there is no such 'a' then it will be
taken as ϕ.
 If i=j, all of the a's and ɛ will be the set.

Induction:
The formula for getting the language rijk is given by regular expression

rijk = rikk-1 (rkkk-1)* rkjk-1 ∪ rijk-1 which completes the induction.

 To get the final regular expression, we have to simply get the language rijn , where
'i' indicates start state, 'j' indicates the final state and 'n' will be number of items.
 If there are 'p' number of paths, leading to final state by
rijk = rij1n + rij2n +...+ rijpn
where F is a set of final state.
F = {qj1,qj2,...qjp}
Arden's method for converting DFA to Regular expression:
R =Q + RP i.e) R = QP*
Q+ RP = Q + (QP*)P
= Q (ɛ + P*P)
= QP*
=R
Algorithm:
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 transition from qj to qi.
4. Calculate qi such that qi = αjiqi
If qi is a start state qi = αjiqj + ɛ.
5. Similarly compute the final state which ultimately gives the regular expression.
Example 1:
Construct regular expression from the given DFA.
0 1
Start 1
q1 q2

0
0
q3

Solution:
q1 = q10 + q30 + ɛ ------------------- ①

q2 = q21 + q11 + q31 ------------------- ②

q3 = q20 ---------------------------③

substitute ③ to ②

q2 = q21 +q11 + q201

q2 = q2(1+01) + q11 ∴ Q + RP = QP*

R P Q

q2 = q11 (1+01)* --------------------------- ④

substitute ④ to ①

q1 = q10 + q200 + ɛ

= q10 + q11 (1+01)*00 + ɛ

q1 = q1 [ 0 + 1 (1 + 01)*00] + ɛ ∴ Q + RP = QP*

R P Q

= ɛ (0 + 1 ( 1 + 01)* 00)* ∴ɛ.R=R

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

Final regular expression is

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

Example 2:
b
a
Start b a
q1 q2 q3

Solution:

q1 = q1 a + ɛ ----------------------------------> ①

q2 = q1 b + q 2 b ----------------------------------> ②
we can rewrite ① as

q1 = ɛ + q1 a ∴ Q + RP = QP*
Q=ɛ
R = q1
P=a
q1 = ɛ a*

q1 = a* ∴ ɛ.R = R

Substitute value of q1 in ②, we get

q2 = q1 b + q 2 b

q2 = a*b + q2b

q2 = a*b + q2b R = Q + RP →QP*

∴ = Q + RP

= a*bb* ∴ b.b* = b+

q2 = a*b+

Final regular expression is a*b+

Exercise Problems:

1. Construct regular expression for the given DFA.

0 1 0,1

Start 1 0
q1 q2 q3

2. Construct regular expression for the given DFA.


1

Start
q1 q2
0

1 0

q3 q4
1
3. Construct regular expression for the given DFA.

a,b

q2
b

Start
q1

a
q3

a,b

Minimization of DFA: ( Myhill-Nerode Theorem) or Table filling algorithm

Minimize the DFA as given below:

0
1

Start 0 1 0
A B C D

0 1
1 0 1
0

1 1 0
E F G H

0
Solution:

Transition Table

Input
State
0 1
→A B F
B G C
*C A C
D C G
E H F
F C G
G G E
H G C
Construct a table as follows:

 Mark X for distinguishable state.


 Here c is the final state.

B X
C X X
D X XX
E X
X X
FX XX X
GX X
X X X X
HX X X X X X
A B C D E F G
A = E, B = H, D = F are equivalent.
Transition Table: Minimized transition table:

Input
State
0 1
→A B F
B G C
*C A C
D C G
E H F
F C G
G G E Input
H G C State
0 1
→A B F
B G C
*C A C
D C G
G G A
Minimized DFA:
0

Start 0 1
A B C 1

1 1 0

D G
1 0
0

Example 2:

Minimize the given DFA.

Input
State
0 1
→A B A
B A C
C D B
*D D A
E D F
F G E
G F G
H G D
Solution:

B X
C X X
D X X X
E X X X
F X X X X
G X X X X X
H X X X X X X
A B C D E F G
Step 1:

(A,D), (B,D), (C,D), (D,H), (D,G), (D,F), (D,E) are distinguishable.

Step 2:

All he final state combinations are as follows:


0
AC → BD = X then AC → X
0
AE → BD = X then AE → X
1 AD = X
AH → then AH → X
0 AD = X
BC → then BC → X
0 AD = X
BE → then BE → X
1 CD = X
BH → then BH → X
1 DG = X
CF → then CF→ X
1 BD = X
CH → then CH→ X
0
CG → DF = X then CG→ X
0 DG = X
EF → then EF→ X
0
EG → DF = X then EG → X
0 DG = X
EH → then EH → X
1 ED = X
FH → then FH → X
1 GD = X
GH → then GH → X

Step 3:

All non accepting combinations (no same stae)


0
AB → BA, AB → AC = X then AB → X

AF → BG, AF→AE = X then AF → X

AG → BF, AG → AG then don't mark as X

BF → AG, BF → CE then don't mark as X

BG → AF, so mark BG as X

FG → EG then mark FG as X.

Step 4:

Equivalent sates are

(AG), (BF),(CE), so A = G, B = F, C = E.

Minimized DFA Table:

Input
State
0 1
→A B A
B A C
C D B
*D D A
H A D

Minimized DFA:

Start 0 1
A,G B,F C,E
0 1

1
0 0

D H
1

0
Steps in Pumping Lemma:

1. Assume the given language is a regular language.


2. Calculate the number of states in DFA.
3. Take one string 'w' and calculate the length of the string.
4. If the length of the string, |w| ≥ n, we can break it into three strings.
5. w=xyz or z=uvw, such that
i. |xy| ≤ n
ii. y ≠ ε (or) |y| > 0 (or) |y| ≥ 1
iii. for all k ≥ 0, the string xykz is also in L.
Problems on Pumping Lemma:
1. Prove that L= {an | n=i2, i ≥ 1} (or) L={0n | n= i2, i ≥ 1} is not regular.
Solution:
Step 1:
Assume that the language L is a regular language.
Step 2:
The number of states are L= {an | n=i2, i ≥ 1}. That is the number of states are 'n'.
Step 3:
Take any string 'w', let w=an where n=i2. The length of the string |w| = n.
Step 4:
|w| ≥ n
Therefore n2 ≥ n, we can break it into three strings as in step 5.
Step 5:
w = an
let w=xyz
xy = am
y = aj
𝑤 an
z= = = an-m
𝑥𝑦 am
to check the assumptions,
xyz = aman-m = am+n-m = an
xy z
So our assumption is true.
i. |xy| ≤ n => |am| ≤ n => m ≤ n
ii. |y| ≠ ε => |y| 1 => |aj| ≥ 1.
So the above two conditions are true.
xykz = xyyk-1z = am(aj)k-1an-m = amaj(k-1)an-m
k=0, xy0z = amaj(0-1)an-m = ama-jan-m =an-j ≠ an.
k=1, xy1z = amaj(1-1)an-m = ama0an-m =an = an.
k=2, xy2z = amaj(2-1)an-m = ama1an-m =aj+n ≠ an.
Since k=0,2, we have the string that does ot belongs to the complete L, so L= {an | n=i2, i
≥ 1} is not regular.

2. Show that the language L= {anbn | n ≥ 1} is not regular.


Solution:
i. Let us assume that the given language 'L' is regular.
ii. The number of states of L= {anbn | n ≥ 1} is n+n=2n.
iii. Take one string 'w' and calculate the length of he string w= anbn
iv. If the length of the string |w| ≥ n, then 2n ≥ n.
v. So we can break the string into tree parts as follows:
W=xyz, let w= aibi
Let us make the assumptions that,
w= aibi
xy = am
y = aj
𝑤
z=
𝑥𝑦
aibi
= am
= aibia-m
z = ai-mbi
To check the assumptions,
amai-mbi
xyz = xy z
= aibi
So our assumption is correct.
i. |xy| ≤ n. Here |am| ≤ n ==> m ≤ n.
ii. y ≠ ε (or) |y| ≥ 1. Here aj ≠ ε (or) |aj| ≥1 ==> j ≥ 1.
Since both the conditions are true for all k ≥ 0, the string xykz ia also in L.
xykz = xyyk-1z
= am(aj)k-1ai-mbi
= am+j(k-1)+i-mbi
xykz = aj(k-1)+ibi
put k=0, xykz = aj(0-1)+ibi = a-j+ibi = ai-jbi ≠ aibi
put k=1, xykz = aj(1-1)+ibi = aibi = aibi.
Put k=2, xykz = aj(2-1)+ibi =aj(1)+ibi = ai+jbi ≠ aibi.
When k=0,2, we have the string that does not belong to the language L. So the language
L= {anbn | n ≥ 1} is not regular.
Exercise problems:
1. Show that L= {0n10n | n ≥ 1} is not regular.
2. Show that L= {0n | n is a perfect square} is not regular.
3. Prove that the set of strings of 0's and 1's that are of the form wwR, that is some
sting followed by its reverse such that L= { wwR | w ϵ {0,1}} is not regular.
4. Show that L= {1k | k=n2, n ≥ 1} is not regular.
5. Prove that the set of strings of 0's and 1's such that L= {ww | w ϵ {0,1}} is not
regular.
Equivalence of Regular Languages:
 The table filling algorithm gives us an easy way to test if two regular languages
are the same.
 Suppose L and M are each represented in some way, for example, one by a regular
expression and one by an NFA.
 Convert each representation to a DFA.
 Now imagine one DFA whose state are the union of the states of the DFA’s for L
and M.
 Test if the start states of the two original DFA’s are equivalent using the table
filling algorithm.
 If they are equivalent then L=M, and if not, then L ≠ M.

Problems:

1. Verify whether the finite automaton machine M1 and M2 shown below are
equivalent over the alphabet {0, 1}.
Finite Automata M1:

0
1
1
Start
A B
0
Finite Automata M2:
0

Start 0
C D

0 1
1

E
Solution:

Step 1: Construct the table using table filling algorithm by combining the state of both the
finite automata M1 and M2. (For same final state don’t mark as X).

B X
C X
D X
EX X X
A B C D
0
BE → AC don’t mark. (Mark all the accepting state).

Step 2:

Do not compare the accepting with non accepting state. So (A,B) (A,E) (B,C)
(B,D) (C,E) (D,E) are not equivalent state.

Step 3:

(Non accepting states)


0 AC, therefore don’t mark.
BE →

Step 4:

Here the start state of M1 is A and the start state of M2 is C. So (AC) is A≡C, then
M1 and M2 are equivalent.

Example

Verify whether the finite automata machine M1 and m2 shown below are equivalent over
the alphabet {a, b}.

Finite Automata M1:

Input
State
a b
→*q1 q1 q2
q2 q3 q1
q3 q2 q3

Finite Automata M1:

Input
State
a b
→*q4 q4 q5
q5 q6 q4
q6 q7 q6
q7 q6 q4

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy