21 DynamicProgramming (HR 2016) CYK ProjDef Finalized
21 DynamicProgramming (HR 2016) CYK ProjDef Finalized
Algorithms
By
Hossein Rahmani
[email protected]
http://webpages.iust.ac.ir/h_rahmani/
1
Intro
Dynamic
Programming Sorting Hash Functions
2
Languages
3
Languages
A language is a set of strings
6
Grammars
Grammars express languages
noun boy
noun dog
verb runs
verb walks 8
A derivation of “the boy walks”:
L = { “a boy runs”,
“a boy walks”,
“the boy runs”,
“the boy walks”,
“a dog runs”,
“a dog walks”,
“the dog runs”,
“the dog walks” }
11
Notation
noun boy
noun dog
Variable Terminal
Production
or
rule
Non-terminal
12
Another Example
S aSb
Grammar: S
Derivation of sentence :
ab
S aSb ab
S aSb S
13
Grammar: S aSb
S
S aSb S
14
Other derivations:
15
Language of the grammar
S aSb
S
n n
L {a b : n 0}
16
Example
S Ab
For grammar G: A aAb
A
L(G) {???}
17
Example
S Ab
For grammar G: A aAb
A
n n
L(G ) {a b b : n 0}
n n
Since: S a b b
18
A grammar G : S aSb
S SS
S
A derivation:
() ((( ))) (( ))
20
Chomsky Normal Form
21
Noam Chomsky: The United States, Not Iran, Poses
Greatest Threat to World Peace
22
Chomsky Normal Form
All productions have form:
A BC and Aa
23
Examples:
S AS S AS
S a S AAS
A SA A SA
Ab A aa
Chomsky Not Chomsky
Normal Form Normal Form
24
The CYK Membership Algorithm
(J. Cocke, D. H. Younger, and T. Kasami)
Input:
• String w
Output:
find if w L(G )
25
Construction: Dynamic Programming
26
Construction: Dynamic Programming
27
The Algorithm
Input example:
• Grammar G : S AB
A BB
Aa
B AB
Bb
• String w : aabbb
28
aabbb
a a b b b
aa ab bb bb
aabb abbb
aabbb
29
S AB
A BB a a b b b
Aa A A B B B
B AB aa ab bb bb
Bb
aab abb bbb
aabb abbb
aabbb 30
S AB
A BB a a b b b
Aa A A B B B
B AB aa ab bb bb
Bb S,B A A
aab abb bbb
aabb abbb
aabbb 31
S AB
a a b b b
A BB
A A B B B
Aa
aa ab bb bb
B AB
S,B A A
Bb aab abb bbb
S,B A S,B
aabb abbb
A S,B
aabbb
S,B
32
Therefore: aabbb L(G )
3
Time Complexity: | w|
34
Quiz 2
35