The set A = { 0n 1n 2n | n=1, 2, 3, ......... } is an example of a grammar…

2018

The set A = { 0n 1n 2n | n=1, 2, 3, ......... } is an example of a grammar that is :

  1. A.

    Context sensitive

  2. B.

    Context free

  3. C.

    Regular

  4. D.

    None of the above

Attempted by 119 students.

Show answer & explanation

Correct answer: A

Final classification: Context-sensitive

  • Not regular: Regular languages cannot enforce equal counts across unbounded blocks of different symbols, so they cannot generate {0^n 1^n 2^n}.

  • Not context-free: Context-free grammars can match two blocks (e.g., {0^n 1^n}) but cannot enforce equality of three blocks. The language {0^n 1^n 2^n} is a standard example of a non-context-free language (provable using the pumping lemma for context-free languages or closure properties).

  • Context-sensitive: There exist context-sensitive grammars that generate the language. One example (replace a→0, b→1, c→2 from the standard construction) is:

    1. S → 0 S B C | 0 1 2

    2. B C → C B

    3. 1 C → 1 2

    4. 2 B → 2 1

Explanation: The grammar above is context-sensitive (rules do not decrease string length and can depend on context). It produces strings with equal numbers of 0s, 1s, and 2s in the order 0^n1^n2^n, so the language belongs to the context-sensitive class.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Mppsc Assistant Professor