Let \(L_1 = \{ w \in \{0,1\}^* | w\) has at least as many occurrences of…

2014

Let \(L_1 = \{ w \in \{0,1\}^* | w\) has at least as many occurrences of (110)’s as (011)’s}. Let \(L_2 = \{ w \in \{0,1\}^* | w\) has at least as many occurrences of (000)’s as (111)’s}. Which one of the following is TRUE?

  1. A.

    \(L_1\) is regular but not \(L_2\)

  2. B.

    \(L_2\) is regular but not \(L_1\)

  3. C.

    Both \(L_1\) and \(L_2\) are regular

  4. D.

    Neither \(L_1\) nor \(L_2\) are regular

Attempted by 138 students.

Show answer & explanation

Correct answer: A

Answer: L1 is regular but L2 is not.

Proof that L1 is regular:

  • Let the bits of the string be s1, s2, ..., sn.

  • For each position i (1 ≤ i ≤ n−2), define +1 if the length-3 block starting at i is 110, −1 if it is 011, and 0 otherwise. Sum these values over i to get (#110) − (#011).

  • A short algebraic manipulation shows the sum telescopes: for each i the contribution equals s_i s_{i+1} − s_{i+1} s_{i+2}, so the total equals s_1 s_2 − s_{n-1} s_n.

  • Therefore (#110) − (#011) depends only on the first two bits and the last two bits of the string. The property (#110) ≥ (#011) is equivalent to the boolean condition (s_1 s_2) ≥ (s_{n-1} s_n), which can be decided by a finite automaton that remembers the first two bits and keeps track of the last two bits seen so far. Hence L1 is regular.

Proof that L2 is not regular (pumping lemma):

  • Assume for contradiction that L2 is regular, and let p be its pumping length.

  • Consider the string w = 1^{2p} 0^{2p}. In w the run of 1s contributes 2p−2 occurrences of 111 and the run of 0s contributes 2p−2 occurrences of 000, so w satisfies (#000) ≥ (#111) and w ∈ L2.

  • By the pumping lemma write w = xyz with |xy| ≤ p and |y| ≥ 1. Because |xy| ≤ p, the substring y lies entirely inside the initial block of 1s, so y consists of only 1s.

  • Pump down (take i = 0): the string xz has fewer 1s in the first block, so the number of occurrences of 111 decreases by at least 1, while the number of occurrences of 000 remains 2p−2. Therefore xz has (#111) < (#000) and so xz ∉ L2.

  • This contradicts the pumping lemma requirement that x y^i z ∈ L2 for all i ≥ 0. Hence L2 is not regular.

Conclusion: L1 is regular (decidable by a DFA that records first two bits and last two bits seen), while L2 is not regular by the pumping-lemma argument.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir