Skip to content
Official PYQ · 2017

GATE CS 2017 Set 2 Q40 — Regular and Context-free Languages

Explain with AI

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^nb^mc^{2m} \mid n \geq 0, m \geq 0 \}
  • L3={anbnc2n∣n≥0}L_3 = \{a^n b^n c^{2n} \mid n \geq 0 \}
  • L4={anbn∣n≥1}L_4 = \{ a^n b^n \mid n \geq 1\}

Which of the following are CORRECT?

  1. L1L_1 is context free but not regular
  2. L2L_2 is not context free
  3. L3L_3 is not context free but recursive
  4. L4L_4 is deterministic context free
Choose one option
View worked solution

Answer: D

Let us analyze each language and the corresponding statements:

  • Language L1={ap∣p is a prime number}L_1 = \{a^p \mid p \text{ is a prime number}\}:
    By Parikh's Theorem, any context-free language over a unary alphabet (single-letter alphabet) must be regular. Since the set of prime numbers does not form an arithmetic progression, L1L_1 is not regular. Consequently, L1L_1 cannot be context-free either.
    Therefore, Statement I ("L1L_1 is context free but not regular") is incorrect.

  • Language L2={anbmc2m∣n≥0,m≥0}L_2 = \{ a^nb^mc^{2m} \mid n \geq 0, m \geq 0 \}:
    In L2L_2, the number of aa's is independent of bb's and cc's, and we only need to match the number of cc's to twice the number of bb's. This can be easily done using a single stack (pushing two symbols for every bb and popping one for every cc).
    We can write a Context-Free Grammar (CFG) for L2L_2: S→ABS \to A B A→aA∣ϵA \to aA \mid \epsilon B→bBcc∣ϵB \to bBcc \mid \epsilon Since L2L_2 is context-free, Statement II ("L2L_2 is not context free") is incorrect.

  • Language L3={anbnc2n∣n≥0}L_3 = \{a^n b^n c^{2n} \mid n \geq 0 \}:
    L3L_3 requires matching three counts simultaneously (nn aa's, nn bb's, and 2n2n cc's), which cannot be done with a single stack. Thus, L3L_3 is not context-free (can be formally proven using the pumping lemma for CFLs). However, it is easily decidable by a Turing machine, meaning it is a recursive language.
    Therefore, Statement III ("L3L_3 is not context free but recursive") is correct.

  • Language L4={anbn∣n≥1}L_4 = \{ a^n b^n \mid n \geq 1\}:
    This is a standard deterministic context-free language (DCFL) because we can construct a Deterministic Pushdown Automaton (DPDA) that pushes aa's onto the stack and pops them upon reading bb's.
    Therefore, Statement IV ("L4L_4 is deterministic context free") is correct.

Since only statements III and IV are correct, the correct option is D.

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

Published
Report a correction
Keep exploringMore Regular and Context-free Languages questions