1 Module 33 Pushdown Automata (PDA’s) –Another example.

Slides:



Advertisements
Similar presentations
Pushdown Automata Section 2.2 CSC 4170 Theory of Computation.
Advertisements

Pushdown Automata CPSC 388 Ellen Walker Hiram College.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
Pushdown Automata Chapter 12. Recognizing Context-Free Languages We need a device similar to an FSM except that it needs more power. The insight: Precisely.
Pushdown Automata Part II: PDAs and CFG Chapter 12.
CFG => PDA Sipser 2 (pages ). CS 311 Fall Formally… A pushdown automaton is a sextuple M = (Q, Σ, Γ, δ, q 0, F), where – Q is a finite set.
Costas Busch - RPI1 Pushdown Automata PDAs. Costas Busch - RPI2 Pushdown Automaton -- PDA Input String Stack States.
1 Module 32 Pushdown Automata (PDA’s) –definition –example.
Theory of Computation What types of things are computable? How can we demonstrate what things are computable?
1 Module 32 Pushdown Automata (PDA’s) –definition –Example We define configurations and computations of PDA’s We define L(M) for PDA’s.
Courtesy Costas Busch - RPI1 Pushdown Automata PDAs.
Module 28 Context Free Grammars Definition of a grammar G
1 Lecture 30 Pushdown Automata (PDA’s) –definition –example.
1 Module 34 CFG --> PDA construction –Shows that for any CFL L, there exists a PDA M such that L(M) = L –The reverse is true as well, but we do not prove.
Fall 2004COMP 3351 Pushdown Automata PDAs. Fall 2004COMP 3352 Pushdown Automaton -- PDA Input String Stack States.
Fall 2006Costas Busch - RPI1 Pushdown Automata PDAs.
1 Lecture 32 CFG --> PDA construction –Shows that for any CFL L, there exists a PDA M such that L(M) = L –The reverse is true as well, but we do not prove.
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
Prof. Busch - LSU1 Pushdown Automata PDAs. Prof. Busch - LSU2 Pushdown Automaton -- PDA Input String Stack States.
Fall 2005Costas Busch - RPI1 Pushdown Automata PDAs.
1 Pushdown Automata PDAs. 2 Pushdown Automaton -- PDA Input String Stack States.
Finite State Machines Data Structures and Algorithms for Information Processing 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.
1 Dr. torng CFG → PDA construction Shows that for any CFL L, there exists a PDA M such that L(M) = L The reverse is true, but we skip the proof Parsing.
CSCI3130: Formal Languages and Automata Theory Tutorial 4 Tutor: William Chow.
Pushdown Automata (PDA) Part 2 While I am distributing graded exams: Design a PDA to accept L = { a m b n : m  n; m, n > 0} MA/CSSE 474 Theory of Computation.
CSCI 2670 Introduction to Theory of Computing September 21, 2005.
Pushdown Automata.
Chapter 7 PDA and CFLs.
CSCI 2670 Introduction to Theory of Computing September 20, 2005.
Pushdown Automata CS 130: Theory of Computation HMU textbook, Chap 6.
Design contex-free grammars that generate: L 1 = { u v : u ∈ {a,b}*, v ∈ {a, c}*, and |u| ≤ |v| ≤ 3 |u| }. L 2 = { a p b q c p a r b 2r : p, q, r ≥ 0 }
Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.
Pushdown Automata Part I: PDAs Chapter Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2)
Lecture # 28 Theory Of Automata By Dr. MM Alam 1.
Push-down Automata Section 3.3 Fri, Oct 21, 2005.
Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein.
Chapter 7 Pushdown Automata
Chapter 7 Pushdown Automata. Context Free Languages A context-free grammar is a simple recursive way of specifying grammar rules by which strings of a.
PushDown Automata. What is a stack? A stack is a Last In First Out data structure where I only have access to the last element inserted in the stack.
1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages.
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
1.Draw a parse tree for the following derivation: S  C A C  C A b b  b b A b b  b b B b b  b b a A a a b b  b b a b a a b b 2. Show on your parse.
1.Draw a parse tree for the following derivation: S  C A C  C A b b  b b A b b  b b B b b  b b a A a a b b  b b a b a a b b 2. Show on your parse.
Summary of Previous Class There are languages that are not decidable –(we have not proved this yet) Why not extend Turing machines just as we did with.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
1 Chapter Pushdown Automata. 2 Section 12.2 Pushdown Automata A pushdown automaton (PDA) is a finite automaton with a stack that has stack operations.
CS 154 Formal Languages and Computability March 10 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
1 Section 12.2 Pushdown Automata A pushdown automaton (PDA) is a finite automaton with a stack that has stack operations pop, push, and nop. PDAs always.
CS 154 Formal Languages and Computability March 15 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
1 Push Down Automata Lecture 6-7 Ref. Handout p29-33,
Lecture 11  2004 SDU Lecture7 Pushdown Automaton.
Pushdown Automata - like NFA-  but also has a stack - transition takes the current state, the current input symbol, and the top-of-the-stack symbol (which.
Recap: Nondeterministic Finite Automaton (NFA) A deterministic finite automaton (NFA) is a 5-tuple (Q, , ,s,F) where: Q is a finite set of elements called.
Introduction to Formal Languages and Automata
Theory of Computation Pushdown Automata pda Lecture #10.
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata.
CS 461 – Sept. 28 Section 2.2 – Pushdown Automata { 0n 1n }
AUTOMATA THEORY VI.
Pushdown Automata.
Principles of Computing – UFCFA3-30-1
Chapter 5 Pushdown Automata
Pushdown Automata (PDA) Part 2
MA/CSSE 474 Theory of Computation Nondeterminism NFSMs.
More About Nondeterminism
Presentation transcript:

1 Module 33 Pushdown Automata (PDA’s) –Another example

2 Palindromes Let PAL be the set of palindromes over {a,b} –Let PAL1 be the following related language: {wcw r | w consists only of a’s and b’s} –we add c to the input alphabet as a special “marker” character –Strings in PAL1 »aca, bcb, abcba, aabcbaa, c –strings not in PAL1 »aaca, aaccaa, abccba, abcb, abba –Let PAL2 be the set of even length palindromes {ww r | w consists only of a’s and b’s}

3 PAL1 Lets first construct a PDA for PAL1 Basic ideas –Have one state remember first “half” of string –Have one state “match” second half of string to first half –Transition between these two states when the first c is encountered

4 PDA for PAL1 M = (Q, , , q 0, Z, A,  ) –Q = {q 0, q m, q f } –  = {a, b, c} –  = {Z, a, b} –q 0 = q 0 –Z = Z –A = {q f }

5 Transition Function Trans Current Input Top of Next Stack # State Char. Stack State Update q 0 a Z q 0 aZ 2 q 0 a a q 0 aa 3 q 0 a b q 0 ab 4 q 0 b Z q 0 bZ 5 q 0 b a q 0 ba 6 q 0 b b q 0 bb 7 q 0 c Z q m Z 8 q 0 c a q m a 9 q 0 c b q m b 10 q m a a q m 11 q m b b q m 12 q m Z q f Z First three transitions push a on top of the stack Second three transitions push b on the stack Third three transitions switch state q 0 to q m No change to stack Transitions 10 and 11 “match” characters from first and last half of input string

6 Notation comment We might represent transition 1 in two other ways  (q 0,a,Z) = (q 0, aZ) (q 0, a, Z, q 0, aZ) Question Is this PDA deterministic? Trans Current Input Top of Next Stack # State Char. Stack State Update q 0 a Z q 0 aZ 2 q 0 a a q 0 aa 3 q 0 a b q 0 ab 4 q 0 b Z q 0 bZ 5 q 0 b a q 0 ba 6 q 0 b b q 0 bb 7 q 0 c Z q m Z 8 q 0 c a q m a 9 q 0 c b q m b 10 q m a a q m 11 q m b b q m 12 q m Z q f Z

7 Computation Graph 1 (q 0, abcba, Z) (q 0, bcba, aZ)(q 0, cba, baZ) (q m, ba, baZ) (q m, a, aZ) (q m,, Z)(q f,, Z) Trans Current Input Top of Next Stack # State Char. Stack State Update q 0 a Z q 0 aZ 2 q 0 a a q 0 aa 3 q 0 a b q 0 ab 4 q 0 b Z q 0 bZ 5 q 0 b a q 0 ba 6 q 0 b b q 0 bb 7 q 0 c Z q m Z 8 q 0 c a q m a 9 q 0 c b q m b 10 q m a a q m 11 q m b b q m 12 q m Z q f Z

8 Computation Graph 2 (q 0, abcab, Z) (q 0, bcab, aZ)(q 0, cab, baZ)(q m, ab, baZ) Trans Current Input Top of Next Stack # State Char. Stack State Update q 0 a Z q 0 aZ 2 q 0 a a q 0 aa 3 q 0 a b q 0 ab 4 q 0 b Z q 0 bZ 5 q 0 b a q 0 ba 6 q 0 b b q 0 bb 7 q 0 c Z q m Z 8 q 0 c a q m a 9 q 0 c b q m b 10 q m a a q m 11 q m b b q m 12 q m Z q f Z

9 Computation Graph 3 (q 0, acab, Z) (q 0, cab, aZ)(q m, ab, aZ)(q m, b, Z)(q f, b, Z) Trans Current Input Top of Next Stack # State Char. Stack State Update q 0 a Z q 0 aZ 2 q 0 a a q 0 aa 3 q 0 a b q 0 ab 4 q 0 b Z q 0 bZ 5 q 0 b a q 0 ba 6 q 0 b b q 0 bb 7 q 0 c Z q m Z 8 q 0 c a q m a 9 q 0 c b q m b 10 q m a a q m 11 q m b b q m 12 q m Z q f Z

10 PAL2 Lets now construct a PDA for PAL What is harder this time? –When do we switch from putting strings on the stack to matching? –Example After seeing aab, should we switch to match mode or stay in stack mode? –Solution Do both using nondeterminism

11 PDA for PAL2 M = (Q, , , q 0, Z, A,  ) –Q = {q 0, q m, q f } –  = {a, b} –  = {Z, a, b} –q 0 = q 0 –Z = Z –A = {q f }

12 Transition Relation Trans Current Input Top of Next Stack # State Char. Stack State Update q 0 a Z q 0 aZ 2 q 0 a a q 0 aa 3 q 0 a b q 0 ab 4 q 0 b Z q 0 bZ 5 q 0 b a q 0 ba 6 q 0 b b q 0 bb 7 q 0 Z q m Z 8 q 0 a q m a 9 q 0 b q m b 10 q m a a q m 11 q m b b q m 12 q m Z q f Z First three transitions push a on top of the stack Second three transitions push b on the stack Third three transitions switch state q 0 to q m Is the PDA deterministic or nondeterministic?

13 Computation Graph 1 (q 0, abba, Z) (q 0, bba, aZ) (q m, abba, Z) (q 0, ba, baZ) (q m, bba, aZ)(q f, abba, Z) (q 0, a, bbaZ) (q m, ba, baZ) (q 0,, abbaZ) (q m, a, bbaZ) (q m, a, aZ) (q m,, abbaZ) (q m,, Z) (q f,, Z) Trans Current Input Top of Next Stack # State Char. Stack State Update q 0 a Z q 0 aZ 2 q 0 a a q 0 aa 3 q 0 a b q 0 ab 4 q 0 b Z q 0 bZ 5 q 0 b a q 0 ba 6 q 0 b b q 0 bb 7 q 0 Z q m Z 8 q 0 a q m a 9 q 0 b q m b 10 q m a a q m 11 q m b b q m 12 q m Z q f Z

14 Computation Graph 2 (q 0, aba, Z) (q 0, ba, aZ) (q m, aba, Z) (q 0, a, baZ) (q m, ba, aZ)(q f, aba, Z) (q 0,, abaZ) (q m, a, baZ) (q m,, abaZ) Trans Current Input Top of Next Stack # State Char. Stack State Update q 0 a Z q 0 aZ 2 q 0 a a q 0 aa 3 q 0 a b q 0 ab 4 q 0 b Z q 0 bZ 5 q 0 b a q 0 ba 6 q 0 b b q 0 bb 7 q 0 Z q m Z 8 q 0 a q m a 9 q 0 b q m b 10 q m a a q m 11 q m b b q m 12 q m Z q f Z

15 PAL Challenge –Construct a PDA for PAL –First step Construct a PDA for odd length palindromes –Then Combine PDA’s for odd length and even length palindromes