Question
If is a grammar with productions
where is the start variable, then which one of the following strings is not generated by ?
Official answer and solution
- Official answer
- D
- From
- Official GATE 2017 answer key
Solution
Find an invariant property relating the counts of terminals 'a' and 'b' across all production rules in grammar G.
Examine the production rules of the grammar:
Let and denote the number of occurrences of 'a' and 'b' in string :
- introduces one 'a' and zero 'b's: .
- introduces one 'a' and one 'b': .
- introduces one 'a' and one 'b': .
- preserves the sum of differences from each subderivation.
- produces the empty string with .
Because every production rule either increases by 1 without increasing , or increases both and by 1 equally, every string generated by must satisfy the invariant:
Check each candidate string:
- (A)
abab: . Generated by . - (B)
aaab: . Generated by - (C)
abbaa: . - (D)
babba: . This violates the invariant and can never be generated by .
D
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2017 Computer Science and Information Technology (CS) Session 1
- Question
- 34 of 65, printed as CS Q.34
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.