Question

Consider the following languages:

L1={anwan∣w∈{a,b}∗}L_1 = \{a^n w a^n \mid w \in \{a, b\}^*\}
L2={wxwR∣w,x∈{a,b}∗,∣w∣,∣x∣>0}L_2 = \{w x w^R \mid w, x \in \{a, b\}^*, |w|, |x| > 0\}

Note that wRw^R is the reversal of the string ww. Which of the following is/are TRUE?

Choose every correct option
Official answer and solution
Official answer
A, B and C
From
Official GATE 2022 answer key
Note on this question

Since every regular language is also context-free, both (A), (B), and (C) are mathematically true and all three are credited in the official key.

Solution

Analyze string membership and construct regular expressions for languages L1L_1 and L2L_2.

  1. For L1={anwan∣w∈{a,b}∗}L_1 = \{a^n w a^n \mid w \in \{a, b\}^*\}:
    Setting n=0n = 0, a0wa0=wa^0 w a^0 = w. Since ww is any arbitrary string in {a,b}∗\{a, b\}^*, setting n=0n = 0 allows L1L_1 to generate every possible string in {a,b}∗\{a, b\}^*. Thus L1={a,b}∗L_1 = \{a, b\}^*, which is a regular language.
    (Even if n≥1n \ge 1 were required, any string starting and ending with 'a' belongs to L1L_1 by setting n=1n=1, giving a{a,b}∗aa\{a, b\}^*a, which is also regular).

  2. For 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∣>0|w| > 0, ∣w∣≥1|w| \ge 1. Let ∣w∣=1|w| = 1:

    • If w=aw = a, then wR=aw^R = a, producing strings of the form axaa x a where ∣x∣>0|x| > 0.
    • If w=bw = b, then wR=bw^R = b, producing strings of the form bxbb x b where ∣x∣>0|x| > 0.
      Any string that starts and ends with the same character and has length at least 3 can be factored into wxwRw x w^R with ∣w∣=1|w|=1. Conversely, any string in L2L_2 has length ≥3\ge 3 and starts and ends with the same character. Thus L2=a(a+b)+a+b(a+b)+bL_2 = a(a+b)^+a + b(a+b)^+b, which is regular.

Since L1L_1 and L2L_2 are both regular, they are also context-free (every regular language is context-free). Therefore, Statement (A), Statement (B), and Statement (C) are all TRUE.

Final answer

Options (A), (B), (C)

Common trap

Assuming the condition wxwRw x w^R requires a pushdown automaton to verify arbitrary matching prefixes and suffixes, failing to notice that choosing ∣w∣=1|w| = 1 suffices.

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

Source

Paper
GATE 2022 Computer Science and Information Technology (CS)
Question
47 of 65
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.