Skip to content
Official PYQ · 2021

GATE CS 2021 Set 2 Q41 — Context-free Grammars and Push-down Automata

Explain with AI

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 correct options
View worked solution

Answer: B;C;D

To determine which of the languages are context-free, we analyze each option:

  • Option A: LA={wxwRxR∣w,x∈{0,1}∗}L_A = \{ wxw^Rx^R \mid w,x \in \{0,1\}^* \}. This language requires matching ww with wRw^R and xx with xRx^R in an overlapping (cross-serial) manner. A single pushdown stack cannot handle two overlapping LIFO comparisons simultaneously. Thus, LAL_A is not context-free.
  • Option B: LB={wwRxxR∣w,x∈{0,1}∗}L_B = \{ ww^Rxx^R \mid w,x \in \{0,1\}^* \}. This is the concatenation of two standard context-free languages: L1={wwR∣w∈{0,1}∗}L_1 = \{ ww^R \mid w \in \{0,1\}^* \} and L2={xxR∣x∈{0,1}∗}L_2 = \{ xx^R \mid x \in \{0,1\}^* \}. Since context-free languages are closed under concatenation, LBL_B is context-free.
  • Option C: LC={wxwR∣w,x∈{0,1}∗}L_C = \{ wxw^R \mid w,x \in \{0,1\}^* \}. If we choose w=ϵw = \epsilon, then wxwR=xwxw^R = x. Since x∈{0,1}∗x \in \{0,1\}^*, any string in {0,1}∗\{0,1\}^* can be represented in this form. Thus, LC={0,1}∗L_C = \{0,1\}^*, which is a regular language and therefore context-free.
  • Option D: LD={wxxRwR∣w,x∈{0,1}∗}L_D = \{ wxx^Rw^R \mid w,x \in \{0,1\}^* \}. Let y=wxy = wx. Then yR=(wx)R=xRwRy^R = (wx)^R = x^Rw^R. Thus, the language is equivalent to {yyR∣y∈{0,1}∗}\{ yy^R \mid y \in \{0,1\}^* \}, which is the classic even-length palindrome language and is context-free.

Therefore, options B, C, and D are context-free.

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

Published
Report a correction
Keep exploringMore Context-free Grammars and Push-down Automata questions