GATE / CS ARCHIVE

GATE CSE 1998 / QUESTION 14(c)

Is the four-run language inherently ambiguous?

Theory of Computation · Context-Free Grammars & Languages · Full GATE CSE 1998 paper

GATE 1998, Q14(c) Descriptive
Report issue

Context-Free Grammars & Languages

Question 14(c), GATE 1998: For L2={a^i b^j a^k b^l : i,j,k,l≥1 and (i=j or k=l)}, decide whether it is inherently ambiguous. Use the grammar extension from part (b) if helpful.
Question 14(c), GATE 1998: For L2={a^i b^j a^k b^l : i,j,k,l≥1 and (i=j or k=l)}, decide whether it is inherently ambiguous. Use the grammar extension from part (b) if helpful.
Question 14(c), GATE 1998: For L2={a^i b^j a^k b^l : i,j,k,l≥1 and (i=j or k=l)}, decide whether it is inherently ambiguous. Use the grammar extension from part (b) if helpful.
Question 14(c), GATE 1998: For L2={a^i b^j a^k b^l : i,j,k,l≥1 and (i=j or k=l)}, decide whether it is inherently ambiguous. Use the grammar extension from part (b) if helpful.
Tap to enlarge
Answer & solution

Answer: No. The four-rule extension gives an unambiguous CFG. (no official key was published)

A context-free language is inherently ambiguous only if every CFG generating it is ambiguous. It is therefore enough to exhibit and prove one unambiguous grammar. Use the extension from part (b): S2→TAB|S1T, T→aTb|ab, retaining the unambiguous unequal-count grammar G1.

Every word of L2 has four nonempty runs ai,bj,ak,bl. The boundaries between the runs are determined by changes of symbol, particularly the middle b-to-a change, so a derivation cannot shift the split between its two a*b* components.

If i=j, only S2→TAB can apply, since S1 generates unequal first counts. The exponent i fixes the unique derivation in T. The remaining exponents k and l fix the unique unary derivations in A and B. If i≠j, only S2→S1T can apply. Then membership requires k=l. Part (a)'s proof gives a unique derivation of ai bj in S1, and the common value k=l gives a unique derivation in T. Hence each word has exactly one parse tree.

Words satisfying both equalities still use only the first branch, so they do not create an intersection ambiguity. A different grammar with productions for “first pair equal” and “second pair equal” may generate those words twice, but ambiguity of one grammar does not establish inherent ambiguity of its language. This four-run language also should not be confused with classical three-run examples whose equality conditions share the middle count. The explicit disjoint grammar here proves that L2 is not inherently ambiguous.

Original paper, page 7