BC210200353 Assignment - 01 CS - 402
BC210200353 Assignment - 01 CS - 402
ASSIGNMENT_01
VU ID: BC210200353 NAME: TALHA SAJID
QUESTION_1:
a. Write the regular expression for language consists of all strings that ends and have exact
one b and can have any number of a’s (excluding none) before it, over the set of
alphabets Σ={a,b}.
Solution:
Regular expression for the language:
The strings that make up the language include:
End with exactly one b.
Can have at least one a before the b, but it can have any number of a's.
No b can appear in the string before the last b.
Thus, the regular expression can be written as:
a+b
Solution: a
a b
q0 q1
q2
QUESTION_2
Consider the language L of strings, defined over ∑= {a, b}, Write the answers of the following:
a) If the regular expression is (𝑎𝑏)*, how many different strings of length 4 are in this
language?
Solution:
Regular Expression: (ab)*
The string "ab" has zero or more repetitions, as indicated by this regular expression.
For strings of length 4:
Each "ab" contributes 2 characters.
To create a string of length 4, we need two repetitions of "ab":
String: "abab"
b) If the regular expression is (𝑎∣𝑏)2, how many strings of length 2 can it generate?
Solution:
Regular Expression: (a|b)²
Two characters are permitted under this regular expression, and each character may
independently be either "a" or "b."
The | operator represents a choice between 'a' or 'b'.
Total number of strings of length 2:
Each character has 2 options ('a' or 'b').
For two positions, the total number of strings is: 2x2=4
Generated strings:
aa, ab, ba, bb
Number of strings of length 2:
4
c) If the regular expression is (𝑎𝑏∣𝑏𝑎)2, how many distinct strings of length 4 can be
generated?
Solution:
c) Regular Expression: (ab|ba)2