Minimum number of states in DFA for given language:

Minimum number of states in DFA for given language:
Answer: 6 — Key idea: use Myhill–Nerode (right-invariant residuals) to count distinct states. Describe the language: L = {a^n | n = 3 or n = 2m for some m ≥ 1}. Accepted…
Attempted by 59 students.
Show answer & explanation
Correct answer: 6
Key idea: use Myhill–Nerode (right-invariant residuals) to count distinct states.
Describe the language:
L = {a^n | n = 3 or n = 2m for some m ≥ 1}.
Accepted lengths: 2, 3, 4, 6, 8, ... (all even ≥ 2, plus 3).
Compute residuals R_i = {k ≥ 0 | i + k ∈ L} for small i (these correspond to different states if they differ):
R0 = {k | k ∈ L} = {2,3,4,6,8,...}.
R1 = {k | 1 + k ∈ L} = {1,2,3,5,7,9,...}.
R2 = {k | 2 + k ∈ L} = {0,1,2,4,6,8,...}.
R3 = {k | 3 + k ∈ L} = {0} ∪ {odd k ≥ 1} = {0,1,3,5,7,...}.
For any i ≥ 4 the future behavior is periodic of period 2 (depends only on parity):
If i ≥ 4 is even then Ri = {k | k is even} (since i + k ≥ 4 and acceptance is just parity even).
If i ≥ 5 is odd then Ri = {k | k is odd}.
These six residuals are all distinct:
R0 (distinct because it does not contain 0 or 1 but contains 2 and 3).
R1 (distinct because 0 ∉ R1 but 1 ∈ R1).
R2 (contains 0,1,2 and even numbers ≥4) — different from the generic even class because it contains 1.
R3 (contains 0 and all odd k ≥1) — different from the generic odd class because it contains 0.
The generic even class for i ≥ 4 (Ri = even k) is different from R2 because R2 contains 1.
The generic odd class for i ≥ 5 (Ri = odd k) is different from R3 because R3 contains 0.
Thus there are exactly six distinct equivalence classes, so any minimal DFA must have 6 states.
Which of those states are accepting? Precisely the classes Ri that contain 0, i.e. the classes corresponding to lengths that themselves belong to L: R2, R3, and the generic even class (i even ≥ 4).
Conclusion: minimal DFA requires 6 states (matches the given answer).