Skip to content
Official PYQ · 2014

GATE CS 2014 Set 3 Q15 — Regular Expressions and Finite Automata

Explain with AI
The length of the shortest string NOT in the language (over Σ={a,b})\Sigma = \{a, b\}) of the following regular expression is _______.
a∗b∗(ba)∗a∗a^*b^*(ba)^*a^*
View worked solution

Answer: 3

To find the length of the shortest string not in the language of the regular expression R=a∗b∗(ba)∗a∗R = a^*b^*(ba)^*a^*, we can test strings of increasing lengths over Σ={a,b}\Sigma = \{a, b\}:

  • Length 0: ϵ\epsilon is in L(R)L(R) (by choosing a0b0(ba)0a0a^0 b^0 (ba)^0 a^0).
  • Length 1:
    • a=a1b0(ba)0a0∈L(R)a = a^1 b^0 (ba)^0 a^0 \in L(R)
    • b=a0b1(ba)0a0∈L(R)b = a^0 b^1 (ba)^0 a^0 \in L(R)
  • Length 2:
    • aa=a2b0(ba)0a0∈L(R)aa = a^2 b^0 (ba)^0 a^0 \in L(R)
    • ab=a1b1(ba)0a0∈L(R)ab = a^1 b^1 (ba)^0 a^0 \in L(R)
    • ba=a0b0(ba)1a0∈L(R)ba = a^0 b^0 (ba)^1 a^0 \in L(R)
    • bb=a0b2(ba)0a0∈L(R)bb = a^0 b^2 (ba)^0 a^0 \in L(R)

Since all strings of length ≤2\le 2 are in L(R)L(R), the shortest string not in L(R)L(R) must have a length of at least 33. Let us test the string babbab of length 3:

Suppose bab∈L(R)bab \in L(R). Then bab=w1w2w3w4bab = w_1 w_2 w_3 w_4 where w1∈a∗w_1 \in a^*, w2∈b∗w_2 \in b^*, w3∈(ba)∗w_3 \in (ba)^*, and w4∈a∗w_4 \in a^*.

  • Since babbab starts with bb, we must have w1=ϵw_1 = \epsilon.
  • Since babbab ends with bb, we must have w4=ϵw_4 = \epsilon.
  • This simplifies the match to bab=w2w3bab = w_2 w_3 where w2∈b∗w_2 \in b^* and w3∈(ba)∗w_3 \in (ba)^*.
  • If w3=ϵw_3 = \epsilon, then bab=w2∈b∗bab = w_2 \in b^*, which is false.
  • If w3=baw_3 = ba, then bab=w2ba  ⟹  w2=bbab = w_2 ba \implies w_2 = b, giving bba≠babbba \neq bab.
  • If ∣w3∣≥4|w_3| \ge 4, the length exceeds 3.

Thus, bab∉L(R)bab \notin L(R). The length of the shortest string not in the language is 3.

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

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