0% found this document useful (0 votes)
7 views26 pages

RE- basics

The document provides an overview of regular expressions, regular grammar, and regular languages, explaining how regular expressions can describe languages accepted by finite automata. It outlines the rules for constructing regular expressions and provides examples of various regular expressions for different languages. Additionally, it discusses the conversion of regular expressions to finite automata.

Uploaded by

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

RE- basics

The document provides an overview of regular expressions, regular grammar, and regular languages, explaining how regular expressions can describe languages accepted by finite automata. It outlines the rules for constructing regular expressions and provides examples of various regular expressions for different languages. Additionally, it discusses the conversion of regular expressions to finite automata.

Uploaded by

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

Regular Expressions, Regular Grammar and

Regular Languages
Define: Regular Expression

• The language accepted by finite automata can be


easily described by simple expressions called Regular
Expressions.
• It is the most effective way to represent any language.
• The languages accepted by some regular expression
are referred to as Regular languages.
• A regular expression can also be described as a
sequence of pattern that defines a string.
• Regular expressions are used to match character
combinations in strings.
• String searching algorithm used this pattern to find
the operations on a string.
Regular Expressions
• Regular Expressions are used to denote regular
languages. An expression is regular if:

1. ɸ is a regular expression for regular language ɸ.


2. ɛ is a regular expression for regular language {ɛ}.
3. If a ∈ Σ (Σ represents the input alphabet), a is
regular expression with language {a}.
4. If a or b are regular expression, a + b is also a
regular expression with language {a,b}.
5. If a and b are regular expression, ab (concatenation
of a and b) is also regular.
6. If a is regular expression, a* (0 or more times a) is
also regular.
Languages associated with regular
expressions
The language L(r) denoted by a regular expression r is
defined by the following rules,
1)  is a r.e denoting the empty set L () = {}
2)  is a r.e denoting the empty set L () = {}
3) For any a is a r.e denoting the set L (a) = {a}
If r1 and r2 are regular expressions, then
4) L (r1 + r2) = L{r1} U L{r2}
5) L (r1 . r2) = L{r1}.L{r2}
6) L ((r1)) = L(r1)
7) L (r1*) = (L (r1))*
Regular Expression
Let  be a given alphabet. Then
1)  ,  , and any a are all regular expressions.
These are called
primitive regular expressions.
2) If r1 and r2 are regular expressions, then
- r1 + r2 is a regular expression.
- r1  r2 is a regular expression.
- r1* is a regular expression.
- (r1 ) is a regular expression.

3) A string is a regular expression, if and only if it can


be derived from the primitive regular expressions by a
finite number of applications of rules in (2).
Regular Expression
Check whether the given string is a regular expression,
S ={ a, b, c}, the string (a + b . c)* . (c + )
r1 = a , r2 = b , r3 = c
r4 = r2 . r3 = b . c
r5 = r1 + r4 = a + b . c
r6 = (r5) = (a + b . c)
r7 = r6* = (a + b . c)*
r8 = 
r9 = r3 + r8 = c + 
r10 = (r9)= (c + )
r11 = r7 . r10 = (a + b . c)* . (c + )
Problems on Regular Expression
1. Languages over the alphabet {0,1} is described by the regular
expression (0+1)*0(0+1)*0(0+1)* is the set of all strings
containing at least two 0’s.
2. The regular expression 0*(10*)* denoted by (1*0)*1* are
equivalent. Two regular expressions are equivalent if
languages generated by them are same.(using the identity)
3. The regular expression for the language accepting all
combinations of a's, over the set ∑ = {a} is R = a*
4. The regular expression for the language accepting all
combinations of a's except the null string, over the set
∑ = {a} is R = a+
5. The regular expression for the language accepting all the
string containing any number of a's and b's is
r.e. = (a + b)*
7. The regular expression for the language accepting all the string
which are starting with 1 and ending with 0, over ∑ = {0, 1} is
R = 1 (0+1)* 0
8. Set of all strings with exactly 2 a’s- b*ab*ab*
9. Set of all strings with atleast 2 a’s – b*ab*a*(a+b)*
10. Set of all strings with atmost 2 a’s – b*(ɛ+a)b*(ɛ+a)b*
11. Set of all strings with number a’s are even –
(b*ab*ab*)*+b* or (b*ab*ab*)*b*
12. Set of all strings that contain’s a – (a+b)* a (a+b)*
13. Set of all strings that starts and ends with same symbol –
a(a+b)*a + b(a+b)*b +(a+b+ɛ)
13. The regular expression for the language starting and ending with a
and b respectively and having any combination of b's in between is
R = a b* b

