GATE / CS ARCHIVE

GATE CSE 2017 SET 1 / QUESTION 37

GATE CSE 2017 Set 1 Q37

Theory of Computation · Context-Free Grammars & Languages · Full GATE CSE 2017 Set 1 paper

GATE 2017 Set 1, Q37 2 marks · MCQ
Report issue

Context-Free Grammars & Languages

Question 37, GATE 2017: G1: S→aSb | T, T→cT | ε. G2: S→bSa | T, T→cT | ε. Classify L(G1)∩L(G2): A finite; B infinite regular; C context-free but not regular; D recursive but not context-free.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

1. Applying G1’s outer production n times wraps n a’s before and n b’s after T. T supplies any cm, so L(G1)={an cm bn:n,m≥0}.

2. Similarly L(G2)={bn cm an:n,m≥0}. Any G1 word with n>0 starts with a, while any G2 word with positive outer count starts with b. Such words cannot agree.

3. Common words must have zero outer count in both grammars, leaving exactly c*. This contains ε,c,cc,..., so it is infinite and regular. Answer B.

Original paper, page 17 · Answer key