Skip to content
Official PYQ · 2008

GATE CS 2008 Q9 — Regular and Context-free Languages

Explain with AI

Which of the following is true for the language

{ap∣p is a prime }?\left\{ a^p \mid p \text{ is a prime } \right \}?

Choose one option
View worked solution

Answer: D

Let the language be L={ap∣p is a prime }={a2,a3,a5,a7,a11,… }L = \{ a^p \mid p \text{ is a prime } \} = \{ a^2, a^3, a^5, a^7, a^{11}, \dots \}.

We can analyze the properties of LL as follows:

  1. Not Regular: We can prove this using the Pumping Lemma for regular languages. Suppose LL is regular with pumping length nn. Choose a prime p≥n+2p \ge n+2. Let w=ap∈Lw = a^p \in L. We split w=xyzw = xyz such that ∣xy∣≤n|xy| \le n and ∣y∣=k≥1|y| = k \ge 1. According to the pumping lemma, xyiz∈Lxy^iz \in L for all i≥0i \ge 0. The length of xyizxy^iz is p+(i−1)kp + (i-1)k. If we choose i=p+1i = p+1, the length becomes p+pk=p(1+k)p + pk = p(1+k). Since p≥2p \ge 2 and 1+k≥21+k \ge 2, the length p(1+k)p(1+k) is a composite number. Thus, ap(1+k)∉La^{p(1+k)} \notin L, which is a contradiction. Hence, LL is not regular.

  2. Not Context-Free: By Parikh's Theorem, any context-free language over a unary alphabet (a single-letter alphabet like {a}\{a\}) must also be regular. Since LL is over a unary alphabet and is not regular, it cannot be context-free.

  3. Accepted by a Turing Machine: Primality testing is a decidable problem. We can easily construct a Turing Machine that, given an input ama^m, systematically tests if mm has any divisors other than 11 and mm (by simulating division). Since the TM halts and accepts if mm is prime, the language is recursive (and hence accepted by a Turing Machine).

Thus, the language is neither regular nor context-free, but it is accepted by a Turing machine.

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

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