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

Regular Language

Uploaded by

swayamvhatkar6
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)
74 views

Regular Language

Uploaded by

swayamvhatkar6
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/ 43

Theory of Computation

Regular Expression
Contents: Introduction to Regular expressions, Equivalence of Regular Expressions and
Finite Automata, Arden’s theorem, Pumping Lemma for regular language, Closure and
decision properties for regular language, Myhill-Nerode theorem, application of regular
expression

The languages accepted by finite automata are represented by simple expression called
regular expression. A regular expression represents regular set.
Formal Definition:
A regular expression over ∑ is recursively defined as follows.

➢ The empty set ( ) , the empty string (є) are Regular expression over ∑.
➢ Every letter a ε Σ is a regular expression over Σ.

➢ If R1 and R2 are regular expressions over Σ, then following are Regular expressions

• (R1+R2) : ‘+’ indicates alteration or parallel path. LR1ULR2.


• (R1⋅R2) : the operation‘.’ denotes concatenation (series). LR1.LR2.
• (R1)*: ‘*’ denotes closure. LR1*
➢ Regular expressions are only those that are recursively obtained by applying rules.

Languages Generated by a regular expressions:

Regular expressions Language generated


a {a}
b {b}
a+b or a|b {a,b}
a.b {ab}
a* { є,a,aa,aaa........}
a+ { a,aa,aaa........}
(ab)* { є,ab,abab,........}
(a+b)* { є,a,b,aa,ab,ba,bb,........}

The table shows some examples of regular expressions and the language corresponding to these
regular expressions.

Regular expressions Meaning

(a+b)* Set of strings of a’s and b’s of any length including the NULL string.
Theory of Computation

ab(a+b)* Set of strings of a’s and b’s starting with the string ab.

(a+b)*abb Set of strings of a’s and b’s ending with the string abb

a*b*c* Set of string consisting of any number of a’s followed by any number
of b’s followed by any number of c’s.

(a+b)*aa(a+b)* Set of strings of a’s and b’s having a sub string aa.

a+b+c+ Set of string consisting of at least one ‘a’ followed by string consisting
of at least one ‘b’ followed by string consisting of at least one ‘c’.

aa*bb*cc* Set of string consisting of at least one ‘a’followed by string consisting


of at least one ‘b’ followed by string consisting of at least one ‘c’.
(a+b)* (a + bb) Set of strings of a’s and b’s ending with either a or bb

(aa)*(bb)*b Set of strings consisting of even number of a’s followed by odd


number of b’s

a (a+b)* b Set of strings starting with a and ending with b.

(0+1)*000 Set of strings of 0’s and 1’s ending with three consecutive zeros(or
ending with 000)

0(0+1)*1+1(0+1)*0 Set of strings of 0’s and 1’s that start and end with different symbol.

(0+1)*(011+111) Set of strings of 0’s and 1’s that ending with 011 or 111.

(0+1)*010(0+1)* Set of strings of 0’s and 1’s having a sub string 010.

Some More Examples:


1] Give a regular expression to accept a language consisting of strings which begin and end with
different letter over ∑={x,y,z}
→ r= x(x+y+z)*y + x(x+y+z)*z + y(x+y+z)*x + y(x+y+z)*z + z(x+y+z)*x + z(x+y+z)*y

2] Give a regular expression to accept a language consisting of strings of 0’s and 1’s beginning
with ‘1’ and not having two consecutive ‘0’s.
→ L(r)={ є,1,10,11,101,110,1010.........}
r=(1+10)*
3] Give a regular expression to accept a language containing all combinations of 0’s and 1’s not
having two consecutive ‘0’s.
Theory of Computation

→ r=(1+10)* + 0(1+10)*
r=(0+ є) (1+10)*
4] Give a regular expression to accept a language consisting of strings of a’s and b’s of even length.
→String of a’s and b’s of even length can be obtained by the combination of the strings aa,
ab, ba ,bb. The language may even consist of an empty string denoted by є.
So, the regular expression can be of the form
r= (aa + ab + ba + bb)*
5]Obtain a regular expression to accept a language consisting of strings of a’s and b’s of odd length.
→String of a’s and b’s of odd length can be obtained by the combination of the strings aa, ab,
ba and bb followed by either a or b.
So, the regular expression can be of the form
r= (aa + ab + ba + bb)* (a+b)
Regular Expressions and Finite Automata:
Every Regular Expression R can b recognized by a transition system means there exiats a
path from initial state to the final state with a transition value,so there is a close relationship
between Regular Expressions and Finite Automata shown in figure below.

Regular Expression

DFA NFA with € moves

NFA without € moves

Figure: Equivalence of Regular Expressions and Finite Automata

Equivalence of Regular Expressions and Finite Automata:


As we know, Regular expressions represent the language accepted by Finite automata. So for
every Regular expressions there exist finite automata accepting the same language.

For any regular expression, it is first converted to the NFA with є-moves then this NFA with
є-moves is converted to NFA without є-moves which in turn is converted to DFA. Another
approach is, directly convert NFA with є-moves to DFA.

Guidelines For Converting NFA with moves to NFA without ɛ moves:

• The no of states remain the same.


• Start state remain the same.
• Final state remains the same.
Theory of Computation

• If the € closure of the start state or any other state contains a final state then make that
state also a Final state.

Rules for converting RE to NFA with € moves:

ɛ

0
0

0.1

0+1

0*

0+

Example:
1] Construct NFA with € moves for the regular expression a*+b*.
Solution:

Step1: a*
Theory of Computation

Step2: b*

Step3:a*+b*

2] Construct NFA with € moves for the regular expression (0|1)*01.


Solution:

Step1: 0+1

Step2:(0+1)*

Step3:01

Step4:(0+1)*01
Theory of Computation

3] Construct NFA with € moves for the regular expression 1(0|1)*. Dec-2009 (5 Marks)
Solution:

Step1: 0+1

Step2:(0+1)*

Step3:1(0+1)*

4]Convert following Regular Expressions to NFA with €


R=(1.(00)*.1+01*.0)* Nov-2011

