Notes For Regular Expression
Notes For Regular Expression
Solution:
Here, the resultant regular expression will denotes the set of all strings having atmost one pair of 0’s
or atmost one pair of 1’s.
Here, atmost one pair of 0’s means, there is either one pair of 0’s, i.e., 00 or no one pair of 0’s.
Similarly, atmost one pair of 1’s means, in the string which will be represented by the resultant
regular expression, there is either one pair of 1’s, i.e., 11 or no one pair of 1’s.
For getting such regular expression, first we have to find the language denoted by this problem-
Now , from the equation (1), (2), (3) and (4), we can easily find out that which regular expression
does not contain a pair of 0’s i.e. 00.
1* and 01*
Now, similarly we can easily find out that which regular expression does not contain a pair of 1’s, i.e.,
11.
0* and 10*
Thus, from equation (5), (6), (7) and (8) we can find the regular expression over input alphabet {0, 1}
having atmost one pair of 0’s or atmost one pair of 1’s. Thus, the resultant regular expression is-
(1* + 01*) + (1* + 01*) 00 (1* + 01*) + (0* + 10*) + (0* + 10*) 11 (0* + 10*)
2Find regular expression for the set of all strings over {a, b} in which the number of occurrences
of ‘a’ is divisible by 3.
Solution:
Here, the resultant regular expression denote the set of all strings over ∑ in which the number of
occurrence of ‘a’ is divisible by 3, i.e., the resultant regular expression will denotes the strings like
aaab, baaaaaa, etc.
To fix this problem, first of all, let us find the languages denoted by-
From equation (1), (2), (3) and (4), which is in first step, we have to find that in which language
denoted by a particular regular expression, the number of occurrence of a varies.
Thus, after seeing carefully all the four regular expressions, we found that from equation (1), (2), (3),
and (4), which is in first step, the number of occurrence of varies only in equation (1) and (4).
Now, we can formally write equation (5) and (6) in the following mathematically form-
Part 1: Which contains such number of a’s which is not divisible by 3, and let us denote it by a1 i*, |
where, i = 1, 2, 4, 5, 7, 8 .. .. .. .. and soon.
Part 2: Which contains such number of a’s which is divisible by 3, and let us denote it by a2 i*, |
where, i = 0, 3, 6, 9, 12, .. .. .. .. and soon.
Similarly, we can break the regular expression of equation (8) into the following two parts are as
follows-
Part 3: Which contains such number of a’s which is not divisible by 3, and let us denote it by ba1 i*, |
where, i = 1, 2, 4, 5, 7, 8 .. .. .. .. and soon.
Part 4: Which contains such number of a’s which is divisible by 3, and let us denote it by ba2 i*, |
where, i = 0, 3, 6, 9, 12, .. .. .. .. and soon
Now, we can get the regular expression in which the number of occurrence of a’s is not divisible by 3.
It is-
a1i* + ba1i*
Now, we can also get the regular expression in which the number of occurrences of a’s is divisible by
3. It is-
a2i* + ba2i*
Thus the resultant regular expression over input alphabets ∑= {a, b} in which the number of
occurrences of a’s is divisible by 3 can be given by-
3Find a regular expression for the language of all strings not containing the substring 000 over
∑ = {0, 1}.
Solution:
Here, the resultant regular expression denotes the set of all strings over the given ∑ which does not
contain a substring 000.
Here, we can describe the given statement i.e., “The resultant regular expression does not contain any
string which has a substring 000”, in the following other ways-
Here, following are the substrings of length 2 which can be immediately followed by a single zero
over the given input alphabets ∑ = {0, 1}-
Thus a single zero can be followed by the substring 01, 10 and 11.
Thus the string under the resultant regular expression can contain the substrings-
Here, the substring 00 can be followed either by 0 or 1 (since length of the given substring, i.e., 000 is
3).
Thus the strings under the resultant regular expression can contain a substring-
001 (2)
1. c) Any substring of length 3 whose both first and last symbol is ‘0’ does not contain ‘0’ as its
middle symbol.
Thus, this substring can contain only ‘1’ as its middle symbol.
Thus, strings under the resultant regular expression can contain the substring-
010 (3)
From equation (1), (2) and (3), we can get the form of resultant regular expression-
But, this regular expression contains λ, the empty string, which is not required. Thus the resultant
non-empty regular expression is-