Given the following two languages : \(L_1 = \{a^n b^n | n ≥ 0, n ≠ 100\}\)…

2017

Given the following two languages :

\(L_1 = \{a^n b^n | n ≥ 0, n ≠ 100\}\)

\(L_2 = \{w ∈ {a, b, c}^*| n_a(w) = n_b(w) = n_c(w)\}\)

Which of the following options is correct ?

  1. A.

    Both \(L_1\) and \(L_2\) are not context free language

  2. B.

    Both \(L_1\) and \(L_2\) are context free language.

  3. C.

    \(L_1\) is context free language, \(L_2\) is not context free language.

  4. D.

    \(L_1\) is not context free language, \(L_2\) is context free language.

Attempted by 61 students.

Show answer & explanation

Correct answer: C

Answer: L1 is a context-free language, and L2 is not a context-free language.

  • Reason for L1:

    The language {a^n b^n | n ≥ 0} is generated by the grammar S → a S b | ε, so it is context-free. L1 differs from this language only by removing the single string a^100 b^100. A finite set (in particular a single string) is regular, and context-free languages are closed under intersection with regular languages; equivalently, removing a regular set from a context-free language yields a context-free language. Therefore L1 is context-free.

  • Reason for L2:

    Consider intersecting the language of all strings with equal counts of a, b, and c with the regular language a*b*c*. The intersection is {a^n b^n c^n | n ≥ 0}, which is a well-known non-context-free language. Since context-free languages are closed under intersection with regular languages, if the original language were context-free then the intersection would also be context-free, contradiction. Hence L2 is not context-free.

Conclusion: L1 is context-free; L2 is not context-free.

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

Explore the full course: Mppsc Assistant Professor