Step1:1(00)*

Step2:1(00)*1
Theory of Computation

Step3:01*.0

Step4: (1(00)*1+01*.0)*

01*.0

5]Give NFA for the following Regular Expressions . May- 2013


R=(a+bb)*(ba*+ ɛ )
Solution:

Step1: (a+bb)

Step2:(a+bb)*
Theory of Computation

Step3:(ba*+ ɛ)

Step4: (a+bb)*(ba*+ ɛ)

(ba*+€)

6]Costruct NFA with € for following Regular Expressions


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

Step1: (0+1)*

(ba*+€)

Step2: (0+1)*10

(ba*+€)

Step3: (00)*

(ba*+€)
Theory of Computation

Step4: (11)*

(ba*+€)

Step4:((0+1)*10+(00)*(11)*)*

(ba*+€)

7] Convert following Regular Expressions to minimized DFA May-2014 (5 Marks)


R=(00+11)*(10)*
Solution:
Step1: 00+11

Step2: (00+11)*
Theory of Computation

Step3: (10)*

Step4: (00+11)*(10)*

➢ Conversion to DFA: Following table shows the equivalent DFA for the above NFA.

X y= є - closure of (X) δ (y,0) δ (y,1)

A →{1}* {1,2,3,7,12,13,14,18} {4} {8,15}

B {4} {4,5} {6} -

C {8,15} {8,9,15,16} {17} {10}

D {6}* {6,11,12,13,14,18,2,3,7} {4} {8,15}

E {17}* {17,14,18} - {15}

F {10}* {10,11,12,13,14,18,2,3,7} {4} {8,15}

G {15} {15,16} {17} -


Theory of Computation

∑ ∑
0 1 0 1
Q Q
→A* C →A* B C
B

B D - B A -

C E F C E A

D* B C E* - G

E* - G G E -

F* B C

G E -

As we see from above table (A,D,F)merged

8] Convert following Regular Expressions to May-2014 (10 Marks)


minimized DFA
R=(11+01)*
Solution:
Step1: 11+01

Step2: (11+01)*

X y= є - closure of (X) δ (y,0) δ (y,1)

A →{1}* {1,2,3,7,12} {8} {4}

B {8} {8,9} - {10}


Theory of Computation

C {4} {4,5} - {6}

D {10}* {2,3,7,10,11,12} {8} {4}

E {6}* {2,3,6,7,11,12} {8} {4}

∑ ∑
Q 0 1 0 1
Q
→A* B C →A* B C

B - D B - A
C - E C - A
D* B C

E* B C

As we see from above table (A,D,E) merged

9] Convert following Regular Expressions to minimized DFA May- 2010


R=(ab/ba)*aa(ab/ba)*
Solution:
Step1: (ab+ba)*

Step2: aa

Step3: (ab/ba)*aa(ab/ba)*

➢ Conversion to DFA: Following table shows the equivalent DFA for the above NFA.
Theory of Computation

X y= є - closure of (X) δ (y,a) δ (y,b)

A →{1} {1,2,3,7,12,13} {4,14} {8}

B {4,14} {4,5,14,15} {16} {6}

C {8} {8,9} {10} -

D {6} {6,11,12,13,2,3,7} {4,14} {8}

E {10} {10,11,12,13,2,3,7} {4,14} {8}

F {16}* {16,17,18,19,23,28} {20} {24}

G {20} {20,21} - {22}

H {22}* {22,27,28,18,19,23} {20} {24}

I {24} {24,25} {26} -

J {26}* {26,27,28,18,19,23} {20} {24}

∑ ∑
a b a b
Q Q
→A B C
→A B C
B F D
B F A
C E -
C A -
D B C
F* G I
E B C
G - F
F* G I
I F -
G - H
H* G I
I J -
J* G I

we see from above table (A,D,E)(F,H,J) merged

10] Convert following Regular Expressions to minimized DFA


R=(a+b)*aba(a+b)*
Solution:
Theory of Computation

Step1: (a+b)*

(ba*+€)

Step2: aba

(ba*+€)

Step3: (a+b)*aba(a+b)*

(ba*+€)

➢ Conversion to DFA: Following table shows the equivalent DFA for the above NFA.

X y= є - closure of (X) δ (y,a) δ (y,b)

A →{1} {1,2,3,5,8,9} {4,10} {6}

B {4,10} {2,3,4,5,7,8,9,10, ,11} {4,10} {6,12}

C {6} {2,3,5,6,7,8,9 } {4,10} {6}

D {6,12} {6,7,8,9,2,3,5,12,13} {4,10,14} {6,12}

E {4,10,14}* {4,7,8,9,10,2,3,5,11,14,15,16,17,19,22} {4,10,18} {6,12,20}

F {4,10,18}* {4,7,8,9,10,2,3,5,11,18,21,22,16,17,19} {4,10,18} {6,12,20}

G {6,12,20}* {6,7,8,9,2,3,5,12,13,20,21,22,16,17,19} {4,10,14,18} {6,12,20}

H {4,10,14,18}* {4,7,8,9,10,2,3,5,11,14,15,16,17,19,22,18,21} {4,10,18} {6,12,20}


Theory of Computation

a b
Q

→A B C Q a b
B B D
→A B A
C B C
D E D B B C
E* F G
D E D
F* F G
E* E G
G* H G G* E G
H* F G
(2)

(1)
As we see from above table (A,C)(E,F,H)are merged.again in another table (E,G) is merged.


a b
Q
→A B A
B B C
D E D
E* E E

(3)

11] Convert following Regular Expressions to minimized DFA


Nov-2014(CBGS)
R=(0+ɛ)(10)*( ɛ+1)
Solution:
Step1: (0+ɛ)

Step2: (10)*

(ba*+€)

Step3: (0+ɛ)(10)* (ɛ+1)

(ba*+€)
Theory of Computation

➢ Conversion to DFA: Following table shows the equivalent DFA for the above NFA.

X y= є - closure of (X) δ (y,0) δ (y,1)

A →{1}* {1,2,4,5,6,7,8,12,13,14,15,16,18} {3} {9,17}

