Consider the context-free grammars over the alphabet given below. and are non-terminals.
The language is
View worked solution
Answer: B
To find the language , let us first determine the languages generated by the individual grammars and .
1. Analyzing Grammar
The productions are:
The non-terminal generates any number of 's, i.e., .
The non-terminal recursively wraps with an equal number of 's on the left and 's on the right. Thus:
2. Analyzing Grammar
The productions are:
Similarly, generates , and wraps it with an equal number of 's on the left and 's on the right. Thus:
3. Finding the Intersection
Let . Then must satisfy the formats of both languages simultaneously:
- Case 1:
If , the string starts with the symbol . For to also belong to , the string must start with . This is only possible if (so it doesn't start with ) and with the first symbol being , which is impossible because contains only 's. Thus, no string with can belong to the intersection. - Case 2:
If , then . For this to match , we must have , which gives . This is perfectly consistent for any .
Therefore, the intersection contains only strings of the form for :
Conclusion
The language is infinite and can be represented by a regular expression, meaning it is regular. Thus, the language is not finite but regular.
Free practice · Your answers on this page are not saved.
