# CYK Algorithm for students with 5 best and easy steps !!!

Spread this useful information with your friends if you liked.

### CYK Algorithm with 5 best and easy steps

The CYK (Cocke-Younger-Kasami) algorithm is a parsing algorithm for context-free grammar that can efficiently determine whether a given string can be derived from a particular context-free grammar.

The algorithm works by building a table of possible non-terminal symbols that can generate each subsequence of the input string.

#### Here are the steps of the CYK algorithm:

1. Given context-free grammar in Chomsky normal form (CNF) and a string of input symbols, split the input string into individual symbols.

2. Initialize a table T of size n x n, where n is the length of the input string. The entry T[i,j] in the table represents the set of non-terminal symbols that can generate the subsequence of input symbols from position i to j.

3. For each entry T[i,i] in the table, populate it with the set of non-terminal symbols that can generate the single input symbol at position i.

4. For each entry T[i,j] in the table, where i < j, compute the set of non-terminal symbols that can generate the subsequence of input symbols from i to j. This can be done by iterating over all possible k values such that i ≤ k < j, and checking whether there are any production rules A -> BC where B is in T[i,k] and C is in T[k+1,j].

5. If the start symbol S of the context-free grammar is in T[1,n], then the input string can be generated by the grammar. Otherwise, it cannot be generated.

The time complexity of the CYK algorithm is O(n^3) for a string of length n and a context-free grammar in CNF.

However, this can be improved to O(n^2 log n) using more advanced techniques such as the Earley parser.

Spread this useful information with your friends if you liked.