Question

Consider the following language.

L={x∈{a,b}∗∣number of a’s in x is divisible by 2 but not divisible by 3}L = \{x \in \{a, b\}^* \mid \text{number of } a\text{'s in } x \text{ is divisible by 2 but not divisible by 3}\}

The minimum number of states in a DFA that accepts LL is _______.

Official answer and solution
Official answer
6
From
Official GATE 2020 answer key

Solution

Analyze the congruence classes of the number of a's modulo lcm(2, 3) = 6.

Let Na(x)N_a(x) denote the number of aa's in string xx. The acceptance condition requires:

Na(x)≡0(mod2)andNa(x)≢0(mod3)N_a(x) \equiv 0 \pmod 2 \quad \text{and} \quad N_a(x) \not\equiv 0 \pmod 3

Examine Na(x) mod 6N_a(x) \bmod 6 (since lcm(2,3)=6\text{lcm}(2, 3) = 6):

  • r=0r = 0: 0 mod 2=00 \bmod 2 = 0, but 0 mod 3=00 \bmod 3 = 0 (Fails).
  • r=1r = 1: 1 mod 2=11 \bmod 2 = 1 (Fails).
  • r=2r = 2: 2 mod 2=02 \bmod 2 = 0 and 2 mod 3=2≠02 \bmod 3 = 2 \ne 0 (Accepts).
  • r=3r = 3: 3 mod 2=13 \bmod 2 = 1 (Fails).
  • r=4r = 4: 4 mod 2=04 \bmod 2 = 0 and 4 mod 3=1≠04 \bmod 3 = 1 \ne 0 (Accepts).
  • r=5r = 5: 5 mod 2=15 \bmod 2 = 1 (Fails).

DFA state requirements:

  • A DFA must track the remainder r=Na(x) mod 6r = N_a(x) \bmod 6, requiring 6 states q0,q1,q2,q3,q4,q5q_0, q_1, q_2, q_3, q_4, q_5.
  • Transitions: on input aa, qi→q(i+1) mod 6q_i \to q_{(i+1) \bmod 6}; on input bb, self-loop qi→qiq_i \to q_i.
  • Accepting states: {q2,q4}\{q_2, q_4\}.
  • Using the Myhill-Nerode theorem, any two states qiq_i and qjq_j (0≤i<j≤50 \le i < j \le 5) are distinguishable by appending aka^k for a suitable kk. None of the 6 states can be merged.
  • Therefore, the minimum number of states is 6.
Final answer

6

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2020 Computer Science and Information Technology (CS)
Question
61 of 65, printed as CS Q.51
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.