14. The regular expression for the language starting with a but not having
consecutive b's is R = {a + ab}*

15. The regular expression for the language accepting all the string in
which any number of a's is followed by any number of b's is followed
by any number of c's is R = a* b* c*

16. The regular expression for the language over ∑ = {0} having even length of
the string is R = (00)*

17. The regular expression for the language having a string which should
have atleast one 0 and alteast one 1 is
R = [(0 + 1)* 0 (0 + 1)* 1 (0 + 1)*] + [(0 + 1)* 1 (0 + 1)* 0 (0 + 1)*]
18. The language consists of the string in which a's appear triples,
there is no restriction on the number of b's is r.e. = (b* (aaa)* b*)*

19. The regular expression for the language L over ∑ = {0, 1} such that all the
string do not contain the substring 01 is R = (1* 0*) (Since
L = {ε, 0, 1, 00, 11, 10, 100, .....} )

20. The regular expression for the language containing the string over {0, 1}
in which there are at least two occurrences of 1's between two
occurrences of 0's.
Solution: At least two 1's between two occurrences of 0's can
be denoted by (0111*0)*.
Similarly, if there is no occurrence of 0’s(zero occurrenc of ZERO), then
any number of 1's are also allowed.
Hence the r.e. for required language is R = (1 + (0111*0))*

21. The regular expression for the language containing the string in
which every 0 is immediately followed by 11 is R = (011 + 1)*
22. The set of strings that alternate 0’s and 1’s
(01)∗+ 1(01)∗+ (01)∗0+ 1(01)∗0
23. Set of strings of odd length- ((a+b)(a+b))* (a+b)
24. Set of strings whose length divisible by 3 –
( (a+b) (a+b) (a+b))*
If it is 2 mod 3=2 -> ( (a+b) (a+b) (a+b))* (a+b) (a+b)
Languages associated with regular
expressions
Exhibit the language L(a* . (a + b)) in set notation
L(a* . (a + b)) = L(a*) . L( (a + b))
= (L(a))*. L(a + b))
= (L(a))*. L(a) U L(b)
= { a }*. { a } U { b }
= {, a, aa, aaa,. . . }. { a, b}
= {a, aa, aaa, aaaa,. . . ,b, ab, aab, aaab,. . . }
Languages associated with regular
expressions
r = (a + b)*. (a + bb), find L(r)
L(r) = L((a + b)*. (a + bb))
= L((a + b)*). L(a + bb)
= (L(a + b))*. L(a + bb)
= (L(a) U L(b))* . L(a) U L(bb)
= {a, b}* . {a} U {b}.{b}
= {a, b}* . {a} U {bb}
= {a, b}* . {a, bb}
= {, a, b, aa, ab, ba, bb,. . .} . {a, bb}
= {a, aa, ba, aaa, aba, baa, bba,. . .,bb, abb, bbb, aabb, abbb, . . .}
Examples
Describe the following sets by regular expressions
1) L1 = the set of all strings of 0’s and 1’s ending with 00- (0 + 1)*00
2) L2 = the set of all strings of 0’s and 1’s and beginning with 0 and ending with
1 - 0(0 + 1)*1
3) L3 = {, aa, aaaa, . . . } - (aa)*
4) The set of all strings of 0’s and 1’s with at least two consecutive zeros - (0 +
1)*00(0 + 1)*
5) The set of all strings of a’s and b’s whose length is divisible by 6 - [(a + b)6]*
6) The set of all strings of a’s and b’s whose 5th last symbol is b - (a + b)4b(a +
b)*
7) The expression r = (aa)* (bb)*b denotes the set of strings with an even
number of a’s followed by an odd number of b’s - L(r) = {a2n b2m+1 / n ≥ 0 , m
≥0}
8) L4 = {an bm / n ≥ 4 , m ≤ 3} - aaaaa*(b + bb + bbb)
Examples
1) (0 + 1)*00
2) 0(0 + 1)*1
3) (aa)*
4) (0 + 1)*00(0 + 1)*
5) [(a + b)6]*
6) (a + b)4b(a + b)*
7) L(r) = {a2n b2m+1 / n ≥ 0 , m ≥ 0 }
8) aaaaa*(b + bb + bbb)
Converting RE to FA
Design a NFA from given regular expression
1 (1* 01* 01*)*.

You might also like