Presentation is loading. Please wait.

Presentation is loading. Please wait.

Pushdown Automata Hopcroft, Motawi, Ullman, Chap 6.

Similar presentations


Presentation on theme: "Pushdown Automata Hopcroft, Motawi, Ullman, Chap 6."— Presentation transcript:

1 Pushdown Automata Hopcroft, Motawi, Ullman, Chap 6

2 PDAs: Pushdown Automata Same as Finite Automata (e.g., NFAs), but with the addition of a stack: On each transition, a stack is manipulated and monitored (operations: push, pop, inspect top, check for empty) Allows the automaton to “count” Definition will need to incorporate stack events When is a string acceptable?

3 PDA definition A pushdown automaton M is a tuple M = (Q, , , , q 0, Z 0, F), where: Q is a set of states  is the input alphabet  is the stack alphabet  : Q   +є    (Q   *)* is the state transition function mapping a (state, symbol, stack symbol) triple to a set of (state, string) pairs q 0 is the start state of M Z 0 is the starting stack symbol (initially on the stack) F  Q is the set of accepting states or final states of M

4 PDA transitions A transition between states q x and q y can be carried out in a PDA when a given next input symbol a is read and a given stack symbol X is on top of the stack When the transition to q y is carried out, the symbol X is replaced with a string w of stack symbols  (q x, a, X) contains the pair (q y, w) How are the stack operations push, pop, inspect top, and check if empty carried out? push Y on input a:  (q x, a, X) -> (q y, YX) pop Y:  (q x, a, X) -> (q y, є) How about inspect top and check if empty?

5 Example L = {a n b n : n >= 0} PDA M = ({q 0,q 1,q 2 }, {a,b}, {Z 0,X}, , q 0, Z 0, {q 2 })  defined (informally) as follows: On input a (from q 0 ) push X onto the stack On input b (from q 0 and q 1 ), pop X and transition to q1 (note: cannot transition if X is not on top of the stack) From q0 and q1, transition to final state q 2 if stack is “empty” (Z 0 is on top)

6 Transition function example  (q 0, a, Z 0 ) = {(q 0, XZ 0 )}  (q 0, a, X) = {(q 0, XX)}  (q 0, b, X) = {(q 1, є)}  (q 1, b, X) = {(q 1, є)}  (q 0, є, Z 0 ) = {(q 2, Z 0 )}  (q 1, є, Z 0 ) = {(q 2, Z 0 )}  (q 0, b, Z 0 ) =  (q 1, b, Z 0 ) =  (q 1, a, X) and many others are all equal to {} push X onto the stack on input a pop X from the stack on input b go to final state if Z 0 is on top

7 PDA diagram q0q0 q2q2 a, Z 0, XZ 0 a, X, XX q1q1 b, X, є є, Z 0, Z 0

8 Alternative diagram q0q0 q2q2 a, push X q1q1 b, pop X є, empty b, pop X

9 Accepting strings in a PDA By final state, just like in regular final automata Or by empty stack: string is acceptable once the stack is empty (Z 0 has been popped out), regardless of what state it is currently in These two “kinds” of PDAs are equivalent (proofs in section 6.2)

10 Equivalence of PDAs and CFGs PDAs and CFGs describe the same set of languages (section 6.3) Proof requires: Construction from a grammar to an equivalent PDA Construction from a PDA to an equivalent grammar


Download ppt "Pushdown Automata Hopcroft, Motawi, Ullman, Chap 6."

Similar presentations


Ads by Google