- 2073 Chaitra
RE: even a's followed by odd b's
Short answer
(aa)* b (bb)*. Zero or more pairs of a's, then exactly one b followed by zero or more pairs of b's, ensuring odd total b's. Equivalent form: (aa)*(bb)*b.
Write a regular expression for an even number of 'a' followed by an odd number of 'b' over the alphabet Σ = {a, b}.
Answer: (aa)* b (bb)*
Explanation.
- (aa)* generates a string of a's of even length: ε, aa, aaaa, ... (zero is even).
- b(bb)* generates a string of b's of odd length: b, bbb, bbbbb, ...
- Concatenating them puts all the a's first and then the b's, as required.
Examples
- b (0 a's, 1 b) ∈ L.
- aabbb (2 a's, 3 b's) ∈ L.
- aab (2, 1) ∈ L.
- aabb (even number of b's) ∉ L, and aba (an a after a b) ∉ L.
Equivalent form: (aa)*(bb)*b.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- DFA: even a and odd b · Theory of Computation, chapter 2
- Regular grammar to RE and FA · Theory of Computation, chapter 2
- Regular expression with substring 0101 · Theory of Computation, chapter 2
- Every RE has NFA; ε-NFA for bb(a∪b)*ab · Theory of Computation, chapter 2
- RE: no more than 3 a's · Theory of Computation, chapter 2
- CFG for RE 0*1(0∪1)* · Theory of Computation, chapter 3
- Handshaking theorem; even number of odd vertices · Discrete Structure, chapter 4 · asked 3×
- Count even and odd until -1 · Computer Programming, chapter 5
- Even and odd parts of a signal · Data Communication, chapter 2
- Even/odd parts; time scaling and folding · Signals and Systems, chapter 1