GATE / CS ARCHIVE

SIMILAR QUESTIONS / THEORY OF COMPUTATION

Intersect two stack-checkable block equalities

3 questions solved the same way, newest first. Back to Theory of Computation

How these are solved

Each operand checks one adjacent count equality; their intersection forces three equal blocks and is not context-free. Later questions include additional union/complement claims and are only method matches.

2 marks · MSQ
Report issue

Context-Free Grammars & Languages

Question 48, GATE 2022: L1={ww:w∈{a,b}*}, L2={a^n b^n c^m:m,n≥0}, L3={a^m b^n c^n:m,n≥0}. Select FALSE claims: A L1 not context-free, L2/L3 deterministic context-free; B neither L1 nor L2 context-free; C L2,L3 and their intersection all context-free; D neither L1 nor its complement context-free.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: B,C,D

The copy language L1={ww} is not context-free: intersecting with a+b+a+b+ gives {aⁱbʲaⁱbʲ: i, j>0}. For pumping length p, aᵖbᵖaᵖbᵖ has any pumping window of length at most p within at most two adjacent blocks. Pumping changes at least one block without changing its matching nonadjacent block, or creates extra alternations, contradicting this language’s form. L2 and L3 are deterministic context-free by pushing one block and matching the adjacent equal-count block; their intersection is {aⁿbⁿcⁿ}, not context-free. Thus A is true and B, C are false. D is also false because the complement of L1 is context-free: include all odd-length words, and for even length choose two different symbols in corresponding half-positions. Let Ea={uav:|u|=|v|} and Eb={ubv:|u|=|v|}; each is context-free via Sa→cS_a d | a for c, d∈Σ, and similarly Sb. E_aE_b ∪ E_bE_a describes exactly the even noncopies, since the two centers differ and are separated by half the total length. Closure under concatenation and union proves the complement claim. Select false statements B, C, D.

For the complement construction, Ea contains odd strings whose center is a and Eb those whose center is b. Concatenating lengths 2r+1 and 2s+1 puts their centers r+s+1 positions apart, exactly half the total length. Thus choosing unequal centers witnesses unequal half-positions. Conversely any mismatching pair in two equal halves determines such a split. Odd-length strings are automatically noncopies and form a regular language.

Original paper, page 32 · Answer key

2 marks · MCQ
Report issue

Closure Properties & Language Hierarchy

Question 38, GATE 2017: L1={a^n b^n c^m:m,n≥0}, L2={a^m b^n c^n:m,n≥0}. Which are context-free? I L1∪L2; II L1∩L2. A I only; B II only; C both; D neither.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

1. L1 is context-free: a stack can match a’s with b’s and then ignore a trailing c block. L2 is likewise context-free by ignoring the initial a block and matching b’s with c’s.

2. Context-free languages are closed under union: a new start symbol can choose either constituent grammar. Therefore I holds.

3. Intersection forces #a=#b=#c and preserves block order, giving {an bn cn}. For pumping length p, a pump window of length at most p in ap bp cp touches at most two blocks. Pumping changes some count but leaves a third unchanged, or breaks the block order. Thus it is not context-free; answer A.

Original paper, page 17 · Answer key

2 marks · MCQ
Report issue

Intersection of two context-free languages

Closure Properties & Language Hierarchy

Question 55, GATE 2005: L1={a^n b^n c^m:n, m>0}, L2={a^n b^m c^m:n, m>0}. Identify the false claim among: A their intersection is context-free; B their union is context-free; C both individual languages are context-free; D their intersection is context-sensitive.
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

L1={an bn cm:n, m>0} and L2={an bm cm:n, m>0} each need only one stack comparison, hence are CFLs. CFLs are closed under union. Their intersection is {ak bk ck:k>0}, which is not context-free (standard CFL pumping argument) but is context-sensitive by linear-space counting. The false assertion is A.

Each individual language compares only two adjacent block counts and allows the remaining block freely, which a PDA can handle. Closure under union proves the union claim. In the intersection, the first language forces #a=#b and the second forces #b=#c, hence all three counts coincide. The standard pumping argument prevents a single stack from enforcing these three blocks: a short pumped region cannot cover all three, so pumping changes only one or two counts or disrupts the block order. Linear-space checking still recognizes the intersection, establishing context sensitivity.

Original paper, page 7