Question
Which one of the following regular expressions represents the set of all binary strings with an odd number of 1's?
Official answer and solution
- Official answer
- D
- From
- Official GATE 2020 answer key
Official answer key retained D. Some coaching keys noted that option D misses strings starting with 0 followed by an odd number of 1s (such as '01'), but official key was finalized as D.
Solution
Analyze the structure of the regular expressions to identify which expression forces the total number of 1's to be odd.
Examine the component parts of the expressions:
- In option D, :
- The sub-expression inside the Kleene star, , contains exactly two 1's surrounded by arbitrary runs of 0's. Any repetition of this block generates an even count of 1's ().
- Following the star, the term contributes exactly one additional 1, bringing the grand total of 1's to an odd number ().
Why other options fail:
- Option A: contains which can itself generate arbitrary numbers of 1's, so the count is not guaranteed to be odd.
- Option B: requires the string to end with a 1, failing to match strings with an odd count of 1's that end in 0 (e.g., '10').
- Option C: requires the string to begin with a 1, failing to match strings that begin with 0 (e.g., '01').
Note on official key: While option D omits strings with leading 0's before the first 1 (such as '01'), IIT Delhi retained option D as the official answer.
D
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2020 Computer Science and Information Technology (CS)
- Question
- 17 of 65, printed as CS Q.7
- 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.