Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Module 32 Pushdown Automata (PDA’s) –definition –Example We define configurations and computations of PDA’s We define L(M) for PDA’s.

Similar presentations


Presentation on theme: "1 Module 32 Pushdown Automata (PDA’s) –definition –Example We define configurations and computations of PDA’s We define L(M) for PDA’s."— Presentation transcript:

1 1 Module 32 Pushdown Automata (PDA’s) –definition –Example We define configurations and computations of PDA’s We define L(M) for PDA’s

2 2 Pushdown Automata Definition and Motivating Example

3 3 Pushdown Automata (PDA) In this presentation we introduce the PDA model of computation (programming language). –The key addition to a PDA (from an NFA-/\) is the addition of external memory in the form of an infinite capacity stack The word “pushdown” comes from the stacks of trays in cafeterias where you have to pushdown on the stack to add a tray to it.

4 4 NFA for {a m b n | m,n >= 0} What strings end up in each state of the above NFA? –I: –B: –C: Consider the language {a n b n | n >= 0}. This NFA can recognize strings which have the correct form, –a’s followed by b’s. However, the NFA cannot remember the relative number of a’s and b’s seen at any point in time. /\ a b IBC

5 5 PDA for {a n b n | n >=0 } * /\ a b IBC NFA Imagine we now have memory in the form of a stack which we can use to help remember how many a’s we have seen by pushing onto and popping from the stack When we see an a in state I, we do the following two actions: 1) We push an a on the stack. 2) We stay in state I. When we see a b in state B, we do the following two actions: 1) We pop an a from the stack. 2) We stay in state B. From state B, we allow a /\-transition to state C only if 1) The stack is empty. Finally, when we begin, the stack should be empty. IBC b;popa;push a /\;only if stack is empty PDA /\ Initialize stack to empty

6 6 Formal PDA definition PDA M = (Q, , , q 0, Z, A,  ) Modified elements –  is the stack alphabet Z is a special character that is initially on the stack Often used to represent an empty stack –  is modified as follows Pop to read the top character on the stack Stack update action –What to push back on the stack –If we push /\, then the net result of the action is a pop

7 7 Example PDA Q = {I, B, C}  = {a,b}  = {Z, a} q 0 = I Z is the initial stack character A = {C}  : S aTopStNSstack update IaaIpush aa IaZIpush aZ I/\aBpush a I/\ZBpush Z BbaBpush /\ B/\ZCpush Z IBC b;a;/\ a;a; aa a;Z; aZ /\;Z;Z /\;a;a /\;Z;Z Example PDA Initialize stack to only contain Z

8 8 Computing with PDA’s * Configurations change compared with NFA-/\’s –Configuration components: current state remaining input to be processed stack contents Computations are essentially the same as with NFA-/\’s given the modified configurations –Determining which transitions of a PDA can be applied to a given configuration is more complicated though

9 9 Computation Graph of PDA Computation graph for this PDA on the input string aabb (I,aabb,Z) (C,aabb,Z) (B,bb,aaZ) (B,abb,aZ)(I,bb,aaZ) (I,abb,aZ) (B,aabb,Z) (B,b,aZ)(B,/\,Z) (C,/\,Z) Q = {I, B, C}  = {a,b}  = {Z, a} q 0 = I Z is the initial stack character A = {C}  : S aTopStNSstack update IaaIpush aa IaZIpush aZ I/\aBpush a I/\ZBpush Z BbaBpush /\ B/\ZCpush Z

10 10 Definition of |- Input string aabb (I, aabb, Z) |- (I,abb,aZ) (I, aabb, Z) |- (B, aabb, Z) (I, aabb, Z) |- 2 (C, aabb, Z) (I, aabb, Z) |- 3 (B, bb, aaZ) (I, aabb, Z) |- * (B, abb, aZ) (I, aabb, Z) |- * (B, /\, Z) (I, aabb, Z) |- * (C, /\, Z) IBC b;a;/\ a;a; aa a;Z; aZ /\;Z;Z /\;a;a /\;Z;Z (I,aabb,Z) (C,aabb,Z) (B,bb,aaZ) (B,abb,aZ)(I,bb,aaZ) (I,abb,aZ) (B,aabb,Z) (B,b,aZ) (B,/\,Z) (C,/\,Z)

11 11 Acceptance and Rejection M accepts string x if one of the configurations reached is an accepting configuration (q 0, x, Z) |- * (f, /\  ),f in A,  in  * Stack contents can be anything M rejects string x if all configurations reached are either not halting configurations or are rejecting configurations IBC b;a;/\ a;a; aa a;Z; aZ /\;Z;Z /\;a;a /\;Z;Z Input string aabb (I,aabb,Z) (C,aabb,Z) (B,bb,aaZ) (B,abb,aZ)(I,bb,aaZ) (I,abb,aZ) (B,aabb,Z) (B,b,aZ) (B,/\,Z) (C,/\,Z) Not an accepting configuration since input not completely processed Not an accepting configuration since state is not accepting An accepting configuration

12 12 Defining L(M) and LPDA L(M) (or Y(M)) –The set of strings ? N(M) –The set of strings ? LPDA –Language L is in language class LPDA iff ? M accepts string x if one of the configurations reached is an accepting configuration (q 0, x, Z) |- * (f, /\  ),f in A,  in  * Stack contents can be anything M rejects string x if all configurations reached are either not halting configurations or are rejecting configurations

13 13 Deterministic PDA’s A PDA is deterministic if its transition function satisfies both of the following properties –For all q in Q, a in  union {/\}, and X in , the set  (q,a,X) has at most one element –For all q in Q and X in G, if  (q, /\, X) { }, then  (q,a,X) = { } for all a in  A computation graph is now just a path again Our default assumption is that PDA’s are nondeterministic

14 14 Two forms of nondeterminism Trans Current Input Top of Next Stack # State Char. Stack State Update ------------------------------------------------------- 1 q 0 a Z q 0 aZ 2 q 0 a Z q 0 aa 3 q0 /\ Z q0 aZ 4 q0 a Z q0 aa

15 15 LPDA and DCFL A language L is in language class LPDA if and only if there exists a PDA M such that L(M) = L A language L is in language class DCFL (Deterministic Context-Free Languages) if and only if there exists a deterministic PDA M such that L(M) = L To be proven –LPDA = CFL –CFL is a proper superset of DCFL

16 16 PDA Comments Note, we can use the stack for much more than just a counter See examples in chapter 7 for some details


Download ppt "1 Module 32 Pushdown Automata (PDA’s) –definition –Example We define configurations and computations of PDA’s We define L(M) for PDA’s."

Similar presentations


Ads by Google