Computer Sciences > GATE 2025 SET-1 > Context-Free Languages
Consider the following two languages over the alphabet {a, b, c}, where m and n are natural numbers.
L1={ambmcm+n|m,n≥1}
L2={ambncm+n|m,n≥1}
Which ONE of the following statements is CORRECT?
A
Both L1 and L2 are context-free languages.
B
L1 is a context-free language but L2 is not a context-free language.
C
L1 is not a context-free language but L2 is a context-free language.
D
Neither L1 nor L2 are context-free languages.

Correct : c

This is one of those questions where the difference between the two languages looks very small on the surface, but it completely changes their computational complexity. Let''s break both down carefully.
L1 = {ambmcm+n | m, n ≥ 1}
In L1, the number of a''s must equal the number of b''s, and the number of c''s must equal m+n. So the count of c''s depends on both m (which is also tied to the count of b''s) and the free variable n. This creates a situation where the automaton must simultaneously track three dependent values — count of a''s, count of b''s (both must be equal to m), and the total count of c''s (which must be m+n).
A pushdown automaton only has a single stack, and it can''t juggle three interdependent counts at the same time. Once it uses the stack to match a''s with b''s, it has lost the information needed to correctly verify the count of c''s. The CFL pumping lemma formally proves L1 is not context-free — any attempt to pump a string in L1 breaks either the a=b equality or the c=m+n condition.
L2 = {ambncm+n | m, n ≥ 1}
Now look at L2. Here, m and n are completely independent of each other — there''s no constraint linking the count of a''s to the count of b''s. The only requirement is that the number of c''s equals the total count of a''s and b''s combined.
This is something a PDA handles very naturally. The PDA simply pushes every a and every b onto the stack as it reads them, and then pops one symbol for each c it encounters. If the stack is empty exactly when all c''s are consumed, the string is accepted. Only one stack operation is needed throughout, making L2 a context-free language.
A simple context-free grammar for L2 would be:
S → AC, A → aAb | ab, C → cC | c (with appropriate adjustments to ensure counts align)
The key takeaway here — whenever you see a language that requires matching counts across three separate sections all tied to the same variable, it''s almost certainly not context-free. But when the counts in one section are a simple sum of two independent variables, a PDA can usually handle it with ease.

Similar Questions

Consider the following languages over the alphabet Σ = {0, 1, c}:L₁ = {0ⁿ1ⁿ | n ≥ 0}L₂ = {wcwʳ | w ∈ {0, 1}*}L₃ = {wwʳ | w ∈ {0, 1}*}Here, wʳ is the reverse of...
#1310 MCQ
A palindrome is a word that reads the same forwards and backwards. In a game of words, a player has the following two plates painted with letters. From...
#1 MCQ
Which number does not belong in the series below? 2, 5, 10, 17, 26, 37, 50, 64
#4 MCQ

Related Topics

context-free language GATE 2025 GATE CS 2025 Set-1 Q45 L1 L2 CFL ambmcm+n not CFL ambncm+n CFL pushdown automaton PDA pumping lemma CFL formal languages GATE theory of computation GATE CFL vs non-CFL GATE computer science 2025 context-free grammar CFG

Unique Visitor Count

Total Unique Visitors

Loading......