CYK Algorithm

Context: FIT2014_MOC Β· the decision procedure for CFL membership β€” a bottom-up parser that runs in polynomial time on any CFG, ambiguous or not Parent Framework: Chomsky Normal Form

Quick Revision

  • 🎯 Objective: given a CFG and a string , decide whether the grammar generates βž” build up, by substring length, the set of nonterminals deriving each substring; Accept iff derives the whole string.
  • πŸ“¦ Core Components: CNF grammar βž” every split is binary | length-ordered table βž” answers for length reuse all shorter answers.
  • ⚑ Key Constraint: the grammar must be in Chomsky Normal Form first, and must be sent to the nullability algorithm instead β€” CNF cannot generate .

πŸ“ How It Works

1. Setup

  • Input βž” with each a letter, .
  • Empty string βž” if , run nullability (see there) and stop.
  • Otherwise βž” convert to Chomsky Normal Form for the non-empty words, then fill the table.

2. Base row β€” single letters

  • For each , collect every nonterminal with a dead production .

3. Inductive rows β€” every longer substring

  • Pairs βž” for each deriving and deriving , add every with a rule .
  • Triples βž” consider both binary splits, and : for each left part and right part, add every with .
  • Length βž” there are split points; take the union over all of them.
  • Rules That Always Hold: βž” CNF guarantees exactly two children, so only binary splits ever need checking; a substring of length only ever consults substrings of length .

4. Decide

  • Accept iff the start symbol appears in the cell for the whole string ; otherwise Reject.

πŸ“Š Exam Execution Trace & Applied Exercises

Manual Execution Trace

Grammar , in CNF: , , Β· Input ().

Cell = nonterminals deriving the substring of length starting at position .

1: : : : :
2: : : :
3: : :
4: :
5:

Justifications for the non-empty cells:

CellSplit usedPairRule fired

Final Extracted Output: ⟹ the grammar generates β€” ACCEPT. (Sanity check: and , exactly applied twice.)

Applied Exercise

Problem: the lecture sets three exercises β€” write the algorithm formally, prove it correct by induction, and give its complexity. The complexity argument:

Final Extracted Output: in the string length for a fixed grammar β€” polynomial, which is the whole point of the algorithm. (Correctness is by induction on substring length: the base row is exact by the dead productions, and the inductive step is exact because CNF forces a binary root split, so every derivation of a length- substring is caught by one of the splits.)


⚠️ Common Mistakes

  • πŸ’‘ Forgetting a split point βž” length needs all splits, not just . A missed split turns an Accept into a wrong Reject.
  • πŸ’‘ Running CYK on a non-CNF grammar βž” a rule like or breaks the β€œone binary split” invariant the whole table rests on.
  • πŸ’‘ Order matters in βž” must derive the left part and the right. never fires on an pair.
  • πŸ’‘ Handing to CYK βž” CNF has no -rule, so the table is meaningless; use nullability.
  • πŸ’‘ An empty cell is not an error βž” most cells are empty; only the top cell’s contents decide the answer.

🧠 Active Recall