Regular Expressions & Languages

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.