GATE / CS ARCHIVE

GATE CSE 2024 SET 1 / QUESTION 61

Count the complement of two regular languages

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

GATE 2024 Set 1, Q61 2 marks · NAT
Report issue

Regular Expressions & Languages

Question 61, GATE 2024: Over {0,1}, r=0*+1* and s=01*+10*, where + means union and * means Kleene star. Count strings of length at most 5 that belong to neither language, including the empty string in the universe.
Tap to enlarge
Answer & solution

Official answer: 44

Approach: Count all short binary strings, subtract the union of the two languages, and account for their overlap.
1. There are Σ from length 0 to 5 of 2^length =1+2+4+8+16+32=63 strings. The empty string is the single length-zero string.
2. Language r contains ε and, at each positive length 1–5, the all-zero and all-one strings. Thus |r within the limit|=1+2×5=11. Count ε only once even though both starred expressions generate it.
3. Language s contains a leading 0 followed by only 1s, or a leading 1 followed by only 0s. It has two strings at each length 1–5 and none at length zero, so its count is 10.
4. The overlap is exactly {0,1}. Longer strings in s contain both symbols, so cannot be in r. Inclusion-exclusion gives union size 11+10−2=19.
5. The complement count is 63−19=44.
Answer: 44. A lengthwise check gives 0,0,0,4,12,28 excluded strings at lengths 0 through 5, again totaling 44.

Original paper, page 35 · Answer key