Question

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^*
Official answer and solution
Official answer
3
From
Official GATE 2014 answer key

Solution

Systematically test strings over {a, b} by increasing length to identify the shortest string outside the language.

Given regular expression R=a∗b∗(ba)∗a∗R = a^* b^* (ba)^* a^*.

  1. Length 0:

    • ϵ\epsilon: generated with exponents 0,0,0,00, 0, 0, 0 (a0b0(ba)0a0=ϵa^0 b^0 (ba)^0 a^0 = \epsilon).
  2. Length 1:

    • aa: a1b0(ba)0a0=aa^1 b^0 (ba)^0 a^0 = a.
    • bb: a0b1(ba)0a0=ba^0 b^1 (ba)^0 a^0 = b.
      All length-1 strings are generated.
  3. Length 2:

    • aaaa: a2b0(ba)0a0=aaa^2 b^0 (ba)^0 a^0 = aa.
    • abab: a1b1(ba)0a0=aba^1 b^1 (ba)^0 a^0 = ab.
    • baba: a0b0(ba)1a0=baa^0 b^0 (ba)^1 a^0 = ba.
    • bbbb: a0b2(ba)0a0=bba^0 b^2 (ba)^0 a^0 = bb.
      All length-2 strings are generated.
  4. Length 3:

    • aaaaaa: a3∈La^3 \in L.
    • aabaab: a2b1∈La^2 b^1 \in L.
    • abaaba: a1b0(ba)1a0=aba∈La^1 b^0 (ba)^1 a^0 = aba \in L.
    • abbabb: a1b2∈La^1 b^2 \in L.
    • baabaa: a0b0(ba)1a1=baa∈La^0 b^0 (ba)^1 a^1 = baa \in L.
    • bbabba: a0b2(ba)0a1=bba∈La^0 b^2 (ba)^0 a^1 = bba \in L.
    • bbbbbb: b3∈Lb^3 \in L.
    • Now consider babbab:
      • If the (ba)∗(ba)^* term has exponent 00, strings have the form a∗b∗a∗a^* b^* a^*, where all bb's must be contiguous; hence babbab cannot be formed.
      • If the (ba)∗(ba)^* term has exponent ≥1\ge 1, the string ends with (ba)kam(ba)^k a^m. Since (ba)(ba) ends in aa and is followed only by a∗a^*, any such string must end with aa.
      • Since babbab ends with bb, it cannot be formed with (ba)k(ba)^k for k≥1k \ge 1.
        Therefore, bab∉L(R)bab \notin L(R).
  5. The string babbab has length 33, and all strings of length <3< 3 are in the language.

Hence, the length of the shortest string NOT in the language is 33.

Final answer

3

Common trap

Missing that bab requires b both before and after a while ending in b, which is impossible in a* b* (ba)* a*.

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

Source

Paper
GATE 2014 Computer Science and Information Technology (CS) Session 3
Question
25 of 65, printed as CS Q.15
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.