4.6.9 · D5Theory of Computation

Question bank — Chomsky Normal Form (CNF) — conversion

1,679 words8 min readBack to topic

True or false — justify

Recall the two legal shapes: (two variables) and (one terminal), plus the special .

A grammar in CNF can never generate the empty string.
False. The special rule is allowed precisely so CNF can generate when the language contains it; only that one start-symbol rule may be empty.
where and are the same variable (e.g. ) is illegal in CNF.
False. "Two variables" means two variable occurrences; is a perfectly legal CNF rule since both children are variables.
where is a terminal is only legal if is the start symbol.
False. Any variable may go to a single terminal; that restriction only applies to -rules, not terminal rules.
The rule is illegal if is the start symbol, because the start symbol must be "clean".
False. The START step keeps the start symbol off the right-hand side; it may still appear on the left of any two-variable rule. is fine.
Every CNF grammar's parse tree for a string of length has exactly internal-plus-leaf structure making it a full binary tree.
True (for ). Every internal node has exactly two children, so the tree is a binary tree with leaves (one per terminal) and internal branchings, powering the CYK Algorithm.
Doing BIN before DEL gives the same final grammar, just via a different path.
False. BIN creates fresh variables inside long right-hand sides; if you then run DEL, nullable propagation can force you to re-binarize the patched rules, so the cleanup is not equivalent and may need redoing.
A grammar with no -rules and no unit rules is already in CNF.
False. It can still have mixed rules like or long rules like ; TERM and BIN are still required.
If a variable is unreachable from the start symbol, it can safely stay in the grammar and the result is still valid CNF.
True for form — an unreachable variable in CNF shape breaks no CNF rule. But it's dead weight; Sipser's pipeline doesn't require removing it, though a tidy grammar would.
for a non-start can appear in a CNF grammar as long as is nullable anyway.
False. Non-start -rules are outright forbidden in CNF; DEL exists to eliminate every one of them.

Spot the error

Each line describes a step someone performed. Say what went wrong.

"Nullable set: , , so is nullable."
Error — is nullable only if every symbol on some right-hand side is nullable. Here 's status is unknown; if is not nullable, is not nullable.
" with nullable, so DEL adds only and ."
Error — you must add a rule for every subset of the nullable positions dropped: . Dropping both and (giving ) was forgotten.
" with both nullable, so DEL adds , , and ."
Error — the empty-right-hand-side case is never added (it would recreate an -rule). You add and only.
"UNIT: and , so I add and stop."
Error — unit pairs use the transitive closure, and you copy the non-unit bodies of each reachable variable. You must copy 's terminal/two-variable bodies into , not add another unit rule .
"TERM: rule has a terminal, so I introduce and rewrite it as ."
Error — a standalone is already legal CNF. TERM only isolates terminals that are mixed with other symbols in a longer rule; you just created an illegal unit rule .
"BIN: becomes , ."
Error — that splits the rule into two alternatives, changing the language. BIN must chain: , , .
"I ran TERM first on then UNIT, and got a unit rule I couldn't remove."
Error — running steps out of Sipser order (START→DEL→UNIT→TERM→BIN) can reintroduce unit-like rules after UNIT already ran. Follow the order so UNIT never has to run twice.
"; UNIT copies 's bodies into but I keep so nothing is lost."
Error — after copying 's non-unit bodies you must delete the unit rule ; keeping it leaves an illegal rename in the grammar.

Why questions

Why does Sipser add a fresh start symbol before anything else?
So the start symbol never appears on any right-hand side; then giving the start the special -privilege can't tangle with other rules that mention it.
Why must DEL and UNIT run before TERM and BIN?
DEL and UNIT can only shrink or rename right-hand sides, while TERM and BIN only lengthen or relabel; doing the shrinkers first means the lengtheners never have to be redone.
Why does DEL add a rule for every subset of nullable positions rather than just one?
A nullable symbol can independently be present or absent in a derivation, so every combination of "which nullable symbols vanished" is a genuine derivation that must be preserved.
Why is the empty-right-hand-side case excluded when patching a rule in DEL?
Adding it would recreate exactly the -rule DEL is trying to remove, defeating the step (except for the permitted ).
Why do unit rules produce "no branching and no terminal", making them useless for CNF?
A rule replaces one variable by one variable — the parse tree gets a node with a single child, which breaks the required full-binary structure and never emits a symbol.
Why does CNF insist on exactly two variables rather than "at most two"?
Exactly two children at every internal node fixes the node count at for a length- string, giving the predictable binary tree that CYK Algorithm and the Pumping Lemma for CFLs rely on.
Why isn't Greibach Normal Form used instead for these proofs?
GNF (rule form ) is tuned for building Pushdown Automata and guaranteeing a terminal per derivation step; CNF's binary-tree shape is what CYK and the CFL pumping lemma need, so each normal form serves a different job.
Why can UNIT increase the number of rules dramatically?
For each variable you copy the non-unit bodies of every variable it can reach through unit chains, so a densely connected unit graph fans many bodies into many variables.

Edge cases

If the original grammar generates , where does that ability end up after conversion?
In the single rule on the fresh start symbol; DEL removes every other -rule but preserves this one when is in the language.
A grammar has a rule . What happens to it?
It's a trivial self-unit rule; UNIT's closure includes the reflexive pair and the rule is simply dropped, since copying 's bodies into adds nothing.
Every variable in the grammar is nullable. What does DEL produce for a rule ?
It adds (all non-empty subsets) but never ; the fully-empty case is skipped.
A rule is already exactly . Do TERM and BIN touch it?
No — it has no terminal to isolate (TERM skips it) and length two needs no splitting (BIN skips it). It's already in final CNF shape.
A rule is where is the only symbol. Does any step change it?
No — it's already a legal terminal rule; DEL, UNIT, TERM, and BIN all leave a standalone single-terminal rule untouched.
The grammar is a single rule and is the whole language. What is the CNF result?
After START you get , ; DEL makes nullable, so the final CNF is just , the one permitted empty rule.
What if BIN faces a rule of length exactly 2 but one symbol is a terminal, like (before TERM ran)?
BIN alone can't fix it because the terminal is illegal; this is why TERM must run first, turning it into (already length 2, so BIN then skips it).
Recall Fastest way to catch a "not-yet-CNF" rule

Scan each right-hand side: length must be exactly 1 (and that one symbol a terminal) or exactly 2 (and both symbols variables). Anything else — mixed, too long, a lone variable, or a non-start — is not CNF.