To convert a context-free grammar to Chomsky normal form, first add a fresh start symbol. Remove epsilon productions, retaining the exceptional start production only when the empty word is to remain in the language; then remove unit productions and symbols that cannot participate in a terminal derivation. Replace each terminal occurring in a right-hand side of length at least two by a new nonterminal that produces that terminal. Finally split every right-hand side of length greater than two into binary productions using fresh nonterminals.
CYK algorithm 2026-10-03
The CYK algorithm decides membership in a context-free language given by a grammar in Chomsky normal form. It records, for every substring, the nonterminals that derive that substring and combines adjacent substrings using binary productions. For a word of length and a fixed grammar, it runs in time.
Past exam of the mathematics course of the University of Cambridge 2017 ii Paper 3 4H a Solution Created 2026-09-24 Updated 2026-10-05
In strict Chomsky normal form, every production of a context-free grammar is or , with nonterminal symbols and a terminal symbol. Such a derivation cannot produce the empty word: it starts with one nonterminal symbol, and every step either increases the symbol count or replaces one symbol by one symbol. The context-free language , generated by , is therefore not generated by any strict CNF grammar.
The convention matters: extended Chomsky normal form permits with excluded from right-hand sides. Under that convention every context-free language has such a grammar, so the requested example would not exist.
Past exam of the mathematics course of the University of Cambridge 2017 ii Paper 3 4H c Solution Created 2026-09-24 Updated 2026-10-05
Context-free languages are closed under union: use a new start symbol with alternatives for two renamed context-free grammars. If they were closed under complement in , De Morgan's laws would givecontradicting the preceding intersection example. Therefore some CFL has a non-context-free complement. This is an existence argument; it does not assert that both complements of the particular are non-context-free.
A concrete choice is . Words outside form a regular language. Among words inside it, membership in means the first two counts or the last two counts differ. Each unequal-count comparison has a context-free grammar: for with , use , ; for , replace by . Append any number of 's, or prefix any number of 's for the analogous comparison. Taking these unions gives a context-free language whose complement is the non-context-free equal-three-count language. These productions are definitions of the example, not a restriction to strict Chomsky normal form.
Past exam of the mathematics course of the University of Cambridge 2018 ii Paper 3 4G a Solution Created 2026-09-24 Updated 2026-10-03
A context-free grammar is in Chomsky normal form when every production rule has one of the formswhere are nonterminal symbols and is a terminal symbol. If the language contains the empty word, one may additionally permit , with the start symbol absent from all right-hand sides.
Past exam of the mathematics course of the University of Cambridge 2018 ii Paper 3 4G c Solution Created 2026-09-24 Updated 2026-10-03
The original grammar generatesbecause each use of adds one on the left and one on the right, and terminates the derivation.
Introduce nonterminals and useEvery production is in Chomsky normal form. The production completes one matched pair, while either start-like symbol terminates with , so the grammar generates exactly the same language. These productions are a valid .
Past exam of the mathematics course of the University of Cambridge 2019 ii Paper 3 4H a Solution Created 2026-09-24 Updated 2026-10-03
A context-free grammar is in Chomsky normal form when every production is of one of the formswhere are nonterminal symbols and is a terminal symbol. Under this strict convention there is no epsilon production, so such a grammar cannot generate the empty word. Conversion of an arbitrary grammar therefore givesIf , the two languages are equal. An alternative extended convention permits the exceptional start production ; under that convention conversion preserves the whole language.
Past exam of the mathematics course of the University of Cambridge 2019 ii Paper 3 4H c Solution Created 2026-09-24 Updated 2026-10-03
Introduce nonterminals for the terminals and one for the pair :Because the original start symbol occurs on a right-hand side, take a fresh start symbol . After eliminating the unit production , one grammar in Chomsky normal form isThe original grammar generates exactlyThe displayed grammar generates the same set: adds an on the left, adds one pair on the right, and terminates the derivation with . Since the original grammar does not generate ,
Past exam of the mathematics course of the University of Cambridge 2020 ii Paper 4 4F Solution Created 2026-09-24 Updated 2026-09-29
A context-free grammar is in Chomsky normal form when every production has the form or , where are nonterminals and is a terminal symbol; one may additionally allow the new start production when the language contains the empty string, provided never appears on a right-hand side.
The standard conversion proceeds as follows.
- Introduce a fresh start symbol and . This changes only when the old start symbol occurs on a right-hand side or when a protected start symbol is needed to preserve .
- Find all nullable nonterminals, add productions obtained by omitting nullable occurrences, and remove the original -productions except the permitted . This leaves unchanged.
- Eliminate each unit production by adding to the non-unit productions reachable through its transitive closure. This leaves unchanged.
- Delete non-generating symbols and then unreachable symbols. This is the only simplification stage that can shrink .
- In every right-hand side of length at least two, replace a terminal by a fresh nonterminal with . New nonterminals are needed exactly for terminals that occur in such mixed or long productions.
- Break every right-hand side of length at least three into binary productions, introducing fresh nonterminals for successive suffixes. New nonterminals are needed exactly when such long productions remain.
The terminal alphabet may be kept unchanged throughout, although unused terminals may be discarded by convention. Every stage preserves the generated language, with the explicit protection of at the start-symbol stage. For example,is already in Chomsky normal form and generates the infinite language , so its conversion may be the grammar itself.
Past exam of the mathematics course of the University of Cambridge 2021 ii Paper 3 12F i Solution Created 2026-09-24 Updated 2026-09-25
A parse tree has the start variable at its root; the ordered children of a variable spell the right side of the production used at that occurrence, and its leaves, read left to right, spell the derived word.
For a grammar in Chomsky normal form with variables, take pumping length . A parse tree for a word of length at least has a root-to-leaf path containing one variable twice. The yield can therefore be writtenwhere , , and replacing the subtree between the repeated variables zero, one, or several times provesThis is the pumping lemma for context-free languages. Without Chomsky normal form but with no epsilon or unit productions, use the maximum production length to choose a larger exponential ; bounded branching and the same repeated-variable argument apply.
Past exam of the mathematics course of the University of Cambridge 2022 ii Paper 4 4I Solution Created 2026-09-23 Updated 2026-09-25
A context-free grammar is in Chomsky normal form when every production has one of the formswhere are nonterminals and is a terminal. One may additionally allow when the empty word belongs to the language, usually with the restriction that the start symbol does not occur on a right-hand side.
In , the productions for giveConsequentlyIn , and generate and , while again givesSince , the two start productions generate exactlyThusEvery production of has the required binary-nonterminal or single-terminal form, so is the Chomsky-normal-form grammar for the nonempty part of .
Past exam of the mathematics course of the University of Cambridge 2023 ii Paper 1 4I a Solution Created 2026-09-24 Updated 2026-09-25
A context-free grammar is in Chomsky normal form when every production is of one of the formswhere are nonterminal symbols and is a terminal symbol. The conventional exceptional production may be allowed when the language contains the empty word, with excluded from right-hand sides.
Past exam of the mathematics course of the University of Cambridge 2023 ii Paper 1 4I d ii Solution Created 2026-09-24 Updated 2026-09-25
The compressed initial production gives the leftmost derivationIt has steps, whereas part (b) gives for every derivation in Chomsky normal form. The Weak Chomsky normal form ternary rule has compressed exactly one pair of binary productions, so the derivation is strictly shorter as required.