Sie sind auf Seite 1von 7

Formal Language and Automata Theory: CS21004

15

CYK algorithm and PDA

15.1 Introduction
We begin todays lecture with an example illustrating how to develop CNF for a given CFL, and later on learn about CYK algorithm and PDA. 15.1.1 Example write the CNF of the fallowing CFL S A B

An equivalent CFL of the above CFL is as fallows: S A B D E

Hence, a CNF of the given CFL is S A B F H D E

    "!#  $"!# !#%& !    "!# '(!# !#)0!     

15.2 CYK algorithm


The Cocke-Younger-Kasami(CYK) algorithm determines whether a string can be generated by a given CFG and, if so, how it can be generated.This is known as parsing the string.The algorithm is an example of dynamic programming. It uses the grammer in CNF, since any CFG can be converted to CNF, CYK algorithm can be used to recognize any CFL. The worst case asymptotic time complexity of CYK algorithm is string. We illustrate the working of CYK algorithm with an example.

132547698

, where n is the length of parsed

Page 2 of 6

CYK algorithm and PDA

Consider the string aabaa, which can be generated by the CFG of the example 15.1.1, for simplicity, we only consider the part which determines whether a string can be generated by a given CFG leaving the part that how it can be generated(which can easily be done as we shortly notice during the implementation of the algorithm). Consider the fallowing table, called as CYK table, which is lled as explained below:
15

S
14 25

13

A
24 35

12

S
23

34 45

F
11

B
22

A
33

F
44 55

D
a

D
a

E
b

D
a

D
a

Figure 1: CYK table for aabaa w.r.t the CFG of example 15.1.1 If we denote the contents of each in the gure by , then  is the set of all non-terminals and each is a terminal of the CFG.

=  A  : A

     "!

, where 
$#&%

When we ll the CYK table subject to above conditions, it is clear that, a string is accepted iff the its CYK table contains the start symbol,S.

in

For further clarifying the working of CYK algorithm, we consider the string aabba, and see whether it can be generated by the CFG of example 15.1.1 or not, the corresponding CYK table is shown in Figure 2. Since the doesnt contain the start symbol(S), the string aabba cannot be generated by the CFG of example 15.1.1.
' #)(

15.3 PDA
A pushdown automaton(PDA) is a nite automaton that can make use of a stack containing data, it recognizes CFLs.It is more powerful machine than DFA/NFA.It also reads the input tape only once. Pushdown automaton differ from normal nite state machines in two ways: (1) They can use the top of the stack to gure out what transition to take. (2) They can manipulate the stack as part of performing a transition. A given input signal, current state, and stack symbol, can fallow a transition to another state, and an optional stack manipulation. It is a non-deterministic nite state machine known as nondeterministic pushdown automaton(NPDA). If a deterministic nite automaton is used, then it is called as deterministic pushdown automaton(DPDA), which
Satya Gautam V & Vipul K Verma Dept. of Computer Science & Engg IIT Kharagpur, India

Chapter 15: CYK algorithm and PDA

Page 3 of 6

15

14 25

13

24 35

12

23

34 45

F
11

B
22

33

A
44 55

D
a

D
a

E
b

E
b

D
a

Figure 2: CYK table for aabba w.r.t the CFG of example 15.1.1

is a strictly weaker device (unlike that of DFA and NFA which have equal power). A NPDA, can be dened as a 6-tuple: where

of the stack alphabet,

' 2 8  

is a nite transition relation (

is an element of Q the start state,

'   ! 
is a nite set of states, x x ) P( x is subset of

is a nite set of the input alphabet, ),

is a nite set

, consisting of the nal states.

There are two possible acceptence criteria: acceptance by empty stack and acceptance by nal state. The two are easily shown to be equivalent: a nite state can perform a pop loop to get to an empty stack, and a machine can detect an empty stack and enter a nal state by detecting a unique symbol pushed by the initial state. For every CFG, there exists a PDA such that the language generated by the grammer is identical with the language generated by the automaton.Conversely, for every PDA there exists a CFG such that the language generated by the automaton is identical with the language generated by the grammer.

15.4 Denition
# 

Now we formally dene a language 1. where


# 

2. Sequence of state is

3. Sequence of content of stack is 4. 5. (Start state)

" #)0# 2 #1 4 # 35 # 687 A9 @B9 93 9 C D @ ED E D53 9H@IP D5@IRQ




accepted by a PDA. Let

# $&%
 

is accepted by

8 2(' 0

,where
#



where

D FG%

IIT Kharagpur, India

(Initially stack is empty)

Satya Gautam V & Vipul K Verma

Dept. of Computer Science & Engg

Page 4 of 6

CYK algorithm and PDA

6.

9H3 '


Computation of machine

8 2(' 0

goes as follows:

Figure 3: State Transition The denition of transition function


2(9 98 62(9 8 D ED F87 C7


# 

of PDA

2 &8

is given as follows:

%

The language over 15.4.1 Example Construct an

decided by the PDA

' 0

accepting language

2 &8 % " 2 8! # F% # " 4


,
%  

is accepted by



! 

The state transition diagram and state transition function of PDA accepting above language  "!$#  "!&% and

"

are shown in

Figure 4: State Transition Diagram of PDA

Satya Gautam V & Vipul K Verma

Dept. of Computer Science & Engg

IIT Kharagpur, India

Chapter 15: CYK algorithm and PDA

Page 5 of 6

Figure 5: State Transition Function of PDA

15.5 Claim
Let

Any context free language

"

be a context free language

2 '"8 ' 2 "8

is accepted by a PDA. without




Q "

.So there is a CFG in Chomsky normal form.

The equivalent PDA accepting context free language(CFL) a string.

"

will simulate the left most derivation of

15.5.1 Example Let we have a grammer


 % ! "

Chomsky normal form of above grammer is as follows:

 !

The state transition diagram of PDA accepting above context free grammer is as follows: Let the input string be

2 '8



2 ' 8

in chomsky normal form

The derivation of string will be as follows:


Dept. of Computer Science & Engg IIT Kharagpur, India

Satya Gautam V & Vipul K Verma

Page 6 of 6

CYK algorithm and PDA

Figure 6: State Transition Diagram of PDA

$% $ $ !# $  $ $  $ 


During left most derivation of string

 

,the graph of Stack Content vs. Time will be as follows:

Satya Gautam V & Vipul K Verma

Dept. of Computer Science & Engg

IIT Kharagpur, India

Chapter 15: CYK algorithm and PDA

Page 7 of 6

Figure 7: Stack Content with respect to time

Satya Gautam V & Vipul K Verma

Dept. of Computer Science & Engg

IIT Kharagpur, India

Das könnte Ihnen auch gefallen