0% found this document useful (0 votes)
8 views

Lecture 13-15

Uploaded by

f20210563
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Lecture 13-15

Uploaded by

f20210563
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 40

Theory of Computation

(CS F351)
BITS Dr. Raghunath
CS&IS Dept.
Pilani
Hyderabad Campus

BITS Pilani, Hyderabad Campus


Lecture: 13-15
Closure properties of CFLs and
BITS
Dr. Raghunath Reddy
Pilani Pushdown automata
Hyderabad Campus

BITS Pilani, Hyderabad Campus


Closure properties of CFLs
 Theorem: Let and be two context-free languages. Then
 is context-free

 is context-free

 is context-free
Closure properties of CFLs
 Theorem: Let be a context-free language then is also
context-free.

If L is a CFL with grammar G, form a grammar for by reversing the right


side of every production.
Closure properties of CFLs
 Theorem: Let and be two context-free languages. Then
 is need not be context-free

 is need not be context-free.


Pushdown automata
Pushdown automata
 A pushdown automata is a system where

 is a finite set of states;

 is an alphabet, called input alphabet;

 is an alphabet, called the stack alphabet;

 in is the initial state;

 is a particular stack symbol called the start symbol;

 is the set of final states;

 is a mapping from to finite subsets of


Pushdown automata
 Moves:
Instantaneous description (ID)
 The ID records
 the state and stack contents.
 Unexpanded input

 ID :

 If is a PDA, we say if contains .

 We use for reflexive and transitive closure of .



Accepted strings and languages
Pushdown automata

 Example: PDA for


Pushdown automata

 Example: PDA for


Pushdown automata

 Example: PDA for


Accepted languages (revisited)
 For a PDA we define

 , a language is accepted by final state to be

 a language accepted by empty stack to be


Accepted languages (revisited)
Accepted languages (revisited)
Pushdown automata

 Example: PDA for


Deterministic Pushdown automata
Non-deterministic Pushdown automata

 Example: PDA for


PDAs and CFGs

 Theorem: The class of languages accepted by pushdown


automata is exactly the class of context-free languages.
CFG PDA
 Lemma: Each context-free language is accepted by some pushdown
automata.

 Proof: Let be a CFG, we must construct a PDA such that .


CSF363 BITS Pilani, Hyderabad Campus
CFG PDA
 Example: and productions are
PDA CFG
 Lemma: If a language is accepted by a pushdown
automata, then it is a context-free language.

 Proof: Let be a language accepted by a pushdown


automata .

 Assume that satisfy the following properties:


 It has a single accepting/final state
 Empties its stack before accepting
 Each transition is either a push, or a pop, but not
both.
PDA CFG
 Proof Cont..

 We construct a CFG given by


PDA CFG
PDA CFG
 Example:
PDA CFG
 Example:
Pumping Lemma for CFLs
 Statement: If is a context-free language, then there is a number
(the pumping length) where, if is any string in with , then can be
written as satisfying the conditions

 Proof:
 Let be a CFG such that
 Let be the maximum number of symbols in the right-hand side of
a rule / production in .
 If the height of the parse tree is at most then the length of the
string generated is at most .
Pumping Lemma for CFLs (cont..)
 Conversely, if a generated string is at least long, each of its parse trees
must be at least high.

 Set .
 If its parse tree must be at least high, because .

 Let be the parse tree of that has the small number of nodes.
 The height of is at least .
 So, it must contain a path from the root to a leaf of length at
least .
 That path has at least nodes; one at a terminal (leaf node) and
variables.
 Some variable appears more than once on the path.
Pumping Lemma for CFLs (cont..)
 Condition 1:

 Condition 2:
Pumping Lemma for CFLs (cont..)
 Condition 3: .

 In the parse tree for the upper occurrence of generates .

 Choose so that both occurrences fall within the bottom


variables on the path and choose the longest path in the parse
tree.

 So, the subtree where generates is at most high.

 A tree of this height can generate a string of length at most


Proving a language is not context free
Proving a language is not context free
 Example: Prove that is not context free.
Proving a language is not context free
 Example: Prove that is not context free.
Proving a language is not context free
 Example: Prove that is not context free.
Closure properties of CFLs
 Theorem: Let and be two context-free languages. Then
 is context-free

 Already proved

 is context-free

 Already proved

 is context-free
 Already proved
Closure properties of CFLs
 Theorem: Let be a context-free language then is also
context-free.

 Already proved
Closure properties of CFLs
 Theorem: Let and be two context-free languages. Then
 is need not be context-free

 is need not be context-free.


Thank you

BITS Pilani, Hyderabad Campus

You might also like