GATE / CS ARCHIVE

GATE CSE 2021 SET 2 / QUESTION 47

GATE CSE 2021 Set 2 Q47

Theory of Computation · Regular Expressions & Languages · Full GATE CSE 2021 Set 2 paper

GATE 2021 Set 2, Q47 2 marks · MSQ
Report issue

Regular Expressions & Languages

Question 47, GATE 2021: Which regexes describe binary multiples of three, allowing leading zeros and ε? A (0+1(01*0)*1)*; B (0+11+10(1+00)*01)*; C (0*(1(01*0)*1)*)*; D (0+11+11(1+00)*00)*. + denotes union.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: A; B; C

Use the remainder automaton r→(2r+b) mod3, start/accept 0. A describes concatenated excursions from 0: a 0 stays at 0, while 1 enters remainder 1, any number of blocks 01*0 returns to 1 via remainder 2, and final 1 returns to 0. B describes the same excursions by separating 11 from 10(1+00)*01: at remainder 2, either 1 or 00 loops back to 2, then 01 exits to 0. C is equivalent to A because arbitrary concatenations of zeros and nonzero excursions can be grouped into runs of zeros followed by runs of excursions. D is wrong: it cannot generate 1001 (binary9); every nonempty D word beginning 1 begins 11. Thus A, B, C. Leading zeros and the empty string are allowed as stated.

The remainder transition table is 0:0→0,1→1; 1:0→2,1→0; 2:0→1,1→2. A complete path from 0 back to 0 can be decomposed at every visit to state 0. This yields the excursion regex used in A. The counterexample 1001 has numeric value 9, so rejecting it conclusively refutes D without needing exhaustive enumeration.

Original paper, page 84 · Answer key