• Save
Theory of Computation: Lecture 38
Upcoming SlideShare
Loading in...5
×
 

Theory of Computation: Lecture 38

on

  • 1,305 views

1) CFL Membership

1) CFL Membership
2) Cocke-Younger-Kasami (CYK) Algorithm
3) Class home page is at http://vkedco.blogspot.com/2011/08/theory-of-computation-home.html

Statistics

Views

Total Views
1,305
Views on SlideShare
754
Embed Views
551

Actions

Likes
0
Downloads
0
Comments
0

36 Embeds 551

http://vkedco.blogspot.com 376
http://www.vkedco.blogspot.com 60
http://vkedco.blogspot.in 30
http://vkedco.blogspot.sk 7
http://vkedco.blogspot.com.au 7
http://vkedco.blogspot.mx 6
http://vkedco.blogspot.ca 6
http://vkedco.blogspot.com.es 5
http://vkedco.blogspot.pt 4
http://vkedco.blogspot.com.ar 4
http://vkedco.blogspot.dk 3
http://vkedco.blogspot.co.at 3
http://vkedco.blogspot.de 3
http://www.vkedco.blogspot.kr 3
http://vkedco.blogspot.com.br 3
http://vkedco.blogspot.se 3
http://vkedco.blogspot.com.tr 3
http://vkedco.blogspot.gr 2
http://www.vkedco.blogspot.tw 2
http://vkedco.blogspot.co.uk 2
http://vkedco.blogspot.co.il 2
http://vkedco.blogspot.fr 2
http://www.vkedco.blogspot.co.uk 2
http://www.vkedco.blogspot.de 1
http://vkedco.blogspot.kr 1
http://vkedco.blogspot.ru 1
http://www.vkedco.blogspot.sg 1
http://vkedco.blogspot.cz 1
http://vkedco.blogspot.co.nz 1
http://translate.googleusercontent.com 1
http://vkedco.blogspot.hu 1
http://vkedco.blogspot.no 1
http://vkedco.blogspot.ro 1
http://vkedco.blogspot.ch 1
http://vkedco.blogspot.jp 1
http://vkedco.blogspot.it 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Theory of Computation: Lecture 38 Theory of Computation: Lecture 38 Presentation Transcript

    • CS 5000: Theory of Computation Lecture 38 Vladimir Kulyukin Department of Computer Science Utah State Universitywww.youtube.com/vkedco
    • Outline ● Review ● CFL Membership ● Cocke-Younger-Kasami (CYK) Algorithmwww.youtube.com/vkedco
    • Review: Regular Languages & Stack Machines ● We can construct an FA for a regular language ● We can construct a regular grammar from an NFA ● Regular grammars are context-free grammars ● It is no surprise that we can construct stack machines from finite automatawww.youtube.com/vkedco
    • Review: Converting CFG To Stack Machine Theorem : If G = (V , Σ , S , P ) is a CFG, there is a stack machine M such that L( G ) = L( M ). Proof Sketch : M = (V ∪ Σ ,Σ , S , δ ) , where δ is defined as follows : 1. for all v ∈ V , δ ( ε , v ) = { x | ( v → x ) ∈ P}; 2. for all a ∈ Σ , δ ( a, a ) = {ε }.www.youtube.com/vkedco
    • Review: Useless Symbols ● A symbol X is useful if there is a derivation S * αXβ * w for some α, β in (V U T)* and w is in T* ● A symbol X is useless if there is no such derivationwww.youtube.com/vkedco
    • Review: Elimination of Useless Symbols Every non - empty CFL is generated by a CFG with no useless symbolswww.youtube.com/vkedco
    • Review: Chomsky Normal Form A CFG is said to be in Chomsky Normal form if all of its productions are of the two forms : 1) A → BC ; 2) A → a; where A, B, C are variables and a is a terminal.www.youtube.com/vkedco
    • Review: CNF Theorem Let G be a grammar with no useless symbols and no ε- productions. There is a CNF grammar G’ such that L(G) = L(G’).www.youtube.com/vkedco
    • CFL Membership and CYK Algorithmwww.youtube.com/vkedco
    • CFL Membership ● Problem: Given a CFG G = (V, T, P, S) and a string x in T*, determine if x is in L(G)? ● Cocke-Younger-Kasami (CYK) algorithm takes a CFG in CNF and a string and returns true or false, depending on whether x is or is not in L(G) ● The CYK algorithm runs in O(n3), where |x|=nwww.youtube.com/vkedco
    • CYK Algorithm: Basic Insight A * xij iff A  BC, A B * xik, and C * x(i+k)(j-k), for B C some k, 1 ≤ k < j i i+k-1 i+k i+j j-k k Xijwww.youtube.com/vkedco
    • Why Does CYK Work? ● Since k and j-k are both strictly less than j, we already know whether each of the two smaller derivations exists, i.e. B * xik and C * x(i+k)(j-k) ● When we reach j=n, we can determine if S*x1nwww.youtube.com/vkedco
    • CYK Algorithm: String Partition ● The input is a CNF grammar G with no ε-productions and a string x such that |x| ≥ 1 ● Let xij be the substring of x of length j beginning at position i ● For example, if x = aabbabb, then x13 = aab and x24 = abba ● Since |x| = n, 1≤ i ≤ n and 1≤ j ≤ n ● In general, if we do 1-based array index counting, i.e., the first position in an array is 1, not 0, and the length of the substring is j, the last available position i at which the substring can begin is n–j+1 ● For example, if |x| = 4 and j = 2, the possible values for i in xi2 are 1, 2, and 3 = 4 – 2 + 1www.youtube.com/vkedco
    • CYK Algorithm: Pseudocode CYK(string x, CNFGrammar G) { create a n x n table V, where n = |x|; for i from 1 upto n { V[i, 1] = {A | A → a is in G and a is the i-th symbol of x}; } for j from 2 upto n { for i from 1 upto n – j + 1 { V[i, j] = { }; for k from 1 upto j – 1 { V[i, j] = V[i, j] U {A | A → BC is a production in G and B is in V[i, k] and C is in V[i+k, j-k]}; } } } if ( S is in V[1, n] ) return true; else return false; }www.youtube.com/vkedco
    • CYK Algorithm: Initialization ● Let xij be the substring of x of length j beginning at position i ● If j = 1, then, for each 1≤ i ≤ n, we can check if xi1 can be derived directly from some variable V of G ● This can be determined by checking if G has a production V  xi1www.youtube.com/vkedco
    • CYK Example • Assume that our CNF grammar is as follows: 1. SAB | BC 2. ABA | a 3. BCC | b 4. CAB | a • Assume that our input x = baabawww.youtube.com/vkedco
    • 5 x 5 Table V[i, j] i 1 2 3 4 5 1 2 j 3 4 5www.youtube.com/vkedco
    • What is V[i, j]? V[i, j] is the set of all variables in G that derive the substring xij of the input string x, i.e. the substring that start at postion i and is of length jwww.youtube.com/vkedco
    • Computing V[1,1] ● The input is baaba ● The first symbol of the input is b ● We need to set V[1,1] to {A | Ab}, where A is in V, i.e. the set of variables of the grammar ● There is only one production that qualifies: Bb ● So V[1,1] = {B}www.youtube.com/vkedco
    • Computing V[1,1] i 1 2 3 4 5 {B} 1 2 j 3 4 5www.youtube.com/vkedco
    • Computing V[2,1] ● The input is baaba ● The second symbol of the input is a ● We compute {A | Aa}, where A is in V ● There are two such productions: Aa, Ca ● So V[2, 1] = {A,C}www.youtube.com/vkedco
    • Computing V[2,1] i 1 2 3 4 5 {B} {A,C} 1 2 j 3 4 5www.youtube.com/vkedco
    • Computing V[3,1] ● The input is baaba ● The third symbol is a ● We need to find productions of the form Aa, where A is in V ● There are two productions: Aa, Ca ● So V[3,1] = {A,C}www.youtube.com/vkedco
    • Computing V[3,1] i 1 2 3 4 5 {B} {A, C} {A, C} 1 2 j 3 4 5www.youtube.com/vkedco
    • Computing V[4,1] ● The input is baaba ● The fourth symbol is b ● We need to find productions of the form Ab, where A is in V ● There is only one production: Bb ● So V[4,1] = {B}www.youtube.com/vkedco
    • Computing V[4,1] i 1 2 3 4 5 {B} {A, C} {A, C} {B} 1 2 j 3 4 5www.youtube.com/vkedco
    • Computing V[5,1] ● The input is baaba ● The fifth symbol of the input is a ● We need to find productions of the form Aa, where A is in V ● There are two such productions: Aa, Ca ● So V[5,1] = {A,C}www.youtube.com/vkedco
    • Computing V[5,1] i 1 2 3 4 5 {B} {A,C} {A,C} {B} {A,C} 1 2 j 3 4 5www.youtube.com/vkedco
    • Computing V[1,2] ● We need to find k, such that 1 ≤ k < 2 and look for productions A  BC where B is in V[1,1] and C is in V[2,1] ● Since V[1,1] = {B} and V[2,1] = {A, C}, the possibilities for the right-hand sides are BA, BC ● The rules that match these possibilities are SBA | BC and ABA ● So V[1,2] = {S,A}www.youtube.com/vkedco
    • Computing V[1,2] i 1 2 3 4 5 {B} {A,C} {A,C} {B} {A,C} 1 2 {S,A} j 3 4 5www.youtube.com/vkedco
    • Computing V[2,2] ● We need to find k, such that 1 ≤ k < 2, and the rules ABC, where B is in V[2,1] and C is in V[3,1] ● Since V[2,1] = {A,C} = V[3,1] = {A,C}, the right-hand side possibilities are AA, AC, CA, CC ● There is only one rule that qualifies: B  CC ● So V[2,2] = {B}www.youtube.com/vkedco
    • Computing V[2,2] i 1 2 3 4 5 {B} {A,C} {A,C} {B} {A,C} 1 2 {S,A} {B} j 3 4 5www.youtube.com/vkedco
    • Computing V[3,2] ● We look for k, such that 1 ≤ k < 2 and rules of the form A  BC, where B is in V[3,1] and C is in V[4,1] ● V[3,1] = {A,C} and V[4,1] = {B} ● So the right-hand side possibilities are AB, CB ● The rules that match these possibilities are: S  AB and C  AB ● So V[3,2] = {S,C}www.youtube.com/vkedco
    • Computing V[3,2] i 1 2 3 4 5 {B} {A,C} {A,C} {B} {A,C} 1 2 {S,A} {B} {S,C} j 3 4 5www.youtube.com/vkedco
    • Computing V[4,2] ● We look for k, such that 1 ≤ k < 2 and rules of the form A  BC, where B is V[4,1] and C is in V[5,1] ● V[4,1] = {B}; V[5,1] = {A,C} ● So the right-hand side possibilities are BA and BC ● The rules that match these possibilities are: S  BC and A  BA ● So V[4,2] = {S,A}www.youtube.com/vkedco
    • Computing V[4,2] i 1 2 3 4 5 {B} {A,C} {A,C} {B} {A,C} 1 2 {S,A} {B} {S,C} {S,A} j 3 4 5www.youtube.com/vkedco
    • Computing V[1,3] ● We look for k, such that 1 ≤ k < 3 and rules of the form A  BC, where, if k = 1, B is in V[1,1] and C is in V[2,2] or where, if k = 2, B is in V[1,2] and C is in V[3,1] ● For k = 1, V[1,1] = {B} and V[2,2] = {B} ● So there is only one right-hand side possibility: BB ● The grammar does not have any productions that match ● For k = 2, V[1,2] = {S,A} and V[3,1] = {A,C} ● So the right-hand side possibilities are: SA, SC, AA, AC ● The grammar does not have any productions that match ● So V[1,3] = { }www.youtube.com/vkedco
    • Computing V[1,3] i 1 2 3 4 5 {B} {A,C} {A,C} {B} {A,C} 1 2 {S,A} {B} {S,C} {S,A} j 3 {} 4 5www.youtube.com/vkedco
    • Computing V[2,3] ● We look for k, such that 1 ≤ k < 3 and rules of the form A  BC, where, if k = 1, B is in V[2,1] and C is in V[3,2] or where, if k = 2, B is in V[2,2] and C is in V[4,1] ● For k = 1, V[2,1] = {A,C} and V[3,2] = {S,C} ● The possibilities are: AS, AC, CS, CC ● The rules that match are: B  CC ● For k = 2, V[2,2] = {B} and V[4,1] = {B} ● The possibilities are: BB ● No rules match ● So V[2,3] = {B}www.youtube.com/vkedco
    • Computing V[2,3] i 1 2 3 4 5 {B} {A,C} {A,C} {B} {A,C} 1 2 {S,A} {B} {S,C} {S,A} j 3 {} {B} 4 5www.youtube.com/vkedco
    • Filling in the Remainder of the Table i 1 2 3 4 5 {B} {A,C} {A,C} {B} {A,C} 1 2 {S,A} {B} {S,C} {S,A} 3 {} {B} {B} j {} {S,A,C} 4 5 {S,A,C}www.youtube.com/vkedco
    • The Input baaba is Accepted Since V[1,5] contains S, we accept the input and return true.www.youtube.com/vkedco
    • References & Reading Suggestions ● Hopcroft and Ullman. Introduction to Automata Theory, Languages, and Computation, Narosa Publishing House ● Moll, Arbib, and Kfoury. An Introduction to Formal Language Theory ● Davis, Weyuker, Sigal. Computability, Complexity, and Languages, 2nd Edition, Academic Press ● Brooks Webber. Formal Language: A Practical Introduction, Franklin, Beedle & Associates, Incwww.youtube.com/vkedco
    • Feedback Errors, comments to vladimir dot kulyukin at gmail dot comwww.youtube.com/vkedco