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

Notes For Regular Expression

Uploaded by

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

Notes For Regular Expression

Uploaded by

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

1:Find the regular expression for the set of all strings over input alphabets ∑ = {0, 1} having

atmost one pair of 0’s or atmost one pair of 1’s.

Solution:

We have the input alphabets ∑ = {0, 1}.

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-

0* = {λ, 0, 00, 000, 0000, 00000, .. .. .. ..} (1)


01* = {0, 01, 011, 0111, 01111, 011111, .. .. .. .. ..} (2)
1* = {λ, 1, 11, 111, 1111, 11111, .. .. .. ..} (3)
10* = {1, 10, 100, 1000, 10000, 100000, .. .. .. .. ..} (4)

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.

Thus, here the regular expressions-

1* and 01*

does not contain a pair of 0’s.

We can write these two of 0’s as-

(1* + 01*) (5)


Now, to find the regular expression that contains exactly one pair of 0’s, we simply write the regular
expression which does not contains a pair of 0’s on the both side of the pair of 0’s, i.e. 00. Thus, the
regular expression which contains exactly one pair of 0’s can be written as-

(1* + 01*) 00 (1* + 01*) (6)

Now, similarly we can easily find out that which regular expression does not contain a pair of 1’s, i.e.,
11.

Thus, here the regular expressions-

0* and 10*

does not contain a pair of 1’s.

We can write these two of 1’s as-

(0* + 10*) (7)


Thus, (0* + 10*) is a regular expression that contains no pair of 1’s.
Now, similarly to find the regular expression that contains exactly one pair of 1’s, we simply write the
regular expression which does not contains a pair of 1’s on the both side of the pair of 1’s, i.e. 11.
Thus, the regular expression which contains exactly one pair of 1’s can be written as-

(0* + 10*) 11 (0* + 10*) (8)

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:

We have the input alphabets ∑ = {a, b}

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-

a* = {λ, a, aa, aaa, aaaa, aaaaa, .. .. .. .. ..} (1)


b* = {λ, b, bb, bbb, bbbb, bbbbb, .. .. .. ..} (2)
ab* = {a, ab, abb, abbb, abbbb, abbbbb, .. .. .. ..} (3)
ba* = {b, ba, baa, baaa, baaaa, baaaaa, .. .. .. .. ..} (4)

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).

Thus, let us distinguish equation (1) an (4) as-

a* = {λ, a, aa, aaa, aaaa, aaaaa, .. .. .. .. ..} (5)


ba* = {b, ba, baa, baaa, baaaa, baaaaa, .. .. .. .. ..} (6)

Now, we can formally write equation (5) and (6) in the following mathematically form-

ai* = {λ, a, aa, aaa, aaaa, aaaaa, .. .. .. .. ..} (7)


| where, i = 0, 1, 2, 3, 4, .. .. ….
bai* = {b, ba, baa, baaa, baaaa, baaaaa, .. .. .. .. ..} (8)
| where, i = 0, 1, 2, 3, 4, .. .. ….
Now, we can break the regular expression of equation (7) into the following two parts-

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*

| where, i = 1, 2, 4, 5, 7, 8 .. .. .. .. and soon.

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*

| where, i = 0, 3, 6, 9, 12, .. .. .. .. and soon

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-

(a1 + ba1)i* (a2 + ba2)i* (a1 + ba1)i*

This is the resultant regular expression.

3Find a regular expression for the language of all strings not containing the substring 000 over
∑ = {0, 1}.

Solution:

We have the input alphabets ∑ = {0, 1}

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-

1. a) No any zero is immediately followed by the substring 00.

Here, following are the substrings of length 2 which can be immediately followed by a single zero
over the given input alphabets ∑ = {0, 1}-

00, 01, 10 and 11


But from statement (a) no any zero can be immediately followed by the substring 00.

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-

001, 010 and 011 (1)

1. b) Substring 00 can’t be immediately followed by a single zero.

Here, the substring 00 can be followed either by 0 or 1 (since length of the given substring, i.e., 000 is
3).

But from statement (b) substring 00 can’t be immediately followed by 0.

Thus, substring 00 can be followed by 1 only.

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-

(001 + 010 + 011 + 001 + 010)*

Removing the duplicates, we get-

(001 + 010 + 011)*

But, this regular expression contains λ, the empty string, which is not required. Thus the resultant
non-empty regular expression is-

(001 + 010 + 011) (001 + 010 + 011)*

or, we can also write it as-

(001 + 010 + 011)+

This is the resultant regular expression.

You might also like