All Exams Test series for 1 year @ ₹349 only
Question

What is the space complexity of the CYK algorithm for the P table, where n is the number of words in the sentence and m is the number of non terminal symbols in the grammar?

The correct answer is
$O(n^2m)$

CYK Algorithm Space Complexity Analysis

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.

Understanding the P Table

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 table is typically indexed based on the start and end positions of substrings within the sentence.
  • Let the input sentence have n words.
  • The table effectively stores results for all possible contiguous substrings.
  • A common representation uses dimensions related to the sentence length. For a sentence of length n, there are $O(n^2)$ possible substrings.
  • Each cell in the table (or associated with a specific substring) stores a set of non-terminal symbols.
  • Let m be the number of non-terminal symbols in the grammar. In the worst case, a single cell might need to store all m non-terminals.

Calculating Space Complexity

The space complexity is determined by the size of this P table.

  1. Number of Substrings: There are $O(n^2)$ possible contiguous substrings in a sentence of length n. For example, substrings of length 1, length 2, ..., length n.
  2. Information per Substring: For each substring, the algorithm stores the set of non-terminals that can derive it. The maximum size of this set is m (the total number of non-terminals).
  3. Total Space: The total space required is the product of the number of substrings and the maximum space needed per substring.

    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)$.

Was this answer helpful?

Important Questions from Context Free Grammars - Teaching

  1. Match the LIST-I with LIST-II
    LIST-I GrammarLIST-II All productions are of the form
    A. Regular GrammarI. $A \to aX$, where $a \in T$ and $X \in V^*$
    B. Unrestricted GrammarII. $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 FormIII. $x \to y$, where $x \in (V \cup T)^+$ and $y \in (V \cup T)^*$
    D. Greibach Normal FormIV. $A \to BC$ or $A \to a$, where A, B, C are in V and a is in T.
Need Expert Advice?

Start Your Preparation with Prepp Mobile App

Download the app from Google Play & App Store
Download the app from Google Play & App Store
Prepp Mobile App