Skip to content
Official PYQ · 2006

GATE CS 2006 Q19 — Context-free Grammars and Push-down Automata

Explain with AI

Let

L1={0n+m1n0m∣n,m≥0}L_1=\{0^{n+m}1^n0^m\mid n,m\geq 0 \},

L2={0n+m1n+m0m∣n,m≥0}L_2=\{0^{n+m}1^{n+m}0^m\mid n,m\geq 0\} and

L3={0n+m1n+m0n+m∣n,m≥0}L_3=\{0^{n+m}1^{n+m}0^{n+m}\mid n,m\geq 0\}.  

Which of these languages are NOT context free? 

Choose one option
View worked solution

Answer: D

To determine which of the languages are not context-free, let us analyze each one individually:

  • Language L1={0n+m1n0m∣n,m≥0}L_1 = \{0^{n+m}1^n0^m \mid n,m \geq 0\}:
    We can rewrite the string format as 0m0n1n0m0^m 0^n 1^n 0^m because the leading 0n+m0^{n+m} can be split into 0m0n0^m 0^n. Since all these symbols are 00, they commute.
    We can easily construct a Context-Free Grammar (CFG) for L1L_1: S→0S0∣AA→0A1∣ϵ\begin{align*} S &\to 0S0 \mid A \\ A &\to 0A1 \mid \epsilon \end{align*} Here, SS generates the outer 0m…0m0^m \dots 0^m and AA generates the inner 0n1n0^n 1^n. Thus, L1L_1 is context-free.
  • Language L2={0n+m1n+m0m∣n,m≥0}L_2 = \{0^{n+m}1^{n+m}0^m \mid n,m \geq 0\}:
    Let k=n+mk = n+m. Since n≥0n \geq 0, we have k≥mk \geq m. Thus, the language can be written as: L2={0k1k0m∣k≥m≥0}L_2 = \{0^k 1^k 0^m \mid k \geq m \geq 0\} This requires a PDA to match the number of leading 00s with the number of 11s (requiring stack operations), and simultaneously ensure that the number of trailing 00s (mm) is less than or equal to kk. Since a PDA cannot perform these multiple overlapping comparisons, L2L_2 is not context-free.
  • Language L3={0n+m1n+m0n+m∣n,m≥0}L_3 = \{0^{n+m}1^{n+m}0^{n+m} \mid n,m \geq 0\}:
    Let k=n+mk = n+m. Since n,m≥0n, m \geq 0, kk can be any non-negative integer. Thus, the language simplifies to: L3={0k1k0k∣k≥0}L_3 = \{0^k 1^k 0^k \mid k \geq 0\} This is a classic non-context-free language (similar to anbncna^n b^n c^n). Thus, L3L_3 is not context-free.

Therefore, L2L_2 and L3L_3 are NOT context-free.

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

Published
Report a correction
Keep exploringMore Context-free Grammars and Push-down Automata questions