Answer: 3
To find the length of the shortest string not in the language of the regular expression R=a∗b∗(ba)∗a∗, we can test strings of increasing lengths over Σ={a,b}:
- Length 0: ϵ is in L(R) (by choosing a0b0(ba)0a0).
- Length 1:
- a=a1b0(ba)0a0∈L(R)
- b=a0b1(ba)0a0∈L(R)
- Length 2:
- aa=a2b0(ba)0a0∈L(R)
- ab=a1b1(ba)0a0∈L(R)
- ba=a0b0(ba)1a0∈L(R)
- bb=a0b2(ba)0a0∈L(R)
Since all strings of length ≤2 are in L(R), the shortest string not in L(R) must have a length of at least 3. Let us test the string bab of length 3:
Suppose bab∈L(R). Then bab=w1w2w3w4 where w1∈a∗, w2∈b∗, w3∈(ba)∗, and w4∈a∗.
- Since bab starts with b, we must have w1=ϵ.
- Since bab ends with b, we must have w4=ϵ.
- This simplifies the match to bab=w2w3 where w2∈b∗ and w3∈(ba)∗.
- If w3=ϵ, then bab=w2∈b∗, which is false.
- If w3=ba, then bab=w2ba⟹w2=b, giving bba=bab.
- If ∣w3∣≥4, the length exceeds 3.
Thus, bab∈/L(R). The length of the shortest string not in the language is 3.