Skip to main content

RE: no more than 3 a's

Short answer

b* (a+ε) b* (a+ε) b* (a+ε) b*. This allows 0 to 3 a's with any number of b's around and between them. Alternatively, union of b*, b*ab*, b*ab*ab*, b*ab*ab*ab*.

Let Σ = {a, b}. Write a regular expression for the language with all strings in Σ* with no more than 3 a's.

Answer: b* (a + ε) b* (a + ε) b* (a + ε) b*

Explanation. The strings with at most three a's have 0, 1, 2 or 3 a's, and any number of b's between and around them. Each factor (a + ε) chooses to include an a or not; b* may appear before, between and after.

b*  (a|ε)  b*  (a|ε)  b*  (a|ε)  b*

Examples

  • ε, b, bbb (0 a's) ∈ L.
  • bab, abab, baba, abbab (≤ 3 a's) ∈ L.
  • ababab (3 a's) ∈ L, but abaaba (4 a's) ∉ L.

Alternative form: b* + bab + babab* + bababab (a union of the cases 0, 1, 2, 3 a's).

✓ Answer checked by Claude Opus 5.5 (high effort)

All Theory of Computation chapter 2 questions →