Context-Free Grammars & Languages



Answer & solution
Answer: B (no official key was published)
Step through it (2 derivations)
1. Approach. The first two a symbols force S→aB→aaBB. Enumerate how the remaining bbab splits between the two B subtrees. Count trees, not different orders of expanding the same tree.
2. Derivation and interpretation. The first two terminals aa force S -> aB and B -> aBB. The remaining bbab must split between the two B children. Each child has one more b than a. Exactly two splits work: b | bab and bba | b. For the first, the right child uniquely derives bab via B -> bS -> baB -> bab. For the second, the left child uniquely derives bba via B -> bS -> bbA -> bba. The single b children use B -> b. Thus there are 2 parse trees, option B; different orders of expanding a fixed tree do not count as additional trees.