Skip to content
Official PYQ · 2022

GATE CS 2022 Q37 — Context-free Grammars and Push-down Automata

Explain with AI

Consider the following languages:

L1={anwan∣w∈{a,b}∗}L_{1} = \{ a^{n} wa^{n} | w \in \{a,b\}^{\ast}\}

L2={wxwR∣w,x∈{a,b}∗,∣w∣,∣x∣>0}L_{2} = \{wxw^{R} | w, x \in \{a,b\}^{*}, |w|, |x| > 0 \}

Note that wRw^{R} is the reversal of the string w.w. Which of the following is/are TRUE?\text{TRUE}?

Select all correct options
View worked solution

Answer: A;B;C

To determine the nature of the languages L1L_1 and L2L_2, we analyze them individually:

Analysis of L1={anwan∣w∈{a,b}∗}L_1 = \{ a^n w a^n \mid w \in \{a,b\}^* \}:

  • If n≥0n \ge 0, choosing n=0n = 0 gives L1={a,b}∗L_1 = \{a,b\}^*, which is regular.
  • If n≥1n \ge 1, any string in L1L_1 must start with aa and end with aa. By choosing n=1n = 1, we can write any such string as awaa w a for some w∈{a,b}∗w \in \{a,b\}^*. Thus, L1=a(a+b)∗aL_1 = a(a+b)^*a, which is regular.

In either standard interpretation of nn, L1L_1 is a regular language.

Analysis of L2={wxwR∣w,x∈{a,b}∗,∣w∣,∣x∣>0}L_2 = \{ w x w^R \mid w, x \in \{a,b\}^*, |w|, |x| > 0 \}:

  • Since ∣w∣≥1|w| \ge 1, the simplest choice for ww is a single character, i.e., w=aw = a or w=bw = b.
  • If w=aw = a, then wR=aw^R = a, giving strings of the form axaa x a where ∣x∣≥1|x| \ge 1.
  • If w=bw = b, then wR=bw^R = b, giving strings of the form bxbb x b where ∣x∣≥1|x| \ge 1.

Any string of length ≥3\ge 3 that starts and ends with the same character belongs to L2L_2. Thus, we can express L2L_2 as the regular expression: L2=a(a+b)+a+b(a+b)+bL_2 = a(a+b)^+a + b(a+b)^+b Hence, L2L_2 is also a regular language.

Since every regular language is also a context-free language (CFL):

  • A is TRUE: Both L1L_1 and L2L_2 are regular.
  • B is TRUE: Both L1L_1 and L2L_2 are context-free.
  • C is TRUE: L1L_1 is regular and L2L_2 is context-free (since L2L_2 is regular, it is also context-free).
  • D is FALSE: They are regular.

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

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