Latest

6/recent/ticker-posts

Write regular expressions for the following languages on {0, 1}- Solution of Peter Linz


 

Write regular expressions for the following languages on {0, 1}. 

(a) all strings ending in 01,

(b) all strings not ending in 01, 

(c) all strings containing an even number of 0’s, 

(d) all strings having at least two occurrences of the substring 00. (Note that with the usual interpretation of a substring, 000 contains two such occurrences),

(e) all strings with at most two occurrences of the substring 00, 

(f) all strings not containing the substring 101.

(an-introduction-to-formal-languages-and-automata- Peter Linz, question no: 17, section: 3.1)

Solution:

(a) all strings ending in 01,

=> (0+1)* 01

(b) all strings not ending in 01, 

=>(0+1)*( 00+10+11) + 0+ 1 + λ     ( 0+1+λ is required because the string can also be of size 0 or 1 )

(c) all strings containing an even number of 0’s, 

=> (1*01*01*)*1*

(d) all strings having at least two occurrences of the substring 00. (Note that with the usual interpretation of a substring, 000 contains two such occurrences),

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

(e) all strings with at most two occurrences of the substring 00, 

=> (1+01)* + (1+01)*0 + (1+01)*00 + (1+01)* 001 + (1+01)*(0010)+ (1+01)*00(0+1(1+01)*00)

(f) all strings not containing the substring 101

=> 0*(1*000*)*1*0*.




Post a Comment

0 Comments