- 2072 Chaitra
CNF: S→AB, A→aAA|ε, B→bBB|ε
Short answer
Remove ε-productions: S→AB|A|B|ε, A→aAA|aA|a, B→bBB|bB|b. Remove unit productions: S→AB|aAA|aA|a|bBB|bB|b|ε. Introduce Xa→a, Xb→b, C→AA, D→BB. CNF: S→AB|XaC|XaA|a|XbD|XbB|b|ε, A→XaC|XaA|a, B→XbD|XbB|b, C→AA, D→BB, Xa→a, Xb→b.
Convert the given context free grammar (CFG) into an equivalent CNF: S → AB; A → aAA | ε; B → bBB | ε (ε is the empty symbol).
Grammar: S → AB; A → aAA | ε; B → bBB | ε.
Step 1: Start symbol
S does not appear on any right-hand side, so no new start symbol is needed.
Step 2: Remove ε-productions
Nullable: A, B, and S (S → AB). Generate all variants:
- S → AB gives AB | A | B (we drop the all-ε variant; ε stays only for S).
- A → aAA gives aAA | aA | a.
- B → bBB gives bBB | bB | b.
S → AB | A | B | ε
A → aAA | aA | a
B → bBB | bB | b
S → ε remains because ε ∈ L(G) and S is the start symbol not occurring on a right side.
Step 3: Remove unit productions
S → A and S → B are units. Replace by the rules of A and B:
S → AB | aAA | aA | a | bBB | bB | b | ε
A → aAA | aA | a
B → bBB | bB | b
Step 4: Convert to CNF
Terminals inside longer rules: Xa → a, Xb → b. Break long rules: C → AA, D → BB.
S → AB | XaC | XaA | a | XbD | XbB | b | ε
A → XaC | XaA | a
B → XbD | XbB | b
C → AA
D → BB
Xa → a
Xb → b
All rules have the form X → YZ or X → a (S → ε allowed for the start). This is the required CNF.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Define CNF; convert S→MaN|bL|bM grammar · Theory of Computation, chapter 3
- CNF conversion (grammar with S→A|B) · Theory of Computation, chapter 3
- Unrestricted grammar; superset of CFG · Theory of Computation, chapter 4 · asked 2×
- CFG versus unrestricted grammar · Theory of Computation, chapter 4
- CNF: S→XYZ|XY|aZ · Theory of Computation, chapter 3
- CNF: S→ASB|ε, A→aAS|a, B→... · Theory of Computation, chapter 3
- Context-sensitive, context-free, regular grammars · Discrete Structure, chapter 2
- Language of grammar; grammar for strings not ending in ab · Discrete Structure, chapter 2
- NFA and DFA from grammar with A, B rules · Discrete Structure, chapter 2 · asked 2×
- NFA and DFA from grammar σ→aA|bB · Discrete Structure, chapter 2 · asked 2×