Skip to content
Official PYQ · 2020

GATE CS 2020 Q51 — Regular and Context-free Languages

Explain with AI
Consider the following language.

L={x∈{a,b}∗∣L = \{{ x\in \{a,b\}^*\mid}number of aa’s in xx divisible by 22 but not divisible by 3}3\}

The minimum number of states in DFA that accepts LL is _________
View worked solution

Answer: 6

Let na(x)n_a(x) denote the number of aa’s in the string xx. The language LL is defined as:

L={x∈{a,b}∗∣na(x) is divisible by 2 but not by 3}L = \{ x \in \{a,b\}^* \mid n_a(x) \text{ is divisible by } 2 \text{ but not by } 3 \}

This condition can be analyzed modulo 66 (since lcm(2,3)=6\text{lcm}(2, 3) = 6):

  • na(x)n_a(x) is divisible by 22 if na(x)≡0,2,4(mod6)n_a(x) \equiv 0, 2, 4 \pmod 6.
  • na(x)n_a(x) is divisible by 33 if na(x)≡0,3(mod6)n_a(x) \equiv 0, 3 \pmod 6.

For na(x)n_a(x) to be divisible by 22 but not by 33, we must have:

na(x)(mod6)∈{0,2,4}∖{0,3}={2,4}n_a(x) \pmod 6 \in \{0, 2, 4\} \setminus \{0, 3\} = \{2, 4\}

Thus, the language only depends on the count of aa’s modulo 66. We can construct a DFA with 66 states, Q={q0,q1,q2,q3,q4,q5}Q = \{q_0, q_1, q_2, q_3, q_4, q_5\}, where state qiq_i represents na(x)≡i(mod6)n_a(x) \equiv i \pmod 6. The start state is q0q_0 and the set of accepting states is F={q2,q4}F = \{q_2, q_4\}. Since transitions on bb do not change the state, we only transition on aa to the next state modulo 66.

To verify if any states can be merged, we test pairwise distinguishability. For any two states qiq_i and qjq_j (0≤i<j≤50 \le i < j \le 5), we can find a string of aa’s of length kk that distinguishes them (i.e., drives one to an accepting state and the other to a non-accepting state). Since all 66 states are pairwise distinguishable, the DFA is already minimal.

Therefore, the minimum number of states in the DFA is 6.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Regular and Context-free Languages questions