CYK Algorithm
CYK Algorithm
Question:
Is w in L(G)?
X4, 5 X4, 4
w4
X5, 5
w5
X4, 5 X4, 4
w4
X5, 5
w5
{B}
b
{A, C}
a
{A, C}
a
{B}
b
{A, C}
a
{S, A} {B}
b
{A, C}
a
{A, C}
a
{B}
b
{A, C}
a
{S, A} {B}
b
{B} {A, C}
a
{A, C}
a
{B}
b
{A, C}
a
{S, A} {B}
b
{B} {A, C}
a
{S, C} {A, C}
a
{B}
b
{A, C}
a
{S, A} {B}
b
{B} {A, C}
a
{S, C} {A, C}
a
{S, A} {B}
b
{A, C}
a
{B}{B} U {S, A}{A, C}= {BB, SA, SC, AA, AC} = Y Steps:
Look for production rules to generate Y S AB | BC There are NONE: S and A A BA | a B CC | b X1 , 3 = C AB | a no elements in this set (empty set)
{S, A} {B}
b
{B} {A, C}
a
{S, C} {A, C}
a
{S, A} {B}
b
{A, C}
a
{S, A} {B}
b
{S, C} {A, C}
a
{S, A} {B}
b
{A, C}
a
{A,C}{S,A} U {S,C}{A,C} = {AS, AA, CS, CA, SA, SC, CA, CC} = Y Steps:
Look for production rules to generate Y There is one: B X3 , 5 = {B}
S AB | BC A BA | a B CC | b C AB | a
{S, A} {B}
b
{S, A} {B}
b
{A, C}
a
{S, A} {B}
b
{A, C}
a
- Table for string w that has length 5 - The algorithm populates the triangular table
Example (Result)
Is baaba in L(G)? Yes We can see the S in the set X1n where n = 5 We can see the table the cell X15 = (S, A, C) then if S X15 then baaba L(G)
Theorem
The CYK Algorithm correctly computes X i j for all i and j; thus w is in L(G) if and only if S is in X1n. The running time of the algorithm is O(n3).
References
J. E. Hopcroft, R. Motwani, J. D. Ullman, Introduction to Automata Theory, Languages and Computation, Second Edition, Addison Wesley, 2001 T.A. Sudkamp, An Introduction to the Theory of Computer Science Languages and Machines, Third Edition, Addison Wesley, 2006
Question
Show the CYK Algorithm with the following example:
CNF grammar G
S AB | BC A BA | a B CC | b C AB | a
Complexity O(n3)