cs 3240: languages and computation pushdown automata & cf grammars note: these are only partial...
TRANSCRIPT
![Page 1: CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d845503460f94a6a371/html5/thumbnails/1.jpg)
CS 3240: Languages and Computation
Pushdown Automata & CF GrammarsNOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10 . PLEASE REFER TO THE TEXTBOOK FOR COMPLETE COVERAGE
![Page 2: CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d845503460f94a6a371/html5/thumbnails/2.jpg)
Project 1
![Page 3: CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d845503460f94a6a371/html5/thumbnails/3.jpg)
Pushdown Automata
Similar to finite automata, but for CFG’s Finite automata are not adequate for CFG’s
because we cannot keep track of what we’ve doneAt any point, we only know the current state, not
previous states Need memory
PDA’s are finite automata with a stack
![Page 4: CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d845503460f94a6a371/html5/thumbnails/4.jpg)
FA and PDA Schematics
State control
a a b b
State control
a a b b
xyz
FA
PDA
Stack: Infinite LIFO (last in first out) device
![Page 5: CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d845503460f94a6a371/html5/thumbnails/5.jpg)
Formal Definition of PDA
A pushdown automaton is a 6-tuple (Q, Σ, , , q0, F), where Q, Σ, , and F are all finite sets, and Q is the set of states Σ is the set of input alphabet is the stack alphabet :Q×Σ× ,P(Q×) is the transition function q0 is the start state and FQ is the set of accept states
![Page 6: CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d845503460f94a6a371/html5/thumbnails/6.jpg)
How does PDA work?
Start in start state Read input character, perform state transition
and update stack Clone a machine if multiple transitions are
possible At end of input if any machine accepts and the
stack is empty then accept
![Page 7: CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d845503460f94a6a371/html5/thumbnails/7.jpg)
Example
read 0 & push 0 on stack
read ε & push ε on stack
read ε & push $ on stack
read 1 & pop 0 off stack
read ε & pop $ off stack
Language accepted: {0n1n | n 0}
![Page 8: CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d845503460f94a6a371/html5/thumbnails/8.jpg)
Example
Read (()())
qstart qacceptε, ε S$ ε, $ ε
(,(ε
),)ε
ε,SSS
ε,S(S)
ε,S()S$
qloop
![Page 9: CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d845503460f94a6a371/html5/thumbnails/9.jpg)
Example
Read (()())
qstart qacceptε, ε S$ ε, $ ε
(,(ε
),)ε
ε,SSS
ε,S(S)
ε,S()
qloop
(S)$
![Page 10: CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d845503460f94a6a371/html5/thumbnails/10.jpg)
Example
Read (()())
qstart qacceptε, ε S$ ε, $ ε
(,(ε
),)ε
ε,SSS
ε,S(S)
ε,S()
qloop
S)$
(
![Page 11: CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d845503460f94a6a371/html5/thumbnails/11.jpg)
Example
Read (()())
qstart qacceptε, ε S$ ε, $ ε
(,(ε
),)ε
ε,SSS
ε,S(S)
ε,S()
qloop
SS)$
(
![Page 12: CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d845503460f94a6a371/html5/thumbnails/12.jpg)
Example
Read (()())
qstart qacceptε, ε S$ ε, $ ε
(,(ε
),)ε
ε,SSS
ε,S(S)
ε,S()
qloop
()S)$
(
![Page 13: CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d845503460f94a6a371/html5/thumbnails/13.jpg)
Example
Read (()())
qstart qacceptε, ε S$ ε, $ ε
(,(ε
),)ε
ε,SSS
ε,S(S)
ε,S()
qloop
)S)$
((
![Page 14: CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d845503460f94a6a371/html5/thumbnails/14.jpg)
Example
Read (()())
qstart qacceptε, ε S$ ε, $ ε
(,(ε
),)ε
ε,SSS
ε,S(S)
ε,S()
qloop
S)$
(()
![Page 15: CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d845503460f94a6a371/html5/thumbnails/15.jpg)
Example
Read (()())
qstart qacceptε, ε S$ ε, $ ε
(,(ε
),)ε
ε,SSS
ε,S(S)
ε,S()
qloop
())$
(()
![Page 16: CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d845503460f94a6a371/html5/thumbnails/16.jpg)
Example
Read (()())
qstart qacceptε, ε S$ ε, $ ε
(,(ε
),)ε
ε,SSS
ε,S(S)
ε,S()
qloop
))$
(()(
![Page 17: CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d845503460f94a6a371/html5/thumbnails/17.jpg)
Example
Read (()())
qstart qacceptε, ε S$ ε, $ ε
(,(ε
),)ε
ε,SSS
ε,S(S)
ε,S()
qloop
)$
(()()
![Page 18: CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d845503460f94a6a371/html5/thumbnails/18.jpg)
Example
Read (()())
qstart qacceptε, ε S$ ε, $ ε
(,(ε
),)ε
ε,SSS
ε,S(S)
ε,S()
qloop
$
(()())
![Page 19: CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d845503460f94a6a371/html5/thumbnails/19.jpg)
Example
Read (()())
qstartε, ε S$ ε, $ ε
(,(ε
),)ε
ε,SSS
ε,S(S)
ε,S()
qloop
(()())
qaccept
![Page 20: CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d845503460f94a6a371/html5/thumbnails/20.jpg)
More Examples
L= {aibjck, i=j or j=k>, and i,j,k>=0}.
L= {wwR | w in {0,1}* }
![Page 21: CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d845503460f94a6a371/html5/thumbnails/21.jpg)
Differences between PDA’s and NFA’s Transitions read one symbol of the string
and push a string onto or pop a symbol off of the stack
Stack alphabet is not necessarily the same as the alphabet for the languagee.g., $ marks bottom of stack in previous
(0n1n) example
![Page 22: CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d845503460f94a6a371/html5/thumbnails/22.jpg)
Instantaneous descriptions
![Page 23: CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d845503460f94a6a371/html5/thumbnails/23.jpg)
![Page 24: CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d845503460f94a6a371/html5/thumbnails/24.jpg)
Equivalence of pda and cfg
![Page 25: CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d845503460f94a6a371/html5/thumbnails/25.jpg)
Equivalence of PDA’s and CFG’s
Theorem: A language is context free if and only if some pushdown automaton accepts it by e.s.
Proved in two lemmas – one for the “if” direction and one for the “only if” direction
We will only do the “only if” step – i.e., show that every context-free language has an associated PDA
![Page 26: CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d845503460f94a6a371/html5/thumbnails/26.jpg)
CFG’s are recognized by PDA’s
Lemma: If a language is context free, then some pushdown automaton accepts it by emp.st.
Proof idea: Construct a PDA following CFG rules
![Page 27: CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d845503460f94a6a371/html5/thumbnails/27.jpg)
Constructing the PDA
You can read any symbol in when that symbol is at the top of the stack Transitions of the form a,aε
The rules will be pushed onto the stack – when a variable A is on top of the stack and there is a rule Aw, you pop A and push w
You accept only if the input is exhausted and the stack is empty
![Page 28: CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d845503460f94a6a371/html5/thumbnails/28.jpg)
Idea of PDA construction for AxBz
State control
a b
At
State control
a b
xBzt
![Page 29: CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d845503460f94a6a371/html5/thumbnails/29.jpg)
Given G build PDA
![Page 30: CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d845503460f94a6a371/html5/thumbnails/30.jpg)
![Page 31: CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d845503460f94a6a371/html5/thumbnails/31.jpg)
Deterministic PDA
![Page 32: CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d845503460f94a6a371/html5/thumbnails/32.jpg)
![Page 33: CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d845503460f94a6a371/html5/thumbnails/33.jpg)