The Cocke-Younger-Kasami (CYK) algorithm is used for parsing strings based on a given context-free grammar, typically one in Chomsky Normal Form (CNF). It uses dynamic programming to determine if a string can be generated by the grammar.
The core data structure in CYK is a table, often called the 'P' table or a DP table. This table stores information about which non-terminal symbols can generate substrings of the input sentence.
The space complexity is determined by the size of this P table.
Space = (Number of Substrings) $\times$ (Max Symbols per Substring)
Space = $O(n^2) \times O(m)$
Space = $O(n^2m)$
Therefore, the space complexity of the CYK algorithm for the P table is $O(n^2m)$.
| LIST-I Grammar | LIST-II All productions are of the form |
|---|---|
| A. Regular Grammar | I. $A \to aX$, where $a \in T$ and $X \in V^*$ |
| B. Unrestricted Grammar | II. $A \to xB$, $A \to x$ or $A \to Bx$, $A \to x$ where $A, B \in V$ and $x \in T^*$ |
| C. Chomsky Normal Form | III. $x \to y$, where $x \in (V \cup T)^+$ and $y \in (V \cup T)^*$ |
| D. Greibach Normal Form | IV. $A \to BC$ or $A \to a$, where A, B, C are in V and a is in T. |