GATE CS 2024 Set 2 — Question 62

NAT+2 / -0MediumRegular ExpressionsFinite Automata & Regular LanguagesTheory of Computation

Theory of Computation → Finite Automata & Regular Languages → Regular Expressions

Last updated

Question

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

Correct answer

15 to 15

Solution

1.Analyze L1L_1: The regular expression bab(abab)b^*ab^*(ab^*ab^*)^* represents the set of all strings over {a,b}\{a, b\} that contain an odd number of 'a's.
  • babb^*ab^* generates strings with exactly one 'a'.
  • (abab)(ab^*ab^*)^* generates strings with an even number of 'a's (including zero).
  • Concatenating them results in strings with 1+2k1 + 2k 'a's, which is always odd.
2. Analyze L2L_2: L2L_2 is the set of all strings over {a,b}\{a, b\} with length w4|w| \leq 4. This includes strings of length 0, 1, 2, 3, and 4.
3.Find L1L2L_1 \cap L_2: We need to count the number of strings of length 4\leq 4 that have an odd number of 'a's.
  • For any length n1n \geq 1, the number of strings with an odd number of 'a's is exactly half of the total strings, i.e., 2n12^{n-1}.
  • Length 0: Total strings = 20=12^0 = 1 (the empty string ϵ\epsilon). Number of 'a's = 0 (even). Count = 0.
  • Length 1: Count = 211=20=12^{1-1} = 2^0 = 1 (string is 'a').
  • Length 2: Count = 221=21=22^{2-1} = 2^1 = 2 (strings are 'ab', 'ba').
  • Length 3: Count = 231=22=42^{3-1} = 2^2 = 4 (strings are 'aaa', 'abb', 'bab', 'bba').
  • Length 4: Count = 241=23=82^{4-1} = 2^3 = 8 (strings are 'aaab', 'aaba', 'abaa', 'baaa', 'abbb', 'babb', 'bbab', 'bbba').
4. Total Count: Summing the counts for each length: 0+1+2+4+8=150 + 1 + 2 + 4 + 8 = 15.

More questions on Finite Automata & Regular Languages

Practice GATE CS PYQs with adaptive difficulty

Timed practice, skill tracking, and AI explanations — free to start.

Start practicing free