Which one of the following regular expressions represents the language: the set of all binary strings having two consecutive 's and two consecutive 's?
View worked solution
Answer: B
The language consists of all binary strings that contain both 00 and 11 as substrings. These two substrings can appear in either order:
00appears before11: This is represented by the regular expression:11appears before00: This is represented by the regular expression:
Combining both cases using the union () operator, we get:
By factoring out the common prefix and common suffix , we get the equivalent expression:
This matches Option B.
Why other options are incorrect:
- Option A: Requires
00and11to be immediately adjacent to each other (i.e., as0011or1100). It fails to generate strings like where they are separated. - Option C: Represents strings containing
00or11(or both). For example, it generates , which does not contain consecutive 's. - Option D: Forces the string to start with
00or11and end with the other. It fails to generate strings like which has arbitrary prefix and suffix.
Free practice · Your answers on this page are not saved.