B {3}* {3,6,7,8,12,13,14,15,16,18} - {9,17}

C {9,17}* {9,10,17,18} {11} -

D {11}* {11,8, 12,13,14,15,16,18} - {9,17}

∑ ∑
0 1 Q 0 1
Q
→A* B C
→A* B C
B* - C
B* - C
C* D -
D* - C C* B -

As we see from above table (B,D) merged

12]Convert the full NFA with € to a complete DFA.

Solution:
Theory of Computation

X y= є - closure of (X) δ (y,a) δ (y,b)

A →{1} {1} {2} {1}

B {2} {2} {2} {3}

C {3}* {1,3} {1,2} {1,3}

D {1,2} {1,2} {2} {1,3}

E {1,3}* {1,3} {1,2} {1,3}

∑ ∑
Q a b Q a b

→A B A →A B A

B B C B B C
C* D E C* D C
D B E D B C
E* D E

As we see from above table (C,E)(B,D)are merged

13]Convert the full NFA with ɛ to a complete DFA.

Solution:
Theory of Computation

X y= є - closure of (X) δ (y,a) δ (y,b)

A →{1}* {1,2 } {3,1} -

B {3,1}* {3,1,2} {3,1,2} {2,3}

C {3,1,2}* {1,2,3} {3,1,2} {2,3}

D {2,3}* {2,3} {1,2} {3}

E {1,2}* {1,2} {3,1,2} -

F {3} {3} {2} {2,3}

G {2}* {2} {1} -

∑ ∑
a b
a b Q
Q
→A* B -
→A* B -
B* B D
B* C D
D* E F
C* C D
E* B -
D* E F
F G D
E* C -
G* A -
F G D

G* A -

As we see from above table (B,C)(A,E)are merged

14] Convert the full NFA with ɛ to a complete DFA.

Accepting state
Theory of Computation

Solution:
X y= є - closure of (X) δ (y,a) δ (y,b)

A →{1} {1,3} {2,3,4} -

B {2,3,4}* {2,3,4} {3,4} {3,4,1}

C {3,4}* {3,4} {3,4} {4,1}

D {3,4,1}* {1,3,4} {2,3,4} {3,4,1}

E {4,1}* {1,4} {2,3,4} {4,1}


Q a b

→A B -

B* C D

C* C E

D* A D

E* A E

Arden’s Theorem:
Arden’s theorem helps in checking equivalence of two regular languages. This theorem can
be used for simplifying RE. And convert Finite automata (DFA) to equivalent regular
expression.
Theorem: Let P, Q, R be regular expression over input ∑. If there is an equation ,
R=Q+RP
Then there will be an unique solution for this is given by,
If R=Q+RP
Then R=QP*

Conversion of FA to RE:
1] Given finite automata should be ɛ free.
2] Each state in machine can be treated as R.E.
3] An equation will be created as follows,
Let P & Q be two states.
I] Assume that there are two incoming transition to P.
i] One from P whose input symbol is ‘a’.
ii] One from Q whose input symbol is ‘b’.
Theory of Computation

Then Eqn becomes, P= Pa+Qb


II] If P is Initial State Then Eqn becomes,
P= Pa+Qb+ɛ
4] To find Required R.E. the eqn of the final state will be solved.
5] If there are more than one final states the solution of all the final states will be added.
Examples:
1] Find R.E. equivalent to following FA.

Solution:
As q0 state is initial state, it has one incoming transition from itself with label ’0’ and ‘1’ and
it is an inital state ‘є’ is added. so the equation for state q0,q1,q2 will be:

q0= q0 0+q0 1+ є ---------------(1)

q1= q0 1 ------------------(2)

q2= q10 ------------------(3)

Solving eqn (1),we get,


q0= q0 (0+ 1)+ є
Using ardens theorem As, R=Q+RP then R=QP*
q0= є (0+ 1)*
q0= (0+ 1)*

Substituting in equation (2) of state q1. The equation for state q1 is:

q1= (0+ 1)*1

Substituting in equation (3) of state q2. The equation for state q2 is:

q2= (0+ 1)*10

As q2 is final state .So Required R.E. becomes,

r=(0+ 1)*10

2] Find R.E. equivalent to following FA.

Solution:
Theory of Computation

As q0 state is initial state, it has one incoming transition from itself with label ’0’ and it is an
inital state ‘є’ is added. so the equation for state q0,q1 will be:

q0= q0 0+ є ---------------(1)

q1= q0 1 +q11 ----------------(2)

Using ardens theorem As, R=Q+RP then R=QP*


Solving eqn (1),we get,
q0= є (0)*
q0= (0)*

Substituting in equation (2) of state q1. The equation for state q1 is:

q1= (0)*+q11

q1= (0)*(1)*

As q1 is final state .So Required R.E. becomes,

r=0*1*

3] Find R.E. equivalent to following FA.

Solution:
As q1 state is initial state, it has one incoming transition from itself with label ’0’ and it is an
initial state ‘є’ is added. so the equation for state q1,q2,q3will be:
q1= q1 0+ є --------------- (1)

q2= q1 1+ q21 ---------------- (2)

q3= q2 0+ q31 + q30 ----------------- (3)

Solving eqn (3),we get,


q3= q3 (0+ 1)+ q2 0
Using ardens theorem As, R=Q+RP then R=QP*
Solving eqn (2),we get,. The equation for state q2 is:
q2= q1 1+ q21
q2= q1 1.1*

Solving eqn (1),we get,. The equation for state q1 is:


q1= q1 0+ є
q1= 0*
Theory of Computation

Substituting in equation (2) of state q2. The equation for state q2 is:

q2= 0*1.1*

As q1& q2 are final state .So Required R.E. becomes,

r=0*+0*1.1*

4] Find R.E. equivalent to following FA.

Solution:
As q0 state is initial state, it has one incoming transition from itself with label ’0’ and it is an
initial state ‘є’ is added. so the equation for state q0,q1,q2 will be:

q0=q00+ q2 1+ є --------------- (1)

