1 / 16

The CYK Algorithm

The CYK Algorithm. Presented by Aalapee Patel Tyler Ondracek CS6800 Spring 2014. A Membership Problem. To determine if the given string is a member of the language defined by a context free grammar. Given a context-free grammar G and a string w G = (V, ∑ ,P , S) where

maddy
Download Presentation

The CYK Algorithm

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The CYK Algorithm Presented by Aalapee Patel Tyler Ondracek CS6800 Spring 2014

  2. A Membership Problem • To determine if the given string is a member of the language defined by a context free grammar. • Given a context-free grammar G and a string w • G = (V, ∑ ,P , S) where • V finite set of variables • ∑ (the alphabet) finite set of terminal symbols • P finite set of rules • S start symbol (distinguished element of V) Is W in the language of G?

  3. CYK Algorithm • Developed by J. Cocke D. Younger, T. Kasamito answer the membership problem • Input should be in Chomsky Normal form • A  BC • A  a • S  λ where B, C Є V – {S} • Uses bottom up parsing • Uses dynamic programming or table filling algorithm

  4. CYK Basic Idea Let u = x1x2…xn be a string to be tested for membership • Step 1: For each substring of u of length 1 find the set of variables A with a rule A -> xi,i • Step 2: for each substring of u of length 2 find the set of variables A that derives A -> xi,i+1 : • Step n: for the string x1,n find the set of variables A that derives A -> x1,n

  5. The Diagonal Table Approach Formula for filling the table: Wi,j = (Wi, i , Wi+1, j), (Wi, i+1 , Wi+2, j) …… (Wi, j-1 , Wj, j ) • Fill the table using the above formula where Wi,jis a production of the Grammar • The final row (i.e. W1,4) determines if the string w is in L(G) • If it contains the start symbol (S) then w is in L(G)

  6. CYK Table Filling Example First row is is not filled using the previous slides formula but is simply filled by whichtransition(s) contain the symbol

  7. CYK Table Filling Example Wi,j = (Wi, i , Wi+1, j), (Wi, i+1 , Wi+2, j) …… (Wi, j-1 , Wj, j) W1,2 = (W1,1, W2,2) = {A, C} {B} = {AB, CB}. What rules form AB and CB?

  8. CYK Table Filling Example Wi,j = (Wi, i , Wi+1, j), (Wi, i+1 , Wi+2, j) …… (Wi, j-1 , Wj, j ) W2,3 = (W2,2, W3,3) = {B} {B} = {BB}. What rules form BB?

  9. CYK Table Filling Example Wi,j = (Wi, i , Wi+1, j), (Wi, i+1 , Wi+2, j) …… (Wi, j-1 , Wj, j) W3,4 = (W3,3, W4,4) = {B} {A} = {BA}. What rules form BA?

  10. CYK Table Filling Example Wi,j = (Wi, i , Wi+1, j), (Wi, i+1 , Wi+2, j) …… (Wi, j-1 , Wj, j) W1,3 = (W1,1, W2,3), (W1,2, W3,3) = {A, C} {∅} U {S, C} {B}= {A, C, SB, CB}. What rules form A, C, SB or CB?

  11. CYK Table Filling Example Wi,j = (Wi, i , Wi+1, j), (Wi, i+1 , Wi+2, j) …… (Wi, j-1 , Wj, j ) W2,4 = (W2,2, W3,4), (W2,3, W4,4) = {B} {C} U {∅} {A}= {BC, A} What rules form BC or A?

  12. CYK Table Filling Example Wi,j = (Wi, i , Wi+1, j), (Wi, i+1 , Wi+2, j) …… (Wi, j-1 , Wj, j) W1,4 = (W1,1, W2,4), (W1,2, W3,4), (W1,3, W4,4) = {A, C} {B} U {S, C} {C} U {C} {A} = {AB, CB, SC, CC, CA} What rules form AB, CB, SC, CC or CA?

  13. CYK Table Filling Example • The string w is in the language • Since W1,n which is W1,4 has the start symbol

  14. CYK Table Filling Example First row is is not filled using the previous slides formula but is simply filled by whichtransition(s) contain the symbol

  15. CYK Table Filling Example • S  AB | BC • A  BA | a • B  CC | b • C  AB | a First row is is not filled using the previous slides formula but is simply filled by whichtransition(s) contain the symbol

  16. References • David Rodriguez-Velazquez “The CYK Algorithm” 2009 course website • Savitha parur venkitachalam “Membership problem CYK Algorithm” 2013 course presentation • http://en.wikipedia.org/wiki/CYK_algorithm • Languages and Machines, An Introduction to the Theory of Computer Science - Thomas A. Sudkamp

More Related