16
Membership problem CYK Algorithm Project presentation CS 5800 Spring 2013 Professor : Dr. Elise de Doncker Presented by : Savitha parur venkitachalam

Membership problem CYK Algorithm Project presentation CS 5800 Spring 2013 Professor : Dr. Elise de Doncker Presented by : Savitha parur venkitachalam

Embed Size (px)

Citation preview

Page 1: Membership problem CYK Algorithm Project presentation CS 5800 Spring 2013 Professor : Dr. Elise de Doncker Presented by : Savitha parur venkitachalam

Membership problem CYK AlgorithmProject presentation CS 5800 Spring 2013Professor : Dr. Elise de DonckerPresented by : Savitha parur venkitachalam

Page 2: Membership problem CYK Algorithm Project presentation CS 5800 Spring 2013 Professor : Dr. Elise de Doncker Presented by : Savitha parur venkitachalam

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)• V and ∑ are assumed to be disjoint

Is W in the language of G?

Page 3: Membership problem CYK Algorithm Project presentation CS 5800 Spring 2013 Professor : Dr. Elise de Doncker Presented by : Savitha parur venkitachalam

CYK Algorithm• Developed by J. Cocke D. Younger, T. Kasami to 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 • Complexity - O(n3)

Page 4: Membership problem CYK Algorithm Project presentation CS 5800 Spring 2013 Professor : Dr. Elise de Doncker Presented by : Savitha parur venkitachalam

CYK basic Ideas• CYK works on two basic ideas

1 . Consider rules satisfying substrings of length from 1 to N Let the string to search be abca First consider substring of length 1 – a , b , c, a Next step length 2– ab , bc , ca Next step length 3– abc , bca Final length 4 – abca

Page 5: Membership problem CYK Algorithm Project presentation CS 5800 Spring 2013 Professor : Dr. Elise de Doncker Presented by : Savitha parur venkitachalam

CYK basic ideas 2. longer substrings can be parsed from parsing shorter ones

Eg: abc can be split as a . bc or ab . cif we know rules to form a and bc (or ab and c) then we know the rules to form abc A substring can be given as

Si,j = (Si, i , Si+1, j ), (Si, i+1 , Si+2, j ) … (Si, j-1 , Sj, j )

i – start index and j- end index

bcd can be formed from abcd as S2,4 = (S2,2 , S3,4) , (S2,3 , S4,4) = (b . cd) , (bc . d)

Page 6: Membership problem CYK Algorithm Project presentation CS 5800 Spring 2013 Professor : Dr. Elise de Doncker Presented by : Savitha parur venkitachalam

CYK table filling • Wi,j = (Wi, i , Wi+1, j ), (Wi, i+1 , Wi+2, j ) …… (Wi, j-1 , Wj, j )• Fill the table with the rules satisfying the substrings • If the final box contains the start symbol then the string is

a member of the language

W 1,4

W 1,3 W 2,4

W 1,2 W 2,3 W 3,4

W 1,1 W2,2 W 3,3 W 4,4

W1 W2 W3 W4

Page 7: Membership problem CYK Algorithm Project presentation CS 5800 Spring 2013 Professor : Dr. Elise de Doncker Presented by : Savitha parur venkitachalam

Table filling example

c b b a

W 1,4

W 1,3 W 2,4

W 1,2 W 2,3 W 3,4

{A , C} {B} {B} {A}

Search string ‘cbba’

Page 8: Membership problem CYK Algorithm Project presentation CS 5800 Spring 2013 Professor : Dr. Elise de Doncker Presented by : Savitha parur venkitachalam

• To fill the next row of the table consider Wi,j = (Wi, i , Wi+1, j ), (Wi, i+1 , Wi+2, j ) …… (Wi, j-1 , Wj, j )

W 1,2 = (W1,1 , W2,2) = {A,C} {B} = {AB , CB}

Rules to form AB or CB = {S, C} W 2,3 = (W2,2 , W3,3) = {B} {B} = {B B}

Rules to form BB = ∅ W 3,4 = (W3,3 , W4,4) = {B} {A} = {B A}

Rules to form BA = {C }

W 1,2 W 2,3 W 3,4

{A , C} {B} {B} {A}

Page 9: Membership problem CYK Algorithm Project presentation CS 5800 Spring 2013 Professor : Dr. Elise de Doncker Presented by : Savitha parur venkitachalam

W 1,4

W 1,3 W 2,4

{S,C} ∅ {C}

{A , C} {B} {B} {A}

Table :

Page 10: Membership problem CYK Algorithm Project presentation CS 5800 Spring 2013 Professor : Dr. Elise de Doncker Presented by : Savitha parur venkitachalam

W 1,3 W 2,4

{S,C} ∅ {C}

{A , C} {B} {B} {A}

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} Rules to form A or C or SB or CB = {C} W2,4 = (W2,2 , W3, 4 ), (W2, 3 , W4, 4 ) = {B} {C} U {A}= { BC, A} Rules to form BC or A = {B}

Page 11: Membership problem CYK Algorithm Project presentation CS 5800 Spring 2013 Professor : Dr. Elise de Doncker Presented by : Savitha parur venkitachalam

W 1,4

{C} {B}

{S,C} ∅ {C}

{A , C} {B} {B} {A}

Table :

Page 12: Membership problem CYK Algorithm Project presentation CS 5800 Spring 2013 Professor : Dr. Elise de Doncker Presented by : Savitha parur venkitachalam

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} Rules to form AB or CB or SC or CC or CA = {S,C,A}

W1,4

{C} {B}

{S,C} ∅ {C}

{A , C} {B} {B} {A}

Page 13: Membership problem CYK Algorithm Project presentation CS 5800 Spring 2013 Professor : Dr. Elise de Doncker Presented by : Savitha parur venkitachalam

{S , C , A }

{C} {B}

{S,C} ∅ {C}

{A , C} {B} {B} {A}

Final Table :The first cell represents the original string and contains the start symbol ‘S’ . Result :‘cbba’ is a member of the language.

Page 14: Membership problem CYK Algorithm Project presentation CS 5800 Spring 2013 Professor : Dr. Elise de Doncker Presented by : Savitha parur venkitachalam

Design • Read the input grammar from a file or

prompt user to input the rules • Check if the grammar is in CNF • If grammar is in CNF, start filling the table • Output :

‘String is a member of the input grammar’ Or ‘String is not a member of the input grammar’

Page 15: Membership problem CYK Algorithm Project presentation CS 5800 Spring 2013 Professor : Dr. Elise de Doncker Presented by : Savitha parur venkitachalam

References• References• http://en.wikipedia.org/wiki/CYK_algorithm#Algorithm• http://www.cs.ucdavis.edu/~rogaway/classes/120/winter12/CYK.pd

f• Languages and Machines, An Introduction to the Theory of

Computer Science - Thomas A. Sudkamp• “Parsing” Internet: http://qntm.org/top• http://en.wikipedia.org/wiki/Parsing• http://en.wikipedia.org/wiki/Dynamic_programming• http://en.wikipedia.org/wiki/Bottom-up_parsing

Page 16: Membership problem CYK Algorithm Project presentation CS 5800 Spring 2013 Professor : Dr. Elise de Doncker Presented by : Savitha parur venkitachalam

Questions