Pushdown Automata Part I: PDAs Chapter 12 1. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2)

Slides:



Advertisements
Similar presentations
Context-Free and Noncontext-Free Languages
Advertisements

Chapter 5 Pushdown Automata
Pushdown Automata Section 2.2 CSC 4170 Theory of Computation.
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.
Finite Automata Section 1.1 CSC 4170 Theory of Computation.
CS21 Decidability and Tractability
Introduction to Computability Theory
1 Introduction to Computability Theory Lecture7: PushDown Automata (Part 1) Prof. Amos Israeli.
Costas Busch - RPI1 Pushdown Automata PDAs. Costas Busch - RPI2 Pushdown Automaton -- PDA Input String Stack States.
Courtesy Costas Busch - RPI1 Pushdown Automata PDAs.
Deterministic FA/ PDA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 4 Updated by Marek Perkowski.
Fall 2004COMP 3351 Pushdown Automata PDAs. Fall 2004COMP 3352 Pushdown Automaton -- PDA Input String Stack States.
Fall 2006Costas Busch - RPI1 Pushdown Automata PDAs.
January 14, 2015CS21 Lecture 51 CS21 Decidability and Tractability Lecture 5 January 14, 2015.
Pushdown Automaton (PDA)
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
CSC 361Finite Automata1. CSC 361Finite Automata2 Formal Specification of Languages Generators Grammars Context-free Regular Regular Expressions Recognizers.
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 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2010.
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.
CS490 Presentation: Automata & Language Theory Thong Lam Ran Shi.
Pushdown Automata (PDA) Intro
TM Design Universal TM MA/CSSE 474 Theory of Computation.
Pushdown Automata CS 130: Theory of Computation HMU textbook, Chap 6.
Pushdown Automata (PDAs)
Push-down Automata Section 3.3 Fri, Oct 21, 2005.
MA/CSSE 474 Theory of Computation Decision Problems DFSMs.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 11 Midterm Exam 2 -Context-Free Languages Mälardalen University 2005.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 6 Mälardalen University 2010.
Pushdown Automata Chapters Generators vs. Recognizers For Regular Languages: –regular expressions are generators –FAs are recognizers For Context-free.
Context-Free and Noncontext-Free Languages Chapter 13 1.
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.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2010 with acknowledgement.
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 2 Context-Free Languages Some slides are in courtesy.
Pushdown Automata Hopcroft, Motawi, Ullman, Chap 6.
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.
Grammar Set of variables Set of terminal symbols Start variable Set of Production rules.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
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.
MA/CSSE 474 Theory of Computation Decision Problems, Continued DFSMs.
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.
CSCI 2670 Introduction to Theory of Computing September 22, 2004.
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.
Normal Forms (Chomsky and Greibach) Pushdown Automata (PDA) Intro PDA examples MA/CSSE 474 Theory of Computation.
Formal Languages, Automata and Models of Computation
Theory of Computation Pushdown Automata pda Lecture #10.
Deterministic FA/ PDA Sequential Machine Theory Prof. K. J. Hintz
Pushdown Automata PDAs
Push-down Automata Section 3.3 Wed, Oct 27, 2004.
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
Push-down Automata.
Intro to Data Structures
Context-Free Grammars
Pushdown Automata (PDA) Part 2
More About Nondeterminism
Presentation transcript:

Pushdown Automata Part I: PDAs Chapter 12 1

Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no, AND if yes, describe the structure a + b * c 2

