GATE / CS ARCHIVE

SIMILAR QUESTIONS / THEORY OF COMPUTATION

Test CFL Boolean and star closure

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

How these are solved

Apply union/concatenation/star closure, contrast unrestricted intersection/complement with intersection with a regular language. The options and side conditions differ; no exact-repeat implication.

1 mark · MCQ
Report issue

Closure Properties & Language Hierarchy

Question 1, GATE 2021: L1 is regular and L2 is context-free. Which language need NOT be context-free? A L1∩L2; B L1·L2 (concatenation); C L1−L2; D L1∪L2.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

CFLs are closed under intersection with regular languages, concatenation with regular languages, and union with regular languages. They are not closed under complement, so choosing regular L1=Σ* makes L1−L2 the complement of a CFL, which need not be context-free. For a concrete witness, the complement of the non-context-free copy language {ww} is context-free; using that complement as L2 yields the non-CFL {ww}. Thus C.

A simpler explicit counterexample to closure under difference uses Σ={a,b,c}. Define L2=Σ*\{an bn cn:n≥0}. This is context-free: strings outside a*b*c* form a regular language; inside that regular pattern, unequal a/b counts or unequal b/c counts form a union of CFLs, each checkable by a PDA. With regular L1=Σ*, L1−L2 is the standard non-CFL {an bn cn}. For A, run the DFA alongside the PDA; for B,D, use standard CFL concatenation/union constructions because regular languages are also CFLs.

Original paper, page 12 · Answer key

1 mark · MSQ
Report issue

Closure Properties & Language Hierarchy

Question 12, GATE 2021: L1 is regular and L2 context-free. Which are necessarily context-free? A L1∩¬L2; B ¬(¬L1∪¬L2); C L1∪(L2∪¬L2); D (L1∩L2)∪(¬L1∩L2). Complements are relative to the common alphabet-star.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: B; C; D

Visually reading the overbars, B is the complement of (complement L1 union complement L2), hence L1 intersection L2, which is context-free. C contains L2 union complement L2 and equals the whole alphabet-star. D is (L1 intersection L2) union (complement L1 intersection L2), hence L2. A is L1 intersection complement L2; taking L1=Σ* shows that it need not be context-free, since CFLs are not closed under complement. Thus B, C, D.

The relevant closure theorem is intersection of a CFL with a regular language, not intersection of two arbitrary CFLs. A product construction combines the CFL's PDA control with the regular DFA state without adding another stack. C and D simplify by excluded middle, so no unsupported general CFL-complement closure is used.

Original paper, page 61 · Answer key

1 mark · MCQ
Report issue

Closure Properties & Language Hierarchy

Question 4, GATE 2017: Let L1,L2 be arbitrary context-free languages and R an arbitrary regular language. Which claims always hold? I:L1∪L2 is context-free. II:complement(L1) is context-free. III:L1−R is context-free. IV:L1∩L2 is context-free. A:I,II,IV. B:I,III. C:II,IV. D:I only.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

1. I holds: take disjoint copies of the two grammars and add a new start production S→S1|S2. The resulting CFG generates their union.

2. III also holds because L1−R=L1∩complement(R). Regular languages are closed under complement, and a PDA for L1 can be combined with a finite automaton for complement(R). Thus the intersection remains context-free.

3. IV fails in general: {an bn cm} and {am bn cn} are CFLs, but their intersection {an bn cn} is not. II cannot hold for all CFLs either, since closure under both complement and union would imply intersection closure by De Morgan's law. Only I and III are guaranteed, B.

Original paper, page 3 · Answer key

1 mark · MCQ
Report issue

Closure properties of context-free languages

Closure Properties & Language Hierarchy

Question 1.5, GATE 2001: Which statement about context-free languages is true: every CFL has a deterministic PDA; CFLs are closed under union; CFLs are closed under intersection; or CFLs are closed under complement?
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

Step 1: Given grammars with disjoint renamed nonterminals and start symbols S1,S2, introduce a fresh start S→S1|S2. This grammar generates their union, proving B.

Step 2: The CFLs {an bn cm} and {am bn cn} have intersection{an bn cn}, which is not context-free. Thus C is false. If CFLs were closed under complement, their union closure and De Morgan would imply intersection closure, so D also fails.

Finally deterministic PDA languages form a strict subclass of CFLs; an arbitrary CFL need not have a deterministic PDA. Hence A is false.

Original paper, page 1

1 mark · MCQ
Report issue

Context-free closure properties

Closure Properties & Language Hierarchy

Question 1.5, GATE 1999: Which pair of operations preserves context-free languages: intersection/complement, union/Kleene star, or the other listed pairs?
Question 1.5, GATE 1999: Which pair of operations preserves context-free languages: intersection/complement, union/Kleene star, or the other listed pairs?
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

For union, introduce a fresh start symbol with alternatives leading to the two original start symbols. For Kleene star, introduce S→S_old S|ε, producing any finite concatenation of words from the original language. Thus union and star preserve context-freeness. Intersection does not: {ai bi cj} intersected with {ai bj cj} gives {an bn cn}. Closure under complement together with union would imply intersection closure by De Morgan, so complement closure also fails. Hence B.

Original paper, page 1

2 marks · MCQ
Report issue

Closure properties of context-free languages

Closure Properties & Language Hierarchy

Question 2.8, GATE 1996: For CFLs L1,L2 and regular R, which need not be context-free: concatenation, L1∩L2, L1∩R, or union?
Tap to enlarge
Your answer
Answer & solution

Answer: B, C (no official key was published)

Context-free languages are closed under union and concatenation by introducing an appropriate new grammar start rule. They are also closed under intersection with a regular language, using a product of a PDA and a finite automaton. But take L1={an bn cm} and L2={am bn cn}, with nonnegative exponents. Each is context-free, while their intersection is {an bn cn}, which is not. Hence intersection of two arbitrary CFLs is the exceptional operation. The paper instead repeats L1∩L2 in choice C, making both B and C valid answers to its literal options; this source discrepancy is retained.

Original paper, page 4

Report issue

Closure of context-free languages

Closure Properties & Language Hierarchy

Question 2(xix), GATE 1992: Which closures hold for CFLs: union, complement, intersection, Kleene star?
Question 2(xix), GATE 1992: Which closures hold for CFLs: union, complement, intersection, Kleene star?
Tap to enlarge
Select all that apply
Answer & solution

Answer: A, D (no official key was published)

For union, introduce a new start symbol choosing either original grammar. For star, use a new start that produces ε or concatenates one original-language word with another repetition. Hence both operations preserve context-freeness. Intersection does not: {an bn cm} intersected with {am bn cn} gives the non-CFL equal-three-block language. If CFLs were also closed under complement, De Morgan together with union closure would imply intersection closure, contradicting that example. Thus complement and arbitrary intersection fail.

Original paper, page 4