Professional Documents
Culture Documents
Cs 401
Cs 401
Cs 401
Question#1:
Consider the language L of strings, defined over ∑= {a, b}, Write regular expressions of
following:
a. Strings starting with “b” and ending with “a” having “ab” as a substring.
Solution:
(a+b): Any number of a’s or b’s
Ab: Ensures “ab” as a substring
(a+b)*: Any number of a’s or b’s
This ensures that the string starts with “b”, ends with “a”, and has “ab” as a substring
b(a+b)*ab(a+b)*a
b. Strings containing even number of a’s and ending with “baba” or “bb”.
Solution:
(a+b)*: Any number of a’s or b’s
aa: Ensures even number of a’s
(a+b)*: Any number of a’s or b’s
(baba+bb): Ends with either “baba” or “bb”
(a+b)*aa(a+b)*(baba+bb)
c. String that having NULL or starts with “a” and having no consecutive b’s in it.
Solution:
(a+ab)*: Zero or more occuuuences of “a” or “ab”
This ensures either an empty string (NULL) or a string starting with “a” and having no
consecutive b’s
Question#2: