Regular Expressions & Languages

Answer & solution
Answer: C (no official key was published)
1. A is regular because the permitted zero counts are finitely many three-digit primes; count zeros up to the maximum with an overflow state. B tracks prefix imbalance in{−2,−1,0,1,2}, rejecting immediately outside that range.
2. D tracks zero count modulo 7 and one count modulo 5. C only bounds the final imbalance and allows arbitrarily large intermediate imbalance.
3. Intersect C with 0*1* and pump 0p1p: pumping a nonempty block of initial zeros sufficiently many times makes the final difference exceed 4. Hence C is not regular.
4. Teaching check: A bound on every prefix permits a finite-state machine to reject immediately when its imbalance leaves a fixed range. A bound only on the final string allows arbitrarily large positive imbalance followed by enough ones to cancel it. Tracking this unbounded debt cannot be done with finitely many states.