Question

For a string ww, we define wRw^R to be the reverse of ww. For example, if w=01101w = 01101 then wR=10110w^R = 10110.

Which of the following languages is/are context-free?

Choose every correct option
Official answer and solution
Official answer
B, C and D
From
Official GATE 2021 answer key

Solution

Examine the matching structure (nesting vs. cross-serial) for each language to see whether it can be recognized by a Pushdown Automaton (PDA).

A language is context-free if and only if it can be recognized by a pushdown automaton (PDA), which uses a single LIFO stack and can verify nested (last-in, first-out) dependencies.

Analyze each language:

  • Option A: {wxwRxR∣w,x∈{0,1}∗}\{w x w^R x^R \mid w, x \in \{0,1\}^*\}.
    Here ww is matched with wRw^R and xx is matched with xRx^R, but they overlap in cross-serial fashion: ww starts first, then xx, then wRw^R finishes before xRx^R. This requires matching two independent pairs in an interleaved order, which cannot be handled by a single stack. This language is not context-free.
  • Option B: {wwRxxR∣w,x∈{0,1}∗}\{w w^R x x^R \mid w, x \in \{0,1\}^*\}.
    This is the concatenation of two even-length palindrome languages: Lpal⋅LpalL_{\text{pal}} \cdot L_{\text{pal}}, where Lpal={uuR∣u∈{0,1}∗}L_{\text{pal}} = \{u u^R \mid u \in \{0,1\}^*\}. Since LpalL_{\text{pal}} is context-free and CFLs are closed under concatenation, this language is context-free. Option B is correct.
  • Option C: {wxwR∣w,x∈{0,1}∗}\{w x w^R \mid w, x \in \{0,1\}^*\}.
    This is the set of all odd-length or general palindromes with an arbitrary center xx. A PDA can push ww nondeterministically, read xx without touching the stack, and then pop and verify against wRw^R. This language is context-free. Option C is correct.
  • Option D: {wxxRwR∣w,x∈{0,1}∗}\{w x x^R w^R \mid w, x \in \{0,1\}^*\}.
    Notice that wxxRwR=(wx)(wx)Rw x x^R w^R = (w x)(w x)^R. Letting u=wxu = w x, this is simply {uuR∣u∈{0,1}∗}\{u u^R \mid u \in \{0,1\}^*\}, which is the standard language of even-length palindromes. Hence it is context-free. Option D is correct.
Final answer

B, C, D

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

Source

Paper
GATE 2021 Computer Science and Information Technology - Session 2 (CS2)
Question
51 of 65, printed as CS Q.41
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.