q1=q01+ q11+ q21 ----------------(2)

q2= q1 0 ----------------(3)

Solving eqn (2),we get,


q1= q01+ q11+ q101
q1= q01+ q1(1+ 01)
Using ardens theorem As, R=Q+RP then R=QP*
Solving eqn (2),we get,. The equation for state q1 is:
q1= q01 (1+ 01)*
Substituting above eqn in (1),we get,. The equation for state q0 is:
q0=q00+ q2 1+ є

q0=q00+ q1 01+ є

q0 = q00+ q01 (1+ 01)* 01+ є

q0 = q0(0+1 (1+ 01)* 01)+ є

q0 =(0+1 (1+ 01)* 01)*

As q0 is final state .So Required R.E. becomes,

r=(0+1 (1+ 01)* 01)*

5] Find R.E. equivalent to following FA.


Theory of Computation

Solution:
As q1 state is initial state, it has one incoming transition from itself with label ’a’&’b’ and it
is an initial state ‘є’ is added. so the equation for state q1,q2,q3will be:

q1= q1 a + q2 b + є --------------- (1)

q2= q1 a + q2 b + q3 a ---------------- (2)

q3= q2 a -------------- (3)

after substituting eqn (3) in eqn (2),we get,


q2= q1 a + q2 b + q2 a a
q2= q1 a + q2 (b + aa)

Using ardens theorem As, R=Q+RP then R=QP*


q2= q1 a ( b + aa )* ------------------(4)
Substituting equation (4) in equation (1)we get,

q1=q1 a + q1 a( b + aa )*b + є

q1=q1 (a + a( b + aa )*b) + є

Using ardens theorem As, R=Q+RP then R=QP*


q1 = є (a + a( b + aa )*b)*

q1 = (a + a( b + aa )*b)* ------------------(5)

Substituting equation (5) in equation (4)we get,

q2= (a + a( b + aa )*b)*a ( b + aa )* ------(6)

Substituting equation (6) in equation (3)we get,

q3= q2 a

q3=(a + a( b + aa )*b)*a ( b + aa )* a

As q3 is final state .So Required R.E. becomes,

r=(a + a( b + aa )*b)*a ( b + aa )* a
Theory of Computation
May-14(5)
6] Find R.E. for following:

Set of all strings over {1,0} that ends with 1 and has no substring 00.

Solution: Let L={1,01,101,011,0101……}


First we construct DFA as,

As q0 state is initial state, it has one incoming transition from itself with label ’1’ and it is an
initial state ‘є’ is added. so the equation for state q0,q1,q2 will be:

q0= q0 1 + є --------------- (1)

q1= q0 0+ q2 0 ----------------(2)

q2= q1 1+ q2 1 --------------- (3)

q3= q1 1+ q3 0+ q31 -------------- (4) it is rejected.

Using ardens theorem As, R=Q+RP then R=QP* eqn (1) becomes,
q0= q0 1 + є
q0= 1* ---------------(5)
n n
after substituting eq (5) in eq (2),we get,
q1= 1*0+ q2 0 ---------------(6)
n n
after substituting eq (6) in eq (3),we get,
q2= q1 1+ q2 1
q2= (q0 0+ q2 0)1 + q2 1
q2= (1*0+ q2 0)1 + q2 1
q2= 1*01+ q2(01+1)
q2= 1*01( 01+1 )* ---------------(7)

As q0 and q2 are final state .So Required R.E. becomes,


r=1*+1*01( 01+1 )*

7] Find R.E. equivalent to following FA. Dec-2010


10 Marks
Theory of Computation

Solution:
As q1 state is initial state, it has one incoming transition from itself with label ’0’ and it is an
initial state ‘є’ is added. so the equation for state q1,q2,q3,q4will be:

q1=q10+q30+q40 + є --------------- (1)

q2=q11+ q21+q41 ---------------- (2)

q3=q20 -------------- (3)

q4=q31 ------------ (4)

after substituting value of q3 and q4 in eqn (1),we get,


q1=q10+q200+q310 + є

q1=q10+q200+q2010 + є

q1=q10+q2(00+010) + є --------(5)
n
Taking eq (2),we get,
q2=q11+ q21+q41
substituting value of q4, we get,
q2=q11+ q21+ q311 --------(6)
substituting value of q3, from(3)we get
q2=q11+ q21+q2011

Using arden’s theorem As, R=Q+RP then R=QP*

q2= q11(1+011)* ---------(7)


From equation (5) and (7) we get,

q1= q10+ q11(1+011)* (00+010) + є

q1=q1[ 0+ 1(1+011)* (00+010) ]+ є

Using arden’s theorem As, R=Q+RP then R=QP*

q1=[0+ 1(1+011)* (00+010) ]* ------(8)

Put this value of q1 in equation (7) we get,


Theory of Computation

q2= [0+ 1(1+011)* (00+010) ]*1(1+011)*

Now,

q4=q31=q201

q4=[0+ 1(1+011)* (00+010) )*]1(1+011)*01

As q4 is final state .So Required R.E. becomes,

r=[0+ 1(1+011)* (00+010) )*]1(1+011)*01

Pumping Lemma for Regular Languages:

Theorem: It states that given any sufficiently long string accepted by an FSM, we can find a
substring near the beginning of the string that may be repeated or pumped as many times as
we like and the resulting string will still be accepted by the same FSM.

PROOF: Let L(M) be the regular language accepted by a given DFA M=(Q,∑, ∂, qo, f) with
some number of nodes ‘n’ consider an input from a1,a2…….am such that m>=n.
There exists two integer ‘j’ and ‘k’ wher 0<=j<k<=n such that qj=qk.

Figure: Pumping Lemma


Since j<k the string “aj+1…..ak” is of the length at least one and sincek<=n it’s length is no
more than ‘n’.
i.e. 1<= | aj+1…..ak | <=n

Formal Statement:
Let ‘L’ be a regular set. Then there is a constant ‘n’ such that if ‘z’ is any word in ’L’ and
|Z| >=n we may write z=uvw such that,
|uv|<=n,
|v|>=1 and for i>=0;
uviw є L
Consider, z=a1,a2........am
u=a1,a2........aj
v=aj+1,........ak
w= ak+1........am
Theory of Computation

