GATE / CS ARCHIVE

GATE CSE 2016 SET 1 / QUESTION 18

GATE CSE 2016 Set 1 Q18

Theory of Computation · Regular Expressions & Languages · Full GATE CSE 2016 Set 1 paper

GATE 2016 Set 1, Q18 1 mark · MCQ
Report issue

Regular Expressions & Languages

Question 18, GATE 2016: Let Σ={0,1}; + denotes union and * Kleene star. Which regex specifies strings containing both 00 and 11 as substrings? A: Σ*0011Σ*+Σ*1100Σ*. B: Σ*(00Σ*11+11Σ*00)Σ*. C: Σ*00Σ*+Σ*11Σ*. D:00Σ*11+11Σ*00.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

A word must contain both a 00 occurrence and a 11 occurrence, in either order, with an arbitrary middle substring and arbitrary prefix/suffix. They cannot overlap because their symbols differ. Hence Σ*(00Σ*11+11Σ*00)Σ*, B. A forces adjacent blocks, C requires only one, and D disallows arbitrary outside context.

Take the earlier of a 00 occurrence and a 11 occurrence. Their positions cannot overlap, so one appears before the other with some possibly empty substring between them. This establishes the two alternatives in B. As a diagnostic example,001011 has both required pairs separated by 10, so it is valid but A rejects it. C incorrectly accepts 00 alone; D rejects valid words with extra prefix or suffix. Arbitrary prefix, middle and suffix are all needed.

Original paper, page 9 · Answer key