CleverSphere

The CYK algorithm

The CYK algorithm decides whether a grammar in Chomsky normal form generates a word. It fills a table from short to long substrings.

Rules

  • Bottom row: variables for single symbols
  • Check every split for each substring length
  • Word generated if S is in the top cell

Your turn

Three problems on this topic. The software checks your answer exactly.

  1. 1 · CYK algorithm
  2. 2
  3. 3

Use the CYK algorithm to check whether the grammar generates the word.

S → SS ; S → AB ; A → a ; B → b · w = bbaa

How many variables are in the top cell?

Is w generated?

Worked example

Use the CYK algorithm to check whether the grammar generates the word.

S → AB ; A → AA ; A → a ; B → BB ; B → b · w = bbb

Worked solution

  1. 1Length 1: {B} {B} {B}
  2. 2Length 2: {B} {B}
  3. 3Length 3: {B}
  4. 4S is not in the top cell.

Typical mistake: Check every split of the substring, not just the one in the middle.

Common questions

What is the running time of CYK?

O(n³ · |G|).

Related

More topics