Application of pumping Lemma:

The pumping lemma is used to prove that certain languages are not regular. With the help of
pumping lemma , we can determine whether it is a regular language or non regular
language.It should never be used to show that some language is regular. If we want to show
that language is regular, write separate expression, DFA or NFA.

1] Prove that L={0i2|i>0} is not regular


Solution:

1. Let i=1 0i2 012 i.e. length=12


i=2 0i2 022 i.e. length=22
i=3 0i2 032 i.e. length=32
Property: As we see the length of each string is a perfect square.
2. Assume that L is regular language.

3. Let l is constant of pumping lemma.

4. Let Z=0l2 where length of Z as,

|z|= l2
5. By pumping lemma z=uvw
Where 1≤ v ≤ l and
uvi w є L ; for i>=0

6. Put i=2 in uvi w


1≤ v ≤ l
2
add l on both sides,
1+ l2 ≤ |uv2 w| ≤ l+ l2
l2+1≤ | uv2 w| ≤ l2+l
As l +1 and l2+l is not perfect square ,so readjust term such that,
2

l2<| uv2 w| < (l+1)2

7. Put l=1 in above equation


1 < |uv2 w| < 4
i.e. length=2,3 and it is not perfect square.
Put l=2
4 < |uv2 w| < 9
i.e. length=5 ,6,7,8 and it is not perfect square.
Therefore the string “uv2 w” does not hold the property of language L.
So, there is contradiction to our assumption. Hence the given language L is not regular .
Theory of Computation

2] Prove that L={0n1n|n>0} is not regular

Solution:

1. Let n=1 0n 1n 01 11 i.e. length=2


n=2 0n 1n 02 12 i.e. length=4
n=3 0n 1n 03 13 i.e. length=6
Property: As we see all strings have even length.

2. Assume that L is regular language.

3. Let l is constant of pumping lemma

4. Let Z= 0l 1l where length of Z as,


|z|= 0l 1l =l+l=2l

5. By pumping lemma z=uvw


Where 1≤ v ≤ l and
uvi w є L ; for i>=0
6. Put i=2 in uvi w
1≤ v ≤ l
add 2l on both sides,
1+2l ≤ |uv2 w| ≤ l+2l
1+2l ≤ | uv2 w| ≤ 3l
2l < |uv2 w| < 3l +1

7. Put l=1 in above equation


2 < |uv2 w| < 4
i.e. length=3 and it is not even
Put l=2
4 < |uv2 w| < 7
i.e. length=5 , 6 and it is not always even .
Therefore the string “uv2 w” does not hold the property of language L.
So, there is contradiction to our assumption. Hence the given language L is not regular .

3] Prove that L={anbn+1|n>0} is not regular

Solution:

1. Let n=1 an bn+1 a1 b2 i.e. length=3


n=2 an bn+1 a2 b3 i.e. length=5
n=3 an bn+1 a3 b5 i.e. length=7
Property: As we see all strings have odd length.
Theory of Computation

2. Assume that L is regular language.

3. Let l is constant of pumping lemma

4. Let Z= al bl +1 where length of Z as,


|z|= al bl+1 =2l+1

5. By pumping lemma z=uvw


Where 1≤ v ≤ l and
uvi w є L ; for i>=0
6. Put i=2 in uvi w
1≤ v ≤ l
add 2l+1 on both sides,
1+2l +1≤ |uv2 w| ≤ l+2l+1
2l+2 ≤ | uv2 w| ≤ 3l+1
2l +1 < |uv2 w| < 3l +2
7. Put l=1 in above equation
3 < |uv2 w| < 5
i.e. length=4 and it is not odd
Put l=2
5 < |uv2 w| < 8
i.e. length=6,7 and it is not always odd .
Therefore the string “uv2 w” does not hold the property of language L.
So, there is contradiction to our assumption. Hence the given language L is not regular .

4] Prove that L={ap|p is a prime number} is not regular DEC-2007,2009

Solution:

1. Let p=2 ap a2 i.e. length=2


p 3
p=3 a a i.e. length=5
p 5
p=5 a a i.e. length=7
Property: As we see length is a prime number.

2. Assume that L is regular language.

3. Let l is constant of pumping lemma

4. Let Z= al where length of Z as,


|z|= al =l

5. By pumping lemma z=uvw


Where 1≤ v ≤ l and
Theory of Computation

uvi w є L ; for i>=0


6. Put i=2 in uvi w
1≤ v ≤ l
add l on both sides,
l +1≤ |uv2 w| ≤ l+l
l+1 ≤ | uv2 w| ≤ 2l
l < |uv2 w| < 2l +1

7. Put l=2 in above equation


2 < |uv2 w| < 5
i.e. length=3,4
Put l=3
3 < |uv2 w| < 7
i.e. length=4,5,6and it is not always prime .
Therefore the string “uv2 w” does not hold the property of language L.
So, there is contradiction to our assumption. Hence the given language L is not regular .

5] Prove that L={W c WR | W є (0+1)*}is not regular where wR is reverse of w.


Solution:
1. Let (0+1) 1 0c0 i.e. length=3
2
(0+1) 01 c 10 i.e. length=5
3
(0+1) 110 c 011 i.e. length=7
Property: As we see all strings have length 2n+1(odd).

2. Assume that L is regular language.

3. Let l is constant of pumping lemma

4. Let W є (0+1)* therefore length of Z as,


|z|= 2l+1

5. By pumping lemma z=uvw


Where 1≤ v ≤ l and
uvi w є L ; for i>=0
6. Put i=2 in uvi w
1≤ v ≤ l
add 2l+1 on both sides,
1+2l +1≤ |uv2 w| ≤ l+2l+1
2l+2 ≤ | uv2 w| ≤ 3l+1
2l +1 < |uv2 w| < 3l +2
Theory of Computation

7. Put l=1 in above equation


