Question

Let L1L_1 be the language represented by the regular expression b∗ab∗(ab∗ab∗)∗b^*ab^*(ab^*ab^*)^* and L2={w∈(a+b)∗∣∣w∣≤4}L_2 = \{w \in (a + b)^* \mid |w| \le 4\}, where ∣w∣|w| denotes the length of string ww. The number of strings in L2L_2 which are also in L1L_1 is ___________

Official answer and solution
Official answer
15
From
Official GATE 2024 answer key

Solution

Observe that L1=b∗ab∗(ab∗ab∗)∗L_1 = b^*ab^*(ab^*ab^*)^* is the set of all strings over {a,b}\{a, b\} with an odd number of aa's, and count such strings of length 0≤∣w∣≤40 \le |w| \le 4.

The regular expression L1=b∗ab∗(ab∗ab∗)∗L_1 = b^*ab^*(ab^*ab^*)^* matches all strings over {a,b}\{a, b\} that contain an odd number of aa's (1,3,5,…1, 3, 5, \dots occurrences of aa).

For each string length k∈{0,1,2,3,4}k \in \{0, 1, 2, 3, 4\} in L2L_2:

  • k=0k = 0: ϵ\epsilon has 00 aa's (00 strings).
  • k=1k = 1: 21−1=12^{1-1} = 1 string (a).
  • k=2k = 2: 22−1=22^{2-1} = 2 strings (ab, ba).
  • k=3k = 3: 23−1=42^{3-1} = 4 strings ((31)+(33)=3+1=4\binom{3}{1} + \binom{3}{3} = 3 + 1 = 4).
  • k=4k = 4: 24−1=82^{4-1} = 8 strings ((41)+(43)=4+4=8\binom{4}{1} + \binom{4}{3} = 4 + 4 = 8).

Total number of strings in L1∩L2=0+1+2+4+8=15L_1 \cap L_2 = 0 + 1 + 2 + 4 + 8 = 15.

Final answer

15

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2024 Computer Science and Information Technology - Set 2 (CS2)
Question
62 of 65
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.