Question
The length of the shortest string NOT in the language (over ) of the following regular expression is _____.
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 .
-
Length 0:
- : generated with exponents ().
-
Length 1:
- : .
- : .
All length-1 strings are generated.
-
Length 2:
- : .
- : .
- : .
- : .
All length-2 strings are generated.
-
Length 3:
- : .
- : .
- : .
- : .
- : .
- : .
- : .
- Now consider :
- If the term has exponent , strings have the form , where all 's must be contiguous; hence cannot be formed.
- If the term has exponent , the string ends with . Since ends in and is followed only by , any such string must end with .
- Since ends with , it cannot be formed with for .
Therefore, .
-
The string has length , and all strings of length are in the language.
Hence, the length of the shortest string NOT in the language is .
3
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.