Skip to content
Official PYQ · 2024

GATE CS 2024 Set 2 Q52 — Regular Expressions and Finite Automata

Explain with AI
Let L1L_{1} be the language represented by the regular expression b∗ab∗(ab∗ab∗)∗b^{*} a b^{*}\left(a b^{*} a b^{*}\right)^{*} and L2={w∈(a+b)∗∣∣w∣≤4}L_{2}=\left\{w \in(a+b)^{*}|| w \mid \leq 4\right\}, where ∣w∣|w| denotes the length of string ww. The number of strings in L2L_{2} which are also in L1L_{1} is _________.
View worked solution

Answer: 15

First, let us analyze the language L1L_1 represented by the regular expression b∗ab∗(ab∗ab∗)∗b^* a b^* (a b^* a b^*)^*.

  • The term b∗ab∗b^* a b^* generates strings containing exactly one aa.
  • The term (ab∗ab∗)∗(a b^* a b^*)^* generates strings containing an even number of aa's (multiples of 2).

Combining these, the regular expression generates strings with an odd number of aa's. Thus, L1L_1 is the set of all strings over {a,b}\{a, b\} containing an odd number of aa's.

The language L2L_2 consists of all strings over {a,b}\{a, b\} of length at most 44. We need to find the number of strings in L2∩L1L_2 \cap L_1, which are strings of length n≤4n \le 4 with an odd number of aa's.

For any length n≥1n \ge 1, exactly half of the 2n2^n possible strings contain an odd number of aa's, which is 2n−12^{n-1} strings. We calculate this for each length nn:

  • Length n=0n = 0: 00 strings (even number of aa's).
  • Length n=1n = 1: 20=12^0 = 1 string ({a}\{a\}).
  • Length n=2n = 2: 21=22^1 = 2 strings ({ab,ba}\{ab, ba\}).
  • Length n=3n = 3: 22=42^2 = 4 strings ({abb,bab,bba,aaa}\{abb, bab, bba, aaa\}).
  • Length n=4n = 4: 23=82^3 = 8 strings.

Summing these up, the total number of strings is:

1+2+4+8=151 + 2 + 4 + 8 = 15

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Regular Expressions and Finite Automata questions