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

CS402 Solution

d

Uploaded by

princeimups2018
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

CS402 Solution

d

Uploaded by

princeimups2018
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Questions No 01 Marks: 5+6 =

111=

a.
exact one b and can have any number of a’s (excluding none) before it, over the
Write the regular expression for language consists of all strings that ends and have

set of alphabets Σ={a,b}.

SOLUTION:

The language consists of all strings that:


1. End with exactly one b.
2. Can have any number of a’s (at least one) before it.
3. Excludes any additional b other than the one at the end.
Given these conditions, the regular expression over the alphabet Σ={a,b} is R = a+b

Where:
 a+: Represents one or more occurrences of a.
 b: Represents exactly one b at the end.

b. Draw the Finite Automaton for above language?


Question No 2: Marks: 3+3+3=9
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?
b) If the regular expression is (𝑎∣𝑏)2, how many strings of length 2 can it generate?
If the regular expression is (𝑎𝑏∣𝑏𝑎)2, how many distinct strings of length 4 can be generated?

SOLUTION:

Part (a): Regular Expression: (ab)∗(ab)^*


The expression (ab)∗(ab)^* means any number (including zero) of repetitions of the
substring abab. For strings of length 4:
 Length 4 means exactly two abab substrings are required, as each abab contributes
2 characters.
Possible string of length 4:
 abababab
Answer: There is 1 string of length 4 in this language.

Part (b): Regular Expression: (a∣b)2(a \mid b)^2


The expression (a∣b)2(a \mid b)^2 means strings of length 2 where each character can be
either aa or bb. To calculate the total number of strings:
 Each character has 2 choices (aa or bb).
 For 2 characters, the total combinations are: 2×2=42 \times 2 = 4
Possible strings:
 aa,ab,ba,bbaa, ab, ba, bb
Answer: There are 4 strings of length 2 in this language.

Part (c): Regular Expression: (ab∣ba)2(ab \mid ba)^2


The expression (ab∣ba)2(ab \mid ba)^2 means strings of length 4 formed by
concatenating two substrings, each of which can be abab or baba. To calculate the total
number of distinct strings:
 Each substring has 2 choices (abab or baba).
 For 2 substrings, the total combinations are: 2×2=42 \times 2 = 4
Possible strings:
 abab,abba,baab,baba
Answer: There are 4 distinct strings of length 4 in this language.

Final Answers:
 (a): 1 string.
 (b): 4 strings.
 (c): 4 strings.

You might also like