3 < |uv2 w| < 5
i.e. length=4 and it is not 2n+1.
Put l=2
5 < |uv2 w| < 8
i.e. length=6,7 and it is not always 2n+1.
Therefore the string “uv2 w” does not hold the property of language L.
So, there is contradiction to our assumption. Hence the given language L is not regular .

6] Prove that L={WWR | W є (0,1)*}is not regular where wR is reverse of w.


Solution: As W (0,1)* Choose string as W=0n1n and WWR= 0n 1n 1n 0n
1. Let n=1 0n 1n 1n0n 0110 i.e. length=4
n n n n
n=2 0 1 1 0 0101 1010 i.e. length=8
Property: As we see all strings have length multiple of 4.

2 Assume that L is regular language.

3 Let l is constant of pumping lemma

4 Let W є (0,1)* therefore length of Z as,


|z|= 4l

5 By pumping lemma z=uvw


Where 1≤ v ≤ l and
uvi w є L ; for i>=0
6 Put i=2 in uvi w
1≤ v ≤ l
add 4l on both sides,
1+4l ≤ |uv2 w| ≤ l+4l
1+4l ≤ | uv2 w| ≤ 5l
4l < |uv2 w| < 5l +3

7 Put l=1 in above equation


4 < |uv2 w| < 8
i.e. length=5,6,7 and it is not multiple of 4
Put l=2
8 < |uv2 w| < 13
i.e. length=9,10,11,12 and it is not always multiple of 4.
Therefore the string “uv2 w” does not hold the property of language L.
So, there is contradiction to our assumption. Hence the given language L is not regular .
Theory of Computation

7] Prove that L={ww| w є (0,1)*}is not regular DEC-2006,2010


Solution: As W (0,1)* Choose string as W=anb and WW= anb anb
1. Let n=1 anb anb i.e. length=4
n n
n=2 a b a b i.e. length=6
n n
n=3 a b a b i.e. length=8
Property: As we see all strings have length 2n+2.

2. Assume that L is regular language.

3. Let l is constant of pumping lemma

4. Let Z= alb alb where length of Z as,


|z|= alb alb = 2l+2

5. By pumping lemma z=uvw


Where 1≤ v ≤ l and
uvi w є L ; for i>=0
6. Put i=2 in uvi w
1≤ v ≤ l
add 2l on both sides,
1+2l +2≤ |uv2 w| ≤ l+2l+2
2l+3 ≤ | uv2 w| ≤ 3l+2
2l +2 < |uv2 w| < 3l +3

7. Put l=1 in above equation


4 < |uv2 w| < 6
i.e. length=5 and it is not 2n+2
Put l=2
6 < |uv2 w| < 9
i.e. length=7,8 and it is not always multiple of 2n+2 .
Therefore the string “uv2 w” does not hold the property of language L.
So, there is contradiction to our assumption. Hence the given language L is not regular.

8] Prove that L={anban|n>0} is not regular


DEC-2009,2011
Solution:

1. Let n=1 an b an a1 b a1 i.e. length=3


n n 2 2
n=2 a ba a ba i.e. length=5
n n 3 3
n=3 a ba a ba i.e. length=7
Property: As we see all strings have odd length.
Theory of Computation

2. Assume that L is regular language.

3. Let l is constant of pumping lemma

4. Let Z= al b al where length of Z as,


|z|= al b a1 =2l+1

5. By pumping lemma z=uvw


Where 1≤ v ≤ l and
uvi w є L ; for i>=0
6. Put i=2 in uvi w
1≤ v ≤ l
add 2l+1 on both sides,
1+2l +1≤ |uv2 w| ≤ l+2l+1
2l+2 ≤ | uv2 w| ≤ 3l+1
2l +1 < |uv2 w| < 3l +2

7. Put l=1 in above equation


3 < |uv2 w| < 5
i.e. length=4 and it is not odd
Put l=2
5 < |uv2 w| < 8
i.e. length=6,7 and it is not always odd .
Therefore the string “uv2 w” does not hold the property of language L.
So, there is contradiction to our assumption. Hence the given language L is not regular .

9] Prove that L = {anb2n |n>0} is not regular.


Solution:

1. Let n=1 an b2n a1 b2 i.e. length=3


n 2n 2 4
n=2 a b a b i.e. length=6
n 2n 3 6
n=3 a b a b i.e. length=9
Property: As we see all strings have length multiple of 3.

2. Assume that L is regular language.

3. Let l is constant of pumping lemma

4. Let Z= al b2l where length of Z as,


|z|= al b2l =3l

5. By pumping lemma z=uvw


Where 1≤ v ≤ l and
Theory of Computation

uvi w є L ; for i>=0


6. Put i=2 in uvi w
1≤ v ≤ l
add 2l+1 on both sides,
1+3l ≤ |uv2 w| ≤ l+3l
3l+1 ≤ | uv2 w| ≤ 4l
3l < |uv2 w| < 4l +2

7. Put l=1 in above equation


3 < |uv2 w| < 6
i.e. length=4,5 and it is not multiple of 3.
Put l=2
6 < |uv2 w| < 10
i.e. length=7,8,9 and it is not always multiple of 3.
Therefore the string “uv2 w” does not hold the property of language L.
So, there is contradiction to our assumption. Hence the given language L is not regular .

10] Prove that L={(ab)nak|n>k,k>=0} is not regular

Solution: This is similar to the string Z=(ab)n+1 an since n>k,k>=0

1. Let n=1 (ab)nak (ab)2a1 ababa i.e. length=5


n=2 n
(ab) a k (ab)3a2 abababaa i.e. length=8
n=3 (ab)nak (ab)4a3 ababababaaa i.e. length=11
Property: As we see all strings have length of 3n+2.

2. Assume that L is regular language.

3. Let l is constant of pumping lemma

4. Let Z= (ab)l +1al where length of Z as,


|z|= (ab)l +1al =3l+2

5. By pumping lemma z=uvw


