GATE Daily

Tuesday27 October 2026

Past sets27 Oct 2026TOC

Context-free grammars: GATE CS question with solution

Q.6

Consider the following two context-free grammars over the terminal alphabet . In each grammar is the only non-terminal and the start symbol, and denotes the empty string.

Which one of the following statements is CORRECT?

One try. It counts in your 27 Oct 2026 set.
Show solution
RememberTo find L(G), write what each production contributes to the symbol counts, then show both directions: every derivation gives a string of the claimed form, and every string of that form has a derivation. One self-embedding rule does not make a language non-regular if other rules undo the count matching.

Solution MCQ · 2 marks · −⅔ if wrong

Answer: (A) and is regular

Method. Find what every sentential form looks like, then read off the language.

. Every rule puts its 's to the left of and its 's to the right, so a sentential form is . The rule adds one and two 's; adds one only. If is used times and is used times, the final string is . So , and every pair is reachable (apply times, then times, then ). Hence . Quick check: but .

. Again all 's stay left of and all 's right of it, so every string is . Conversely any is derived by applying times, times, then . So , which is regular. The rule is redundant.

The trap. A rule of the form suggests , but a grammar's language is not decided by one rule: here and let the two counts vary independently, so the "matching" is lost. In the opposite care is needed: the extra rule adds only 's, so the -count can exceed the number of blocks but never fall below it.

What was tested. Deriving a grammar's language from the contribution of each production (a symbol-count argument in both directions), and not judging regularity from the shape of a single production.

Copied. Paste it into the new chat.Too long to send. Copy the question and solution by hand.