GateAI
Regular and Context-Free Languages

GATE CSE 2022 · Q47

MSQ2 marksMedium

Time

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?

Select all that applyOne or more correct

Pick every correct option

Solution

Step-by-step verified solution

Official answer: A) L1 and L2 are regular.; B) L1 and L2 are context-free.; C) L1 is regular and L2 is context-free.

Regular and Context-Free Languages

Let us analyze both languages:

  1. Language L1L_1:

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

    For n=0n = 0, a0wa0=wa^0 w a^0 = w. Since ww can be any string in {a,b}∗\{a,b\}^*, setting n=0n = 0 generates all strings in {a,b}∗\{a,b\}^*. Thus:

    L1={a,b}∗L_1 = \{a,b\}^*

    This is clearly a regular language (and consequently context-free).

  2. Language L2L_2:

    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, let the first symbol of ww be c∈{a,b}c \in \{a, b\}. Then wRw^R ends with the same symbol cc. Because xx has length at least 11, the total length of any string in L2L_2 is at least ∣w∣+∣x∣+∣wR∣≥1+1+1=3|w| + |x| + |w^R| \ge 1 + 1 + 1 = 3.

    Conversely, any string s∈{a,b}∗s \in \{a, b\}^* of length ≥3\ge 3 that starts and ends with the same symbol can be written with ∣w∣=1|w| = 1 (where ww is simply the first character) and xx as the remaining inner substring of length ≥1\ge 1. Thus:

    L2=a(a+b)+a∪b(a+b)+bL_2 = a(a+b)^+ a \cup b(a+b)^+ b

    This language is generated by a regular expression and is recognized by a finite automaton, so L2L_2 is regular (and consequently context-free).

Since every regular language is also context-free:

  • (A) L1L_1 and L2L_2 are regular: TRUE

  • (B) L1L_1 and L2L_2 are context-free: TRUE

  • (C) L1L_1 is regular and L2L_2 is context-free: TRUE

  • (D) L1L_1 and L2L_2 are context-free but not regular: FALSE (they are regular)

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 Q47 of the GATE CSE 2022 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 it is the only one in GATE CSE 2022.

How GATE tests Regular and Context-Free Languages

More from GATE CSE 2022

Share this solution

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

GateAI solution cardGATE CSE 2022 · Q47 · MSQ

Consider the following languages: L1 = {an w an w ∈ {a,b}*} L2 = {w x wR w, x ∈ {a,b}*, |w|, |x| > 0} Note that wR is the reversal of the string w. Which of the following is/are TRUE?

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.