Where 1≤ v ≤ l and
uvi w є L ; for i>=0
6. Put i=2 in uvi w
1≤ v ≤ l
add 3l+2 on both sides,
3+3l ≤ |uv2 w| ≤ l+3l+2
3l+3 ≤ | uv2 w| ≤ 4l+2
3l +2 < |uv2 w| < 4l +4
Theory of Computation

7. Put l=1 in above equation


5 < |uv2 w| < 8
i.e. length=6,7 and it is not multiple of 3n+2.
Put l=2
8 < |uv2 w| < 12
i.e. length=9,10,11 and it is not always multiple of 3n+2.
Therefore the string “uv2 w” does not hold the property of language L.
So, there is contradiction to our assumption. Hence the given language L is not regular .

Closure properties for regular language:


Closure properties express the idea that when one or several languages are regular, then
certain operations on regular languages are also regular.
Consider L & M be the regular language. The following operations on L and M produce the
regular language.
➢ Union: LM
➢ Concatenation: LM
➢ Closure: L*
➢ Complement: L
➢ Intersection: LM
➢ Difference: L-M
➢ Reversal: LR = {wR | wL}
➢ Homomorphism:
h(L) = {h(w) | wL, h is a homomorphism}
➢ Inverse homomorphism:
h-1(L) = {w | h(w)L, h is a homomorphism}

1] Closure under Union:


Theorem: If L and M are two regular languages then its union L  M is also regular. The
regular language is closed under union.

Proof: If L and M are two regular languages. There are regular expression r1 and r2 that
define these languages. since each regular language is defined by some regular expression.
Then (r1+r2) defines the language L+M i.e. L  M .Hence L  M is a regular language.

Example 1: Consider following two languages over ∑ = {0,1},

L = {00,10,110} and

M = {00, 10}

LM = {00,10,110 }
Theory of Computation

2] Closure under concatenation:


Theorem: If L and M are regular languages, then its concatenation i.e. LM is also regular
language. The regular language is closed under concatenation.

Proof: If L and M are two regular languages. There are regular expression r1 and r2 that
define these languages. since each regular language is defined by some regular expression.
Then (r1.r2) defines the language LM .Hence LM is a regular language.

Example 1:

Consider following two languages over ∑ = {0,1},

L = {00,10,110} and

M = {00, 10}

L.M = {0000,0010,1000,1010,11000,11010 }

3] Closure under Kleen closure:


Theorem:If L is a regular language over, then its closure i.e. L* is also regular language.
The regular language is closed under kleen closure.

Proof: If L is a regular language over . The regular expression (r*) consists of all strings
that are generated by all strings in L concatenated with itself zero or more number of times.
Hence L* is a regular language.

Example 1:

L = {ba}

L*={€,ba,baba.......}

4] Closure under Complementation:


Theorem: If L is a regular language then its complement L is also regular language. The
regular language is closed under complement.

Proof: If L is a regular language over , then L from all * is also regular. Therefore

L = *-L

Proof: Let L be recognized by an DFA A as,


A = (Q, , , q0, F) that accepts all and only the strings of 0’s and 1’s that end in 01.
L(A) = (0+1)*01
The complement of L (A) is therefore all string of 0’s and 1’s that do not end in 01
Construct B = (Q, , , q0, Q-F),
now L = L(B)
Theory of Computation

5] Closure under Intersection:


Theorem: If L and M are two regular languages then LM is also regular language. The
regular language is closed under Intersection.

Proof: By DeMorgan’s Law,

LM = (LM)

We already proved that regular languages are closed under complement and union. So the
regular language is closed under Intersection.

Example: Consider DFA for all string of 0’s and 1’s that the set of that contain ‘0’

L=

Consider another DFA for all string of 0’s and 1’s that the set of that contain ‘1’

M=

The product of above DFA is

6] Closure under Difference:


Theorem: If L and M are regular languages, then its difference i.e. L - M is also regular
language. The regular language is closed under difference.
Theory of Computation

Proof: Observe that L - M = LM. We already know that regular languages are closed under
complement and intersection.

Example: Consider following two languages over ∑ = {0,1},

L = {00,10,110} and

M = {00, 10}

L-M = {110 }

7] Closure under Reversal:


Theorem: If L is a regular languages, then its reversal i.e. LR is also regular language. The
regular language is closed under Reversal.

Proof: Let L be recognized by an FA A, turn A into an FA recognizing LR, by

◼ Reversing all arcs

◼ Making the old start state the new sole accepting state

◼ Creating a new start state q0, with (q0, )=F (the old accepting states)

Example:

L= LR=

8] Closure under Homomorphism:


A string homomorphism is a function on strings that works by substituting a particular string
for each symbol.
Theorem: If L is a regular language over, and h is a homomorphism on , then h(L) is also
regular language. The regular language is closed under homomorphism.

Proof: Consider an example

Example: Let h: {0,1}*→{a,b}* be defined by h(0)=ab, h(1)=. Then


h(0011) = abab
h(L(10*1)) = L((ab)*)
9] Closure under Inverse Homomorphism:

Theorem: If L is a regular language over, and h is a homomorphism on , then h(L) is also


regular language. The regular language is closed under homomorphism.

Proof: Let L is recognized by an FA ,A = (Q, 2, , q0, F)


Theory of Computation

We construct an FA B = (Q, 1, , q0, F), where (q, a) = (q, h(a)).

h-1(L) is recognized by B.

Example: 1 = {a, b}, 2 = {0, 1}

h(a) = 01, h(b) = 10

L: h-1(L):

Q]Give the rules for defining the languages associated with any regular expressions

Let L1 = all words beginning with a DEC-2012

L2 = all words ending with a

What is L1 intersection L2?

Solution: Let Ll = all words beginning with, a


L2 = all words ending with a
what is L1 intersection L2 ?

L1= a(a+b)*

L2=(a+b)*a

L1 intersection L2: all words beginning with, a and ending with a


a (a+b)* a
Decision properties for regular language:
A decision property for a regular language is an algorithm that takes a formal description of a
language (e.g., a DFA or RE) and tells whether or not some property holds. There are various
decision properties for a regular language such as

• Membership: Is string w in L?

• Emptiness: Is L = ?

