Computer Sciences > Gate 2016 Set-1 > Regular Language
Which one of the following regular expressions represents the language: the set of all binary strings having two consecutive 0s and two consecutive 1s?
A
(0+1)*0011(0+1)* + (0+1)*1100(0+1)*
B
(0+1)* (00(0+1) *11+11(0+1)*00)(0+1)*
C
(0+1)*00(0+1) *+ (0+1) *11(0+1) *
D
00(0+1) *11+11(0+1)*00

Correct : R

Given:
Language: Set of all binary strings containing both two consecutive 0s and two consecutive 1s.
Alphabet: Σ = {0, 1}.
To find:
The correct regular expression for this language.
Solution:
The condition states that every string in the language must contain the substring "00" AND the substring "11".
Since "00" and "11" share no common characters, they cannot overlap at all.
This means in any valid string, either "00" comes before "11", or "11" comes before "00".
Let me write the regular expression for the first case, where "00" appears before "11":
(0+1)*00(0+1)*11(0+1)*
Now for the second case, where "11" appears before "00":
(0+1)*11(0+1)*00(0+1)*
Combining both cases using union (+), I get:
(0+1)*00(0+1)*11(0+1)* + (0+1)*11(0+1)*00(0+1)*
Now I can factor out (0+1)* from the left and right sides:
(0+1)*(00(0+1)*11 + 11(0+1)*00)(0+1)*
Let me check the other options just to be completely sure.
Option A requires "00" and "11" to be immediately adjacent to each other, so it misses strings like "001011".
Option C uses union between the two conditions, which represents strings with "00" OR "11", not AND.
Option D forces the string to start with "00" or "11" and end with "11" or "00", so it misses strings like "100110".
So only option B correctly captures the required language.
Answer:
(B) (0+1)* (00(0+1) *11+11(0+1)*00)(0+1)*

Similar Questions

Let L1 and L2 be any context-free language and R be any regular language. Then, which of the following is correct ? I. L1 ∪ L2 is context-free. II. L1' is cont...
#166 MCQ
For Σ = {a, b}, let us consider the regular language L = {x ∣ x = a2+ 3k or x = b10 + 12k, k ≥ 0} Which one of the following can be a pumping length (the co...
#252 MCQ
Consider the following languages. L1 = { wxyx ∣ w,x,y ∈ (0+1)+ } L2 = { xy ∣ x,y ∈ (a+b)*, ∣x∣=∣y∣, x≠y } Which one of the following is TRUE ?
#279 MCQ

Related Topics

regular expressions binary strings regex consecutive 0s and 1s GATE Computer Science 2016 GATE CS 2016 Set-1 Q21 formal languages automata language representation regex regex 00 and 11

Unique Visitor Count

Total Unique Visitors

Loading......