GateAI
Regular and Context-Free Languages

GATE CSE 2021 Set 2 · Q41

MSQ2 marksMedium

Time

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?

Select all that applyOne or more correct

Pick every correct option

Solution

Step-by-step verified solution

Official answer: B) {wwR xxR w, x ∈ {0, 1}*}; C) {wxwR w, x ∈ {0, 1}*}; D) {wxxR wR w, x ∈ {0, 1}*}

Regular and Context-Free Languages

Let us analyze each language:

  • Option A: {wxwRxR∣w,x∈{0,1}∗}\{w x w^R x^R \mid w, x \in \{0, 1\}^*\} This language requires matching two independent reversed patterns that are interleaved (cross-serial dependency). A single pushdown automaton cannot verify both ww against wRw^R and xx against xRx^R simultaneously. Hence, 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 language is the concatenation of two CFLs: L1={wwR∣w∈{0,1}∗}L_1 = \{w w^R \mid w \in \{0, 1\}^*\} and L2={xxR∣x∈{0,1}∗}L_2 = \{x x^R \mid x \in \{0, 1\}^*\}, where both are standard context-free languages (even-length palindromes). Since CFLs are closed under concatenation, L1L2L_1 L_2 is context-free.

  • Option C: {wxwR∣w,x∈{0,1}∗}\{w x w^R \mid w, x \in \{0, 1\}^*\} By choosing w=ϵw = \epsilon, any string s∈{0,1}∗s \in \{0, 1\}^* can be written as ϵsϵR=s\epsilon s \epsilon^R = s. Thus, the language generates all strings over {0,1}∗\{0, 1\}^*, i.e., L={0,1}∗L = \{0, 1\}^*, which is a regular language. Every regular language is also context-free.

  • Option D: {wxxRwR∣w,x∈{0,1}∗}\{w x x^R w^R \mid w, x \in \{0, 1\}^*\} Let y=wxy = w x. Then yR=(wx)R=xRwRy^R = (w x)^R = x^R w^R. Thus, any string of this form is yyRy y^R for y=wx∈{0,1}∗y = w x \in \{0, 1\}^*. Choosing x=ϵx = \epsilon gives all even-length palindromes {wwR∣w∈{0,1}∗}\{w w^R \mid w \in \{0, 1\}^*\}. Therefore, the language is exactly the set of even-length palindromes, which is context-free.

Thus, the correct options are B, C, and D.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Regular and Context-Free Languages previous year question is Q41 of the GATE CSE 2021 Set 2 paper. Find more GATE CSE PYQs on Regular and Context-Free Languages in Theory of Computation, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Regular and Context-Free Languages PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Regular and Context-Free Languages in GATE CSE

Regular and Context-Free Languages has 21 GATE CSE PYQs across 13 papers from 2011 to 2026. 4 of them are 2-mark MSQs like this one, and GATE CSE 2021 Set 2 has 2.

How GATE tests Regular and Context-Free Languages

More from GATE CSE 2021 Set 2

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2021 Set 2 · Q41 · MSQ

For a string w, we define wR to be the reverse of w. For example, if w = 01101 then wR = 10110. Which of the following languages is/are context-free?

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.