• Finiteness: Is L a finite language?

• Equivalence: Is equivalence of state?

1] Testing Membership in a regular language:


This property tells whether a particular string ‘w’ belongs to language L or not.
Theory of Computation

We can construct a DFA for the language L. Then we simulate the DFA on input ‘w’. If we
reach to final state then w € L otherwise not.

2] Testing Emptiness of regular language:


Given an FA for language L, L is not empty if and only if at least one final state is reachable
from the start state in FA.
Alternatively, given a regular expression E for L, we can use the following to test if
L(E) = :
◼ E=F+G, L(E)= if and only if L(F) and L(G) are empty
◼ E=FG, L(E)= if and only if either L(F) or L(G) is empty
◼ E=F*, L(E) is not empty

3] Testing Equivalence of states:


This property tells whether the states are equivalent ot not .

We can construct a DFA for the language L. Then we can find the equivalence of state .if
both states having their ‘0’ as well as ‘1’ transition are equivalent then we say that the states
are equivalent.

4] Testing Equivalence of regular language(Finiteness):


This property gives answer for whether the regular language is finite or not. we can test it by
following method.

Given a DFA for language L,


• Eliminate all states that are not reachable from the start state and all states that do not
reach an accepting state.
• Test if there are any cycles in the remaining DFA;
• if so, L is infinite, if not, then L is finite.

Myhill-Nerode theorem:

Myhill-Nerode theorem provides the necessary condition for a set to be regular.

Theorem Statement:

A language L is regular if and only if the equivalence set RL has finite no. of equivalence classes and
the number of states in the smallest DFA recognizing L is equal to the number of equivalence classes
in RL.

• There are 3 parts to theorem:

1] For any language L, we have equivalence relation R: xRy if z, xz and yz are the same
outcome ie. Either distinguishable or not

2] If L is regular, then equivalences classes are finite.


Theory of Computation

3]If equivalences classes are finite then language is regular.

• Let L be a language in *

• Two strings x and y in * are distinguishable with respect to L if there is a string z∈ *, so
that exactly one of the strings xz and yz is in L

• In other words, if for every z, both xz and yz have the same status i.e. either both are in L or
both are not in L

Example: Consider the language, L={x∈{0,1}* | x ends with 10}

For z=0, the strings 01011 and 100 are distinguishable with respect to L because

01011z ∈ L and 100z ∉ L.

For z=0 , 01z ∈ L and 01011z ∈ L so 01 and 01011 are in distinguishable.

• Suppose that L⊆* and M=(Q,  , q0, F,  ) is any FA recognizing L.

If x and y are two strings in * for which *(q0,x)=*(q0,y), then x and y are indistinguishable
with respect to L

• Thus two strings x and y belongs to same class if both of them trace the same path from initial
state q0 to some state qi

Applications of RE:

➢ For validating inputs: User gives incorrect type of input .

For example: valid identifier must start with alphabet followed by number of alphabets and digits.

Sometimes the counter is initialized to negative numbers. In such cases use routine that take input
string and regular expression and returns TRUE if input matches with the regular expression.

➢ For searching and selecting parts of a given text on the basis of a given pattern:

To find specific word from a files, but don’t know the exact file.Using some routines we list all the
files which contains that word. But the result may not describe the pattern correctly. The regular
expression describes such vaguely defined patterns more precisely.

▪ example- grep command in Linux

➢ For lexical analysis :

RE is used in one of the phases of compilation: lexical analysis. The high level program is given as a
input in the form of sequence of characters. The lexical analyzer converts the sequence of characters
into the tokens in high level language. The tokens are categorized in different classes like identifier,
Theory of Computation

keyword, operators, literals etc. The regular expressions are used to recognize the tokens from
sequence of characters

May-2014(CBGS)
1 Construct an NFA with є transition for the following RE 05
(00+11)*(10)*
2 Give application of RE 02
3 Give the regular expression for the following 05
i] Set of all string over {0,1}that ends with 1 and has no substring 00.
ii] Set of all string over {0,1}with even no of 1’s followed by odd no of 0’s.

4 Give and Explain the formal statement of pumping lemma for regular 10
languages and use it to prove that the following language is not regular.
L= {anbn |n>0}
Dec-2014(CBGS)
1 State and Explain any 5 closure properties of RL 05
2 Convert following Regular Expressions to minimized DFA 10
(0+ є)( 10)*( є+1)
3 Give the formal statement of pumping lemma and hence prove that
10
L = { WCWR |W (a+b)*}is not regular.
May-2014
1 Explain applications of regular expression. 05
2 Explain Myhill Nerode Theorem 05
3 Draw NFA for the given regular expression and convert it into its 10
equivalent DFA. (11+01)*
4 Explain closure properties of regular language 10
5 Write short note on Arden’s theorem 05
Dec-2014
1 05
2 Using Pumping Lemma to check anbn is regular for n>=1 10
3
May-13
1 10
2
DEC-13
1 State and prove the formal statement of pumping lemma for RL.
2 List and Explain decision properties for regular language. Explain the
test for checking emptiness of the regular language.
May-12
1 10

2 Design PDA for the grammar ,by empty stack S → 0AA 10


A → 0S | 1S | 0
DEC-12
Theory of Computation

1 Explain PDA and Power of PDM.Design NPDA for S→ a |aAA 10


A→ aS |bS
2 Costruct a PDA accepting a language of palindrome 10
3 Give application of PDA 03
May-11
1 Design PDA for language L={WCWR |W € (a,b)*} 10
2 Design PDA for the grammar ,Test Whether 0104 would belong to the 10
language. S → 0BB
B → 0S | 1S | 0
DEC-11
1 m
L={(0 1 0n m+n | m, n≥1} 08
2 Differentiate between DPDA and NPDA 04
3 Define PDA and construct PDA for the grammar E→E+E | E-E | (E) |
id
May-10
n m n
1 L={a b a | m,n>=1} 05
DEC-10
1 Differentiate between DPDA and NPDA 05
2 Design PDA for language L={WCWR |W € (a,b)*} 10

You might also like