GATE / CS ARCHIVE

GATE CSE 2020 / QUESTION 32

GATE CSE 2020 Q32

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

GATE 2020, Q32 2 marks · MCQ
Report issue

Context-Free Grammars & Languages

Question 32, GATE 2020: L1={wxyx:w,x,y∈{0,1}*}; L2={xy:x,y∈{a,b}*, |x|=|y|, x≠y}. Which statement is true? A L1 regular and L2 context-free; B L1 context-free but not regular, L2 context-free; C neither context-free; D L1 context-free, L2 not context-free.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Worked explanation

Empty strings are permitted for the starred variables in L1. Setting x=y=ε produces every binary w, so repeated appearances of x impose no restriction at all. For L2, the grammar below is more informative than incorrectly invoking closure under complement of context-free languages. Write V→b|aVa|aVb|bVa|bVb in addition to the displayed U productions. U and V wrap arbitrary equal numbers of symbols around different central letters. Concatenating them makes the central positions differ by half the total length. Conversely, if unequal halves of length m differ at position r, choose first component length 2r−1 and second length 2(m−r)+1. Their centers land at r and m+r. This proves both grammar inclusions, hence context-freeness without claiming that arbitrary complements of CFLs are CFLs.

Derivation and answer

For L1 choose x=ε, y=ε and let w be any binary string; hence L1=Σ*, regular. For L2 a CFG can guess a differing position in the two equal-length halves. Explicitly let U generate all odd-length strings with central a via U→a|aUa|aUb|bUa|bUb, and V generate those with central b by the analogous rules with base b. S→UV|VU then generates exactly even-length strings whose two halves differ somewhere. If component lengths are 2i+1 and 2j+1, their differing central symbols are i+j+1 positions apart, exactly half the total length. Conversely any mismatch supplies such a split. Thus L2 is context-free and A holds.

Original paper, page 11 · Answer key