GATE / CS ARCHIVE

GATE CSE 2008 / QUESTION 9

Unary prime-length language

Theory of Computation · Context-Free Grammars & Languages · Full GATE CSE 2008 paper

GATE 2008, Q9 1 mark · MCQ
Report issue

Context-Free Grammars & Languages

Question 9, GATE 2008: Which statement holds for {a^p | p is prime}?

(A) Not accepted by a Turing machine
(B) Regular but not context-free
(C) Context-free but not regular
(D) Neither regular nor context-free, but accepted by a Turing machine
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

1. Primality of the input length is decidable, so a Turing machine accepts the language. It is not regular: if a pumping length is p, choose prime q>p; a pumpable nonempty segment has length d≤p, and pumping it q+1 times changes length to q+qd=q(1+d), composite.
2. Every unary context-free language is regular (its length set is ultimately periodic/semilinear), so this language is not context-free either. Therefore D.

Original paper, page 3