Q88.Marks: +2.0UGC NET Paper 2: Computer Science 2nd January 2026 Shift 1
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?
1. O(n 3)
2.O(nm 2)
3.O(n 2 m)✓ Correct
4.O(n 2 m 2)
Solution
The correct answer is O(n2m).
Key Points
The CYK algorithm is a parsing algorithm for context-free grammars, often used to determine whether a given string can be generated by a grammar.
The algorithm uses a table, often called the "P table," which is a 2D array where P[i][j] stores information about the non-terminal symbols that can generate the substring from position i to j in the input string.
For a sentence of length n and a grammar with m non-terminal symbols, the space required to store this table is proportional to O(n2m).
This space complexity arises because:
There are approximately n2 entries in the table, corresponding to all substrings of the input string of different lengths.
For each entry, we may need to store information for up to m non-terminal symbols.
Step-by-Step Solution / Explanation
Step 1: Understanding the dimensions of the P table
The P table is a triangular 2D table used to store parsing information for substrings of the input string.
Given a string of length n, the table has approximately n2 entries, as it stores information for all possible substrings of the string.
Step 2: Accounting for the number of non-terminal symbols
For each table entry, the algorithm may need to store information about all the m non-terminal symbols in the grammar.
This means that the memory required for each entry is proportional to m.
Step 3: Calculating the total space complexity
The total space complexity is the product of the number of entries in the table and the space required for each entry.
Total space complexity = O(n2) * O(m) = O(n2m).
Additional Information
Time Complexity of CYK Algorithm:
The time complexity of the CYK algorithm is O(n3m), where n is the length of the input string and m is the number of non-terminal symbols in the grammar.
This arises because for each entry in the table, the algorithm may need to consider all possible splits of the substring and all combinations of non-terminal symbols.
Applications of the CYK Algorithm:
The CYK algorithm is commonly used in natural language processing and computational linguistics to parse sentences according to a given grammar.
It is also used in formal language theory and compiler design for syntax analysis of programming languages.
Limitations of the CYK Algorithm:
The algorithm requires the grammar to be in Chomsky Normal Form (CNF), which may require preprocessing to convert a given grammar into CNF.
The algorithm is not efficient for very large input strings or grammars with a large number of non-terminal symbols.