Question
Which one of the following regular expressions represents the language: the set of all binary strings having two consecutive 0s and two consecutive 1s?
Official answer and solution
- Official answer
- B
- From
- Official GATE 2016 answer key
Solution
Construct a regular expression ensuring the presence of both substrings 00 and 11 in either order.
The condition requires that any valid string contains both the substring 00 and the substring 11.
In any such string, either 00 appears before 11, or 11 appears before 00:
- If
00appears before11: The string has the form . - If
11appears before00: The string has the form
Factoring out the outer terms yields:
Comparing with other options:
- Option A requires
00and11to be immediately adjacent (0011or1100), missing strings like001011. - Option C uses addition (), which represents strings having two consecutive 0s OR two consecutive 1s.
- Option D omits arbitrary leading and trailing bits.
B
Choosing option A, which enforces adjacent substrings 0011 or 1100 and omits intervening characters.
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2016 Computer Science and Information Technology (CS) Session 1
- Question
- 28 of 65, printed as CS Q.18
- 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.