← 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.
Discussion
Ask a question, share your thoughts or report an error.
Sign in to participate in the discussion.
Join the discussion