Skip to main content

Design FSA accepting odd number of b's

Short answer

The DFA has states E (even, start) and O (odd, final). On a, stay in current state; on b, switch state. It accepts exactly strings with an odd number of b's.

Design a Finite State Automata that accepts precisely those strings over {a, b} that contain an odd number of b's. Your design should include the proper definition of the finite-state automaton, transition table and the transition diagram.

Idea

Track the parity of the number of b's read. State E: even number of b's (start). State O: odd number of b's (final). Reading b switches state; reading a keeps it.

Formal definition

M = (Q, Σ, δ, q₀, F) where Q = {E, O}, Σ = {a, b}, q₀ = E, F = {O}, and δ is:

Transition table

Stateab
→ EEO
*OOE

Transition diagram

        a                       a
       ┌─┐                     ┌─┐
       ↓ │                     ↓ │
 ──→ ( E ) ────────b─────────→ (( O ))
         ↑                         │
         └───────────b─────────────┘

Trace

  • "abb": E –a→ E –b→ O –b→ E. Rejected (2 b's).
  • "bab": E –b→ O –a→ O –b→ E. Rejected.
  • "aabbb": E –a→ E –a→ E –b→ O –b→ E –b→ O. Accepted (3 b's).

The language is L = {w ∈ {a, b}* : number of b's is odd} = ab a(b ab a)*. I verified the machine against the b-count for all strings up to length 8.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Discrete Structure chapter 2 questions →