GATE Computer ScienceVery hardGATE CS
Let #ab(w) and #ba(w) be the numbers of occurrences of the substrings ab and ba in w ∈ {a, b}*. Which one of the following languages is regular?
- A. { w : n_a(w) = n_b(w) }
- B. { w : #ab(w) = #ba(w) }
- C. { w : #aa(w) = #bb(w) }
- D. { w : #ab(w) ≥ #aa(w) }
Correct answer: B. { w : #ab(w) = #ba(w) }
The occurrences of ab and ba alternate along the string, so #ab − #ba ∈ {0, ±1}, and it is 0 exactly when w is empty or its first and last symbols are equal: a regular condition. For #aa = #bb, intersect with a⁺b⁺ to get n − 1 = m − 1, i.e. aⁿbⁿ, which is not regular.
More Theory of Computation questions
- Let L = { w ∈ {a, b} : w begins with aba, or (w ends with b and na(w) ≡ 0 (mod 3)) }. The minimal complete DFAs for L and for its reversal…
- Consider the following claims about an arbitrary regular language L over Σ. I. { w : ww ∈ L } is regular. II. { w : w wᴿ ∈ L } is regular…
- Let D be a DFA and G a context-free grammar over the same alphabet. Consider the problems: I. Is L(D) ⊆ L(G)? II. Is L(G) ⊆ L(D)? III. Is…
- A single-tape Turing machine has blank B and starts in q0 on the leftmost cell of a binary numeral (MSB at the left). Rules: δ(q0,0) =…
- For a Turing machine M (given by its encoding ⟨M⟩) consider these sets: I. { ⟨M⟩ : M has at least 481 states } II. { ⟨M⟩ : L(M) contains…
- Which of the following languages are deterministic context-free? I. { aⁱbʲcᵏ : i = j or j = k } II. { aⁱbʲcᵏ : i = j, k ≥ 0 } III. { w c…