1 / 26

Pushdown Automata (PDA)

Pushdown Automata (PDA). CSE-501 Formal Language & Automata Theory Aug-Dec,2010. ALAK ROY. Assistant Professor Dept. of CSE NIT Agartala. Pushdown Automata (PDA). Informally: Think of an ε -NFA with the additional power that it can manipulate a stack.

anthea
Télécharger la présentation

Pushdown Automata (PDA)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Pushdown Automata (PDA) CSE-501 Formal Language & Automata Theory Aug-Dec,2010 ALAK ROY. Assistant Professor Dept. of CSE NIT Agartala

  2. Pushdown Automata (PDA) • Informally: • Think of an ε-NFA with the additional power that it can manipulate a stack. • Transitions are modified to accommodate stack operations. • Questions: • What is a stack? • How does a stack help? • Why PDA? • A DFA can “remember” only a finite amount of information, whereas a PDA can “remember” an infinite amount of (certain types of) information.

  3. q0 q6 • Example: {0n1n | 0=<n} Is not regular {0n1n | 0nk, for some fixed k} Is regular, for any fixed k. • For k=3: L = {ε, 01, 0011, 000111} 0 0 0 q1 q2 q3 1 1 1 1 0/1 1 1 q7 q5 q4 0/1 0 0 0

  4. In a DFA, each state remembers a finite amount of information. • To get {0n1n | 0n} with a DFA would require an infinite number of states using the preceding technique. • An infinite stack solves the problem for {0n1n | 0n} as follows: • Read all 0’s and place them on a stack • Read all 1’s and match with the corresponding 0’s on the stack • Only need two states to do this in a PDA • Similarly for {0n1m0n+m | n,m0}

  5. PDA MODEL

  6. Characteristic of PDA • PDS (Pushdown Stack)

  7. PDA • Being nondeterministic, the PDA can have a choice of next moves. • Its moves are determined by: • The current state (of its “NFA”), • The current input symbol (or ε), and • The current symbol on top of its stack. • In each choice, the PDA can: • Change state, and also • Replace the top symbol on the stack by a sequence of zero or more symbols. • Zero symbols = “pop.” • Many symbols = sequence of “pushes.”

  8. Formal Definition of a PDA • A pushdown automaton (PDA) is a seven-tuple: M = (Q, Σ, Г, δ, q0, z0, F) Q A finite set of states Σ A finite input alphabet Г A finite stack alphabet q0 The initial/starting state, q0 is in Q z0 A starting stack symbol, is in Г F A set of final/accepting states, which is a subset of Q δ A transition function, where δ: Q x (Σ U {ε}) x Г –> finite subsets of Q x Г*

  9. Consider the various parts of δ: Q x (Σ U {ε}) x Г –> finite subsets of Q x Г* • Q on the LHS means that at each step in a computation, a PDA must consider its’ current state. • Г on the LHS means that at each step in a computation, a PDA must consider the symbol on top of its’ stack. • Σ U {ε} on the LHS means that at each step in a computation, a PDA may or may not consider the current input symbol, i.e., it may have epsilon transitions. • “Finite subsets” on the RHS means that at each step in a computation, a PDA will have several options. • Q on the RHS means that each option specifies a new state. • Г* on the RHS means that each option specifies zero or more stack symbols that will replace the top stack symbol.

  10. Conventions • a, b, … are input symbols. • But sometimes we allow ε as a possible value. • …, X, Y, Z are stack symbols. • …, w, x, y, z are strings of input symbols. • , ,… are strings of stack symbols.

  11. The Transition Function • Takes three arguments: • A state, in Q. • An input, which is either a symbol in Σ or ε. • A stack symbol in Γ. • δ(q, a, Z) is a set of zero or more actions of the form (p, ). • p is a state;  is a string of stack symbols.

  12. Actions of the PDA • If δ(q, a, Z) contains (p, ) among its actions, then one thing the PDA can do in state q, with a at the front of the input, and Z on top of the stack is: • Change the state to p. • Remove a from the front of the input (but a may be ε). • Replace Z on the top of the stack by . (or Pop Z, Push )

  13. Two types of PDA transitions: δ(q, a, z) = {(p1, 1), (p2, 2),…, (pm, m)} • Current state is q • Current input symbol is a • Symbol currently on top of the stack z • Move to state pi from q • Replace z with  i on the stack (leftmost symbol on top) • Move the input head to the next input symbol : p1 a/z/ 1 q a/z/ 2 p2 a/z/ m pm

  14. Two types of PDA transitions: δ(q, ε, z) = {(p1, 1), (p2, 2),…, (pm, m)} • Current state is q • Current input symbol is not considered • Symbol currently on top of the stack z • Move to state pi from q • Replace z with  i on the stack (leftmost symbol on top) • No input symbol is read : p1 ε/z/ 1 q ε/z/ 2 p2 ε/z/ m pm

  15. Example: PDA • Design a PDA to accept {0n1n | n > 1}. • The states: • q = start state. We are in state q if we have seen only 0’s so far. • p = we’ve seen at least one 1 and may now proceed only if the inputs are 1’s. • f = final state; accept.

  16. Example: PDA – (2) • The stack symbols: • Z0 = start symbol. Also marks the bottom of the stack, so we know when we have counted the same number of 1’s as 0’s. • X = marker, used to count the number of 0’s seen on the input.

  17. Example: PDA – (3) • The transitions: • δ(q, 0, Z0) = {(q, XZ0)}. • δ(q, 0, X) = {(q, XX)}. These two rules cause one X to be pushed onto the stack for each 0 read from the input. • δ(q, 1, X) = {(p, ε)}. When we see a 1, go to state p and pop one X. • δ(p, 1, X) = {(p, ε)}. Pop one X per 1. • δ(p, ε, Z0) = {(f, Z0)}. Accept at bottom.

  18. Actions of the Example PDA 0 0 0 1 1 1 q Z0

  19. Actions of the Example PDA 0 0 1 1 1 q X Z0

  20. Actions of the Example PDA 0 1 1 1 q X X Z0

  21. Actions of the Example PDA 1 1 1 q X X X Z0

  22. Actions of the Example PDA 1 1 p X X Z0

  23. Actions of the Example PDA 1 p X Z0

  24. Actions of the Example PDA p Z0

  25. Actions of the Example PDA f Z0

  26. Thank You

More Related