GATE / CS ARCHIVE

GATE CSE 2010 / QUESTION 39

Regular expression for even parity

Theory of Computation · Regular Expressions & Languages · Full GATE CSE 2010 paper

GATE 2010, Q39 2 marks · MCQ
Report issue

Regular Expressions & Languages

Question 39, GATE 2010: Let L be all binary strings with an even number of 1s, including zero 1s. Which regular expression represents L? Concatenation is implicit and * denotes Kleene star.
Options: (A) (0*10*1)*; (B) 0*(10*10*)*; (C) 0*(10*1)*0*; (D) 0*1(10*1)*10*.
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

A binary string with an even number of 1s can be decomposed into initial zeros followed by zero or more pairs of 1s, with any number of zeros after each 1. This is exactly 0*(10*10*)*, option B. Each repeated block contributes two 1s, while any string with 2k ones can be split into k such blocks. The outer star includes the zero-ones case, including epsilon.

Why the alternatives fail: A cannot generate a nonempty all-zero string; C cannot generate 11011, whose zero separates two adjacent pairs of ones; D always has at least its two explicit outer ones and therefore misses epsilon and all-zero strings. B allows arbitrary zeros before, between and after every pair, and its repetition count can be zero.

Original paper, page 9