Vous êtes sur la page 1sur 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

## 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

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 an element of Q the start state,

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

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



# \$&%
 

is accepted by

8 2(' 0

,where
#



where

D FG%

Page 4 of 6

## CYK algorithm and PDA

6.

9H3 '


Computation of machine

8 2(' 0

goes as follows:

## 2(9 98 62(9 8 D ED F87 C7

# 

of PDA

2 &8

is given as follows:

%

## 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

Page 5 of 6

15.5 Claim
Let

"



Q "

"

 % ! "

## 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

## The derivation of string will be as follows:

Dept. of Computer Science & Engg IIT Kharagpur, India

Page 6 of 6

 

Page 7 of 6