CFG for unequal adjacent symbol counts

December 4, 2026 · Team EasyExamNotes · 1 min read (est.) · 0 comments

Share on WhatsApp

← RGPV CS-501 Theory of Computation May 2023 Solved Paper

Question

Design a CFG for L(G)={aⁱbʲcᵏ | i≠j or j≠k}.

Asked in: CS-501 | May 2023 | 5(a)(i)

Answer

Assume all exponents are nonnegative integers. Split the union into four cases: i>j, i<j, j>k, j<k. Use the following productions:

S→U E C | E V C | A V F | A F W
E→aEb | ε
F→bFc | ε
U→aU | a
V→bV | b
W→cW | c
A→aA | ε
C→cC | ε

E generates equal a and b counts, F equal b and c counts. U,V,W generate positive runs. The four alternatives therefore enforce exactly the four inequalities respectively. For example aabcc is generated by UEC with U=a, E=ab, C=cc. The word abc cannot be generated because all counts are equal. Every word satisfying either inequality falls into at least one of the four cases.

← RGPV CS-501 Theory of Computation May 2023 Solved Paper

Discussion

Ask a question, share your thoughts or report an error.

Sign in to participate in the discussion.

Join the discussion