Skip to content
Official PYQ · 2006

GATE CS 2006 Q29 — Regular and Context-free Languages

Explain with AI

If ss is a string over (0+1)∗(0+1)^*  then let n0(s)n_0(s) denote the number of 00’s in ss and n1(s)n_1(s) the number of 11’s in ss. Which one of the following languages is not regular?

Choose one option
View worked solution

Answer: C

To determine which language is not regular, we analyze each option based on whether it requires finite or infinite memory (states) to be recognized.

  1. L={s∈(0+1)∗∣n0(s) is a 3-digit prime}L = \{ s \in (0+1)^* \mid n_{0}(s) \text{ is a 3-digit prime} \}

    The set of 3-digit prime numbers is finite (ranging from 101101 to 997997). Since the number of 00's is restricted to a finite set of values and there is no restriction on 11's, a DFA only needs to count 00's up to 999999. Any count beyond 999999 can go to a dead state. Since this requires a finite number of states, the language is regular.

  2. L={s∈(0+1)∗∣for every prefix s′ of s,∣n0(s′)−n1(s′)∣≤2}L = \{ s \in (0+1)^* \mid \text{for every prefix } s' \text{ of } s, |n_{0}(s') - n_{1}(s')| \le 2 \}

    This condition requires that at any point during the scanning of the string, the running difference between the number of 00's and 11's must stay within the range [−2,2][-2, 2]. If the difference ever exceeds this range, the string is rejected. This can be tracked using a finite number of states (representing differences of −2,−1,0,1,2-2, -1, 0, 1, 2, plus a dead state). Thus, the language is regular.

  3. L={s∈(0+1)∗∣∣n0(s)−n1(s)∣≤4}L = \{ s \in (0+1)^* \mid |n_{0}(s) - n_{1}(s)| \le 4 \}

    This condition only constrains the final difference of the entire string. During the processing of the string, the intermediate difference can grow arbitrarily large (for example, in the string 0k1k0^k 1^k, the difference reaches kk before returning to 00). To verify if the final difference is ≤4\le 4, a machine must keep track of an arbitrarily large difference, which requires infinite memory. Thus, this language is not regular.

  4. L={s∈(0+1)∗∣n0(s) mod 7=n1(s) mod 5=0}L = \{ s \in (0+1)^* \mid n_{0}(s) \bmod 7 = n_{1}(s) \bmod 5 = 0 \}

    This language requires the number of 00's to be a multiple of 77 and the number of 11's to be a multiple of 55. This can be easily recognized by a DFA using the product construction with 7×5=357 \times 5 = 35 states. Since it requires finite memory, the language is regular.

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

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