Download as ppsx, pdf, or txt
Download as ppsx, pdf, or txt
You are on page 1of 13

BY : Trusha Patel, CD Dept, CSPIT, CHARUSAT, Changa

Regular Expression
Theory of Computation
Theory of Computation 2

Definition of RE

BY : Trusha Patel, CD Dept, CSPIT, CHARUSAT, Changa


 L1 and L2 are elements of R and r1 and r2 are corresponding
regular expression then
 L1∪L2 corresponding RE is ( r1 + r2 )
 L1L2 corresponding RE is (r1r2)
 L1* corresponding RE is r 1*
Theory of Computation 3

RE notations

BY : Trusha Patel, CD Dept, CSPIT, CHARUSAT, Changa


Notation Meaning RE Language
ϵ ^ Null character
| + or / Choice a|b a+b {a, b}
Kleene closure
* 0 or more occurrence
a* {ϵ, a, aa, aaa, aaaa, aaaaa, …}
Positive closure
+ 1 or more occurrence a+ {a, aa, aaa, aaaa, aaaaa, …}

? 0 or 1 occurrence a? {ϵ,a}
. Concatenation a ( b | c ) {ab, ac}
ø Null set {}
[] Character set [1-3] {1, 2, 3}
^ Reverse of set [27]^ {0, 1, 3, 4, 5, 6, 8, 9}
Theory of Computation 4

Examples

BY : Trusha Patel, CD Dept, CSPIT, CHARUSAT, Changa


1) String end with 0
 ( 0 + 1 )* 0

2) String end with 11


 ( 0 + 1 )* 11

3) String do not end with 01


 ᴧ + 0 + 1 + (0+1)*(00+10+11)
Theory of Computation 5

Examples

BY : Trusha Patel, CD Dept, CSPIT, CHARUSAT, Changa


4) Next to last (second last) symbol is 0
 ( 0 + 1 )* 0 ( 0 + 1 )

5) String has first and last letter different


 0( 0 + 1)*1 + 1( 0 + 1)*0

6) String begin or end with 00 or 11


 ( ( 00 + 11 ) ( 0 + 1 )* (10+01) ) +
( (10+01) ( 0 + 1 )* ( 00 + 11) )
Theory of Computation 6

Examples

BY : Trusha Patel, CD Dept, CSPIT, CHARUSAT, Changa


7) String containing 00 as substring
 ( 0 + 1 )* 00 ( 0 + 1 )*

8) String not containing 00 as substring


 ( 0 + ᴧ ) (10 +1 )*
 ( 1 + 01 )* ( 0 + ᴧ )

9) String end with 1 and not containing 00


 ( 1 + 01 )+
Theory of Computation 7

Examples

BY : Trusha Patel, CD Dept, CSPIT, CHARUSAT, Changa


10)String contain both 11 and 010 as substring
 (0+1)* (11(0+1)*010 + 010(0+1)*11) (0+1)*

11)String that containing 10 and 01 as substring


 (0+1)* (0+1+0+ + 1+0+1+) (0+1)*

12)String not containing 00x11 as substring


 (1+01)* (0+01)*
Theory of Computation 8

Examples

BY : Trusha Patel, CD Dept, CSPIT, CHARUSAT, Changa


13)String has exactly two 0
 1* 0 1* 0 1*

14)String have at least two 0


 ( 0 + 1 )* 0 ( 0 + 1 )* 0 ( 0 + 1 )*

15)String has no more than one occurrence of 00 (maximum


one time 00)
 ( 1 + 01 )* ( 0 + 00 + ᴧ ) ( 10 + 1 )*
Theory of Computation 9

Examples

BY : Trusha Patel, CD Dept, CSPIT, CHARUSAT, Changa


16)String with even number of 0’s
 1* ( 0 1* 0 1* )*

17)String with odd number of 1’s


 ( 0* 1 0* )( 1 0* 1 0*)*

18)Even number of 0’s and 1’s


 (00+11)*+
(00+11)*(10+01)(00+11)*(10+01) (00+11)*
Theory of Computation 10

Examples

BY : Trusha Patel, CD Dept, CSPIT, CHARUSAT, Changa


19)Strings in which every 0 is followed immediately by 11
 1* ( 011 )*

20)String of length 3 or 1 plus a multiple of 3


 (0+1) (0+1) (0+1) +
((0+1)(0+1)(0+1))* (0+1)
Theory of Computation 11

Examples

BY : Trusha Patel, CD Dept, CSPIT, CHARUSAT, Changa


21)String of even length
 { 00 , 01 , 10 , 11 }*
 ( 00 + 01 + 10 + 11)*
 ( (0+1) (0+1) )*

22)String of length 6 or less


 ( 0 + 1 + ᴧ )6
Theory of Computation 12

Examples

BY : Trusha Patel, CD Dept, CSPIT, CHARUSAT, Changa


23)ᴧ∊L if x∊L then 001x & x11 are in L
 (001)* (11)*

24)0∊L if x∊L then 001x, x001 & x11 are in L


 (001)* 0 (001+11)*

25)ᴧ∊L , 0∊L if x∊L then 001x & 11x are in L


 (001+11)* (ᴧ+0)
Theory of Computation 13

Examples

BY : Trusha Patel, CD Dept, CSPIT, CHARUSAT, Changa


26) Language of C identifier
 [a-zA-Z_] [a-zA-Z0-9_]*

27) Unsigned real number


 [0-9]+ (.[0-9]+)? ([+-]e[0-9]+)?

28) Signed real number


 [+-] [0-9]+ (.[0-9]+)? ([+-]e[0-9]+)?

You might also like