Question

Consider the following languages.

L1={ap∣p is a prime number}L2={anbmc2m∣n≥0,m≥0}L3={anbnc2n∣n≥0}L4={anbn∣n≥1}\begin{aligned} L_1 &= \{a^p \mid p \text{ is a prime number}\} \\ L_2 &= \{a^n b^m c^{2m} \mid n \ge 0, m \ge 0\} \\ L_3 &= \{a^n b^n c^{2n} \mid n \ge 0\} \\ L_4 &= \{a^n b^n \mid n \ge 1\} \end{aligned}

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.

Choose one option
Official answer and solution
Official answer
D
From
Official GATE 2017 answer key

Solution

Classify each given language within the Chomsky hierarchy.

Evaluate the four languages:

  1. L1={ap∣p is prime}L_1 = \{a^p \mid p \text{ is prime}\}:
    By Parikh's theorem, any context-free language over a single-letter alphabet is regular. Since L1L_1 is not regular (primes do not form an arithmetic progression), L1L_1 cannot be context-free. Thus, Statement I is INCORRECT.
  2. L2={anbmc2m∣n≥0,m≥0}L_2 = \{a^n b^m c^{2m} \mid n \ge 0, m \ge 0\}:
    L2=a∗{bmc2m∣m≥0}L_2 = a^* \{b^m c^{2m} \mid m \ge 0\}. Since a∗a^* is regular and {bmc2m}\{b^m c^{2m}\} is a deterministic context-free language, their concatenation is a context-free language. Thus, Statement II (which asserts L2L_2 is not context-free) is INCORRECT.
  3. L3={anbnc2n∣n≥0}L_3 = \{a^n b^n c^{2n} \mid n \ge 0\}:
    Requires matching the counts of three separate symbol blocks (a,b,ca, b, c) simultaneously. By the pumping lemma for CFLs, L3L_3 is not context-free. However, a multi-track Turing machine can easily compare the counts, so L3L_3 is recursive (decidable). Thus, Statement III is CORRECT.
  4. L4={anbn∣n≥1}L_4 = \{a^n b^n \mid n \ge 1\}:
    A deterministic pushdown automaton (DPDA) can push each 'aa' onto the stack and pop an 'aa' for each 'bb', accepting when the input and stack are both empty. Thus, L4L_4 is a deterministic context-free language (DCFL). Thus, Statement IV is CORRECT.

Statements III and IV only are correct, which corresponds to option D.

Final answer

D

Common trap

Assuming unary languages can be context-free without being regular; by Parikh's theorem, every unary CFL is regular.

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

Source

Paper
GATE 2017 Computer Science and Information Technology (CS) Session 2
Question
40 of 65, printed as CS Q.40
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.