Just Recognizing We need a device similar to an FSM except that it needs more power. The insight: Precisely what it needs is a stack, which gives it an unlimited amount of memory with a restricted structure. Example: Bal (the balanced parentheses language) (((())) 3

Definition of a Pushdown Automaton M = (K, , , , s, A), where: K is a finite set of states  is the input alphabet  is the stack alphabet s  K is the initial state A  K is the set of accepting states, and  is the transition relation. It is a finite subset of (K  (   {  })   *)  (K   *) state input or  string of statestring of symbols to pop to push from top on top of stackof stack 4

Definition of a Pushdown Automaton A configuration of M is an element of K   *   *. The initial configuration of M is (s, w,  ). K : Current state  * : Input left to read  * : Stack content Compare to the configuration of FSM 5

Manipulating the Stack c will be written as cab a b If c 1 c 2 …c n is pushed onto the stack: c 1 c 2 c n c a b c 1 c 2 …c n cab 6

Yields Let c be any element of   {  }, Let  1,  2 and  be any elements of  *, and Let w be any element of  *. Then,yields-in-one-step |- M is defined as (q 1, cw,  1  ) |- M (q 2, w,  2  ) iff ((q 1, c,  1 ), (q 2,  2 ))  . Let |- M * be the reflexive, transitive closure of |- M. C 1 yields configuration C 2 iff C 1 |- M * C 2 7 q1q1 q2q2 c/1/2c/1/2 If ((q 1, c,  1 ), (q 2,  2 ))  ,

Computations A computation by M is a finite sequence of configurations C 0, C 1, …, C n for some n  0 such that: ● C 0 is an initial configuration, ● C n is of the form (q, ,  ), for some state q  K M and some string  in  *, and ● C 0 |- M C 1 |- M C 2 |- M … |- M C n. 8

Nondeterminism If M is in some configuration (q 1, s,  ) it is possible that: ●  contains exactly one transition that matches. ●  contains more than one transition that matches. ●  contains no transition that matches. 9

Accepting A computation C of M is an accepting computation iff: ● C = (s, w,  ) |- M * (q, ,  ), and ● q  A. M accepts a string w iff at least one of its computations accepts. Other paths may: ● Read all the input and halt in a nonaccepting state, ● Read all the input and halt in an accepting state with the stack not empty, ● Loop forever and never finish reading the input, or ● Reach a dead end where no more input can be read. The language accepted by M, denoted L(M), is the set of all strings accepted by M. 10

Rejecting A computation C of M is a rejecting computation iff: ● C = (s, w,  ) |- M * (q, w,  ), ● C is not an accepting computation, and ● M has no moves that it can make from (q, w,  ). M rejects a string w iff all of its computations reject. So note that it is possible that, on input w, M neither accepts nor rejects. 11

A PDA for Balanced Parentheses 12

A PDA for Balanced Parentheses M = (K, , , , s, A), where: K = {s}the states  = {(, )} the input alphabet  = {(}the stack alphabet A = {s}  contains: ((s, (,  **), (s, ( )) ((s, ), ( ), (s,  )) **Important: This does not mean that the stack is empty If input is (, what’s on stack top doesn’t matter and a ( is pushed to stack. If input is ) and ( is on stack top, then ( is popped and nothing is pushed to stack. 13

A PDA for A n B n = { a n b n : n  0} 14

A PDA for A n B n = { a n b n : n  0} M = (K, , , , s, A), where: K = {s, f}the states  = { a, b } the input alphabet  = { a }the stack alphabet A = {f}the accepting states  contains: ((s, a,  ), (s, a )) ((s, b, a ), (f,  )) ((f, b, a ), (f,  )) 15

A PDA for {w c w R : w  { a, b }*} 16

M = (K, , , , s, A), where: K = {s, f}the states  = { a, b, c } the input alphabet  = { a, b }the stack alphabet A = {f}the accepting states  contains: ((s, a,  ), (s, a )) ((s, b,  ), (s, b )) ((s, c,  ), (f,  )) ((f, a, a ), (f,  )) ((f, b, b ), (f,  )) A PDA for {w c w R : w  { a, b }*} 17

A PDA for { a n b 2n : n  0} 18

A PDA for { a n b 2n : n  0} M = (K, , , , s, A), where: K = the states  = the input alphabet  = the stack alphabet A = the accepting states  contains: 19

Exploiting Nondeterminism A PDA M is deterministic iff: ●  M contains no pairs of transitions that compete with each other, and ● Whenever M is in an accepting configuration it has no available moves. But many useful PDAs are not deterministic. 20

A PDA for PalEven ={ww R : w  { a, b }*} S   S  a S a S  b S b A PDA: 21

A PDA for PalEven ={ww R : w  { a, b }*} S   S  a S a S  b S b A PDA: 22

A PDA for {w  { a, b }* : # a (w) = # b (w)} 23

A PDA for {w  { a, b }* : # a (w) = # b (w)} 24

More on Nondeterminism Accepting Mismatches L = { a m b n : m  n; m, n > 0} Start with the case where n = m: a//a a//a b/a/b/a/ b/a/b/a/ 12 25

More on Nondeterminism Accepting Mismatches L = { a m b n : m  n; m, n > 0} Start with the case where n = m: a//a a//a b/a/b/a/ b/a/b/a/ ● If stack and input are empty, halt and reject. ● If input is empty but stack is not (m > n) (accept): ● If stack is empty but input is not (m < n) (accept): 12 26

More on Nondeterminism Accepting Mismatches L = { a m b n : m  n; m, n > 0} a//a a//a b/a/b/a/ b/a/b/a/ ● If input is empty but stack is not (m > n) (accept): a//a a//a b/a/b/a/ b/a/b/a/ /a//a/ /a//a/

More on Nondeterminism Accepting Mismatches L = { a m b n : m  n; m, n > 0} a//a a//a b/a/b/a/ b/a/b/a/ ● If stack is empty but input is not (m < n) (accept): a//a a//a b/a/b/a/ b/a/b/a/ b// b// b// b// 28

Putting It Together L = { a m b n : m  n; m, n > 0} ● Jumping to the input clearing state 4: Need to detect bottom of stack. ● Jumping to the stack clearing state 3: Need to detect end of input. 29

The Power of Nondeterminism Consider A n B n C n = { a n b n c n : n  0}. PDA for it? 30

The Power of Nondeterminism Consider A n B n C n = { a n b n c n : n  0}. Now consider L =  A n B n C n. L is the union of two languages: 1. {w  { a, b, c }* : the letters are out of order}, and 2. { a i b j c k : i, j, k  0 and (i  j or j  k)} (in other words, unequal numbers of a ’s, b ’s, and c ’s). 31

A PDA for L =  A n B n C n What is it? 32

Are the Context-Free Languages Closed Under Complement?  A n B n C n is context free. If the CF languages were closed under complement, then  A n B n C n = A n B n C n would also be context-free. But we will prove that it is not. 33

L = { a n b m c p : n, m, p  0 and n  m or m  p} S  NC/* n  m, then arbitrary c 's S  QP/* arbitrary a 's, then p  m N  A/* more a 's than b 's N  B/* more b 's than a 's A  a A  a A A  a A b B  b B  B b B  a B b C   | c C/* add any number of c 's P  B'/* more b 's than c 's P  C'/* more c 's than b 's B'  b B'  b B' B'  b B' c C'  c | C' c C'  C' c C'  b C' c Q   | a Q/* prefix with any number of a 's 34

Reducing Nondeterminism and show where the competitions are ● Jumping to the input clearing state 4: Need to detect bottom of stack, so push # onto the stack before we start. ● Jumping to the stack clearing state 3: Need to detect end of input. Add to L a termination character (e.g., $) 35

Reducing Nondeterminism ● Jumping to the input clearing state 4: 36

Reducing Nondeterminism ● Jumping to the stack clearing state 3: 37

More on PDAs A PDA for {ww R : w  {a, b}*}: What about a PDA to accept {ww : w  { a, b }*}? 38