Skip to main content

Design FSA accepting even number of a's

Short answer

The DFA has states q0 (even a's, start and final) and q1 (odd). On 'a', toggle state; on 'b' remain. Transition table: q0 –a→ q1, –b→ q0; q1 –a→ q0, –b→ q1. It accepts strings over {a,b} with an even number of a's.

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

Idea

We only need to remember whether the number of a's read so far is even or odd. So two states are enough: q0 (even number of a's, including zero) and q1 (odd number). Reading a toggles the state; reading b does not change it.

Formal definition

M = (Q, Σ, δ, q0, F) where

  • Q = {q0, q1}
  • Σ = {a, b}
  • Start state q0
  • F = {q0} (final state, since the empty string has zero a's, which is even)
  • δ is given by the table below.

Transition table

Stateab
→ *q0q1q0
q1q0q1

(→ start state, * final state)

Transition diagram

          b                      b
         ┌─┐                    ┌─┐
         ↓ │                    ↓ │
  ──→ (( q0 )) ───────a──────→ ( q1 )
            ↑                     │
            └──────────a──────────┘

Trace

  • "abab": q0 –a→ q1 –b→ q1 –a→ q0 –b→ q0. Ends in q0, accepted (2 a's).
  • "baab": q0 –b→ q0 –a→ q1 –a→ q0 –b→ q0, accepted.
  • "ab": q0 –a→ q1 –b→ q1, rejected (1 a).

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

✓ Answer checked by Claude Opus 5.5 (high effort)

All Discrete Structure chapter 2 questions →