Context-Free Grammars & Languages



Answer & solution
Answer: bcde (length 4) (no official key was published)
Bcde has two different parses. The difference is whether the initial b and final e are supplied by the outer S rule or by P and R:
Parse 1: S⇒PQR, with P⇒bPc⇒bc, Q⇒ε, R⇒dRe⇒de. Concatenation gives bcde.
Parse 2: S⇒bSe⇒bPQRe, with P⇒ε, Q⇒cQd⇒cd, R⇒ε. This also gives bcde.
These are distinct parse trees because the first root uses S→PQR and the second root uses S→bSe. Merely changing the order of independent rewrites would not demonstrate ambiguity; here the production at the root really differs.
To prove shortestness, fix a word's exponents. Every parse is uniquely determined by t, the number of outer S→bSe applications, since p=i−t, q=j−i+t and r=m−t determine the unique chains in P,Q,R. Two parses require two possible t values. If consecutive valid choices are t and t+1, the lower choice has p≥1 and r≥1. Those two recursive chains alone contribute at least two b/c symbols and two d/e symbols, so the total length is at least four. The displayed word attains that bound.