Consider the following languages. \(L_1 = \{a^p \mid p \text{ is a prime…
2017
Consider the following languages.
\(L_1 = \{a^p \mid p \text{ is a prime number} \}\)
\(L_2 = \{ a^nb^mc^{2m} \mid n \geq 0, m \geq 0 \}\)
\(L_3 = \{a^n b^n c^{2n} \mid n \geq 0 \}\)
\(L_4 = \{ a^n b^n \mid n \geq 1\}\)
Which of the following are CORRECT?
I. \(L_1\) is context free but not regular
II. \(L_2\) is not context free
III. \(L_3\) is not context free but recursive
IV. \(L_4\) is deterministic context free
Answer: D. III and IV only — ConceptLanguage-class questions are decided by closure properties and machine models. Every unary context-free language is regular, a context-free grammar may…
- A.
I, II and IV only
- B.
II and III only
- C.
I and IV only
- D.
III and IV only
Attempted by 105 students.
Show answer & explanation
Correct answer: D
Concept
Language-class questions are decided by closure properties and machine models. Every unary context-free language is regular, a context-free grammar may coordinate two dependent blocks, and a deterministic pushdown automaton can compare two consecutive blocks.
A language can be recursive without being context-free: a terminating algorithm may verify several length constraints even when one stack cannot enforce all of them.
Application
L1 = {a^p | p is prime}: If L1 were context-free, then as a unary context-free language it would be regular. Prime lengths are not ultimately periodic, so L1 is not regular and therefore not context-free. Statement I is false.
L2 = {a^n b^m c^{2m} | n ≥ 0, m ≥ 0}: The grammar S → aS | T and T → bTcc | ε generates any number of a symbols, followed by m b symbols and 2m c symbols. Hence L2 is context-free, so statement II is false.
L3 = {a^n b^n c^{2n} | n ≥ 0}: It requires the same n across three blocks, with the c block twice as long. It is not context-free. It is recursive because an algorithm can verify the block order, count a and b symbols, and check that the number of c symbols is twice that count. Statement III is true.
L4 = {a^n b^n | n ≥ 1}: A deterministic pushdown automaton pushes one marker for each a, switches when the first b appears, and pops one marker per b. It accepts exactly when the input ends with the stack balanced. Statement IV is true.
Cross-check
For L3, let h(a)=a, h(b)=b and h(c)=cc. If L3 were context-free, closure under inverse homomorphism and intersection with the regular language a*b*c* would make {a^n b^n c^n | n ≥ 0} context-free, a contradiction.
The proposed grammar S → aSbcc | ε does not generate a^n b^n c^{2n}; for n=2 it yields aabbccbcc, so it does not preserve one contiguous b block followed by one contiguous c block.
Result
Only statements III and IV are correct. Therefore the answer is III and IV only.
A video solution is available for this question — log in and enroll to watch it.
Explore the full course: Iocl Engineers Officers Grade A Paper 2