If is a grammar with productions
where is the start variable, then which one of the following strings is not generated by ?
View worked solution
Answer: D
To determine which string cannot be generated by the grammar , we can analyze the properties of the strings generated by its production rules:
1. Finding the Invariant of the Grammar
Let and denote the number of occurrences of the symbols and in a string , respectively. Let's analyze how each production affects these counts:
- : and . Here, .
- : Adds exactly one and one . If the inner satisfies , then the resulting string also satisfies .
- : Adds exactly one and one . If the inner satisfies , then the resulting string also satisfies .
- : Adds one and no . This strictly increases the count of relative to , preserving .
- : Concatenates two strings. If both satisfy , their concatenation also satisfies .
By induction, every string generated by must satisfy the invariant:
2. Testing the Options
- Option A (): , . Since , it satisfies the invariant.
Derivation: - Option B (): , . Since , it satisfies the invariant.
Derivation: - Option C (): , . Since , it satisfies the invariant.
Derivation: - Option D (): , . Since , this string violates the invariant and therefore cannot be generated by .
Free practice · Your answers on this page are not saved.
