GateAI
Regular and Context-Free Languages

GATE CSE 2017 Set 2 · Q40

MCQ2 marksMedium

Time

Consider the following languages. L1={ap∣p is a prime number} L_1 = \{a^p \mid p \text{ is a prime number}\} L2={anbmc2m∣n≥0,m≥0} L_2 = \{a^n b^m c^{2m} \mid n \ge 0, m \ge 0\} L3={anbnc2n∣n≥0} L_3 = \{a^n b^n c^{2n} \mid n \ge 0\} L4={anbn∣n≥1} L_4 = \{a^n b^n \mid n \ge 1\} Which of the following are CORRECT? I. L1L_1 is context-free but not regular. II. L2L_2 is not context-free. III. L3L_3 is not context-free but recursive. IV. L4L_4 is deterministic context-free.

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: D) III and IV only

Regular and Context-Free Languages

Let us evaluate each statement:

  • Statement I: L1={ap∣p is prime}L_1 = \{a^p \mid p \text{ is prime}\} is defined over a unary alphabet Σ={a}\Sigma = \{a\}. By Parikh's Theorem, any context-free language over a unary alphabet is regular. Since L1L_1 is not regular (primes cannot be recognized by a finite automaton), it cannot be context-free either. Thus, statement I is incorrect.

  • Statement II: L2={anbmc2m∣n≥0,m≥0}L_2 = \{a^n b^m c^{2m} \mid n \ge 0, m \ge 0\} is context-free (and deterministic context-free) because a pushdown automaton can read any number of aa's without using the stack, push two symbols onto the stack for each bb, and pop one symbol for each cc. Thus, statement II is incorrect.

  • Statement III: L3={anbnc2n∣n≥0}L_3 = \{a^n b^n c^{2n} \mid n \ge 0\} requires simultaneously comparing the number of aa's, bb's, and cc's, which cannot be done with a single stack. Hence, L3L_3 is not context-free (it is context-sensitive), and it is clearly recursive. Thus, statement III is correct.

  • Statement IV: L4={anbn∣n≥1}L_4 = \{a^n b^n \mid n \ge 1\} is a standard deterministic context-free language (DCFL) recognizable by a deterministic pushdown automaton (DPDA). Thus, statement IV is correct.

Statements III and IV are correct, corresponding to option (D).

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 Q40 of the GATE CSE 2017 Set 2 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 2017 Set 2 has 2.

How GATE tests Regular and Context-Free Languages

More from GATE CSE 2017 Set 2

Share this solution

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

GateAI solution cardGATE CSE 2017 Set 2 · Q40 · MCQ

Consider the following languages. L1 = {ap p is a prime number} L2 = {an bm c2m n ≥ 0, m ≥ 0} L3 = {an bn c2n n ≥ 0} L4 = {an bn n ≥ 1} Which of the following are CORRECT? I. L1 is context-free but not regular. II. L2 is not context-free. III. L3 is not context-free but recursive. IV. L4 is deterministic 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.