Consider the CFG with as the non-terminal alphabet, as the terminal alphabet, as the start symbol and the following set of production rules:
For the string , how many derivation trees are there?
View worked solution
Answer: B
To find the number of derivation trees for the string , we trace the leftmost derivations step-by-step starting from the start symbol :
- Since the string starts with , the first production must be:
- The second symbol is also , so we must expand using :
Now, we need to derive the remaining substring from the two non-terminals . Each must derive a substring such that . Since any string derived from has one more than , its length must be odd. Thus, the only possible odd-length partitions of the -character string are:
- Case 1: and and .
- (unique derivation)
- (unique derivation)
- Case 2: and and .
- (unique derivation)
- (unique derivation)
Since both cases yield exactly one unique derivation tree, there are a total of 2 derivation trees for the string .
Free practice · Your answers on this page are not saved.
