GateAI
Regular and Context-Free Languages

GATE CSE 2019 · Q31

MCQ2 marksMedium

Time

Which one of the following languages over Σ={a,b}\Sigma = \{a, b\} is NOT context-free?

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: C) {wan wR bn w ∈ {a, b}*, n ≥ 0}

Regular and Context-Free Languages

Let us analyze each language:

  • (A) L1={wwR∣w∈{a,b}∗}L_1 = \{w w^R \mid w \in \{a, b\}^*\}: This is the language of even-length palindromes, which is standard non-deterministic context-free (a PDA pushes ww and pops on guessing the midpoint to match wRw^R).

  • (B) L2={wanbnwR∣w∈{a,b}∗,n≥0}L_2 = \{w a^n b^n w^R \mid w \in \{a, b\}^*, n \ge 0\}: A PDA can push ww onto the stack, then push ana^n and pop on matching bnb^n, and finally pop the remaining ww to match wRw^R. Because the stack operates in LIFO order, anbna^n b^n is fully processed and cleared before matching ww with wRw^R. Hence, this is context-free.

  • (C) L3={wanwRbn∣w∈{a,b}∗,n≥0}L_3 = \{w a^n w^R b^n \mid w \in \{a, b\}^*, n \ge 0\}: To check ww and wRw^R, the stack must be used to match them. However, the count nn of ana^n must also be compared with bnb^n appearing *after* wRw^R. Since the stack must clear/compare ww with wRw^R first, the count of nn cannot be retained simultaneously using a single pushdown stack. Using the Pumping Lemma for CFLs, it can be proven that L3L_3 is NOT context-free.

  • (D) L4={anbi∣i∈{n,3n,5n},n≥0}={anbn}∪{anb3n}∪{anb5n}L_4 = \{a^n b^i \mid i \in \{n, 3n, 5n\}, n \ge 0\} = \{a^n b^n\} \cup \{a^n b^{3n}\} \cup \{a^n b^{5n}\}: This is a finite union of three context-free languages, and since CFLs are closed under union, L4L_4 is context-free.

Therefore, the language in option (C) is not context-free.

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 Q31 of the GATE CSE 2019 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. 9 of them are 2-mark MCQs like this one, and GATE CSE 2019 has 3.

How GATE tests Regular and Context-Free Languages

More from GATE CSE 2019

Share this solution

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

GateAI solution cardGATE CSE 2019 · Q31 · MCQ

Which one of the following languages over = {a, b} is NOT 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.