GATE / CS ARCHIVE

GATE CSE 2018 / QUESTION 35

Which counting languages are context-free

Theory of Computation · Context-Free Grammars & Languages · Full GATE CSE 2018 paper

GATE 2018, Q35 2 marks · MCQ
Report issue

Context-Free Grammars & Languages

Question 35, GATE 2018: Over words a^m b^n c^p d^q, with all exponents nonnegative, define I m+p=n+q; II m=n and p=q; III m=n=p and p≠q; IV mn=p+q. Which are context-free? A I,IV; B I,II; C II,III; D II,IV.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

Method

One stack can track a single signed difference, so the crossed-looking equality in I is still manageable; a finite-state component checks block order. II has grammar S→AB, A→aAb|ε, B→cBd|ε. For III, restricting to positive a,b,c blocks and no d leaves the standard non-CFL equal-three-count language. For IV, the multiplication constraint cannot be reduced to one additive counter. The pumping argument below makes this precise, including decompositions that cross a block boundary rather than assuming where the pumped substrings lie.

Solution

I is context-free: a PDA tracks the signed running difference(#a+#c)−(#b+#d) with one stack symbol for positive excess and another for negative excess, canceling opposite contributions; finite control enforces a*b*c*d* order. II is the concatenation{an bn}{cp dp}, a CFL. For III, intersect with a+b+c+ (no d); the result is{an bn cn: n≥1}, not context-free. For IV, suppose pumping length p and take ap bp cp². Pumping up either disrupts block order or adds α a symbols, β b symbols and γ c symbols, with α+β+γ≤p and at least one added symbol. If α+β=0, the product stays p² but γ>0. Otherwise the required increase in c is p(α+β)+αβ≥p, while actual γ≤p−α−β<p. In every case the equality mn=p+q fails (here the fourth-block length remains 0). Thus only I and II are CFL, B.

Original paper, page 14 · Answer key