Samiksha Jaiswal (Editor)

Pushdown automaton

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit
Pushdown automaton

In computer science, a pushdown automaton (PDA) is a type of automaton that employs a stack.

Contents

Pushdown automata are used in theories about what can be computed by machines. They are more capable than finite-state machines but less capable than Turing machines. Deterministic pushdown automata can recognize all deterministic context-free languages while nondeterministic ones can recognize all context-free languages, with the former often used in parser design.

The term "pushdown" refers to the fact that the stack can be regarded as being "pushed down" like a tray dispenser at a cafeteria, since the operations never work on elements other than the top element. A stack automaton, by contrast, does allow access to and operations on deeper elements. Stack automata can recognize a strictly larger set of languages than pushdown automata. A nested stack automaton allows full access, and also allows stacked values to be entire sub-stacks rather than just single finite symbols.

Informal description

A finite state machine just looks at the input signal and the current state: it has no stack to work with. It chooses a new state, the result of following the transition. A pushdown automaton (PDA) differs from a finite state machine in two ways:

  1. It can use the top of the stack to decide which transition to take.
  2. It can manipulate the stack as part of performing a transition.

A pushdown automaton reads a given input string from left to right. In each step, it chooses a transition by indexing a table by input symbol, current state, and the symbol at the top of the stack. A pushdown automaton can also manipulate the stack, as part of performing a transition. The manipulation can be to push a particular symbol to the top of the stack, or to pop off the top of the stack. The automaton can alternatively ignore the stack, and leave it as it is.

Put together: Given an input symbol, current state, and stack symbol, the automaton can follow a transition to another state, and optionally manipulate (push or pop) the stack.

If, in every situation, at most one such transition action is possible, then the automaton is called a deterministic pushdown automaton (DPDA). In general, several actions are possible, and the automaton is called a general, or nondeterministic, PDA. A given input string may drive a nondeterministic pushdown automaton to one of several configuration sequences; if one of them leads to an accepting configuration after reading the complete input string, the latter is said to belong to the language accepted by the automaton.

Formal definition

We use standard formal language notation: Γ denotes the set of strings over alphabet Γ and ε denotes the empty string.

A PDA is formally defined as a 7-tuple:

M = ( Q ,   Σ ,   Γ ,   δ ,   q 0 ,   Z ,   F ) where

  • Q is a finite set of states
  • Σ is a finite set which is called the input alphabet
  • Γ is a finite set which is called the stack alphabet
  • δ is a finite subset of Q × ( Σ { ε } ) × Γ × Q × Γ , the transition relation.
  • q 0 Q is the start state
  •   Z Γ is the initial stack symbol
  • F Q is the set of accepting states
  • An element ( p , a , A , q , α ) δ is a transition of M . It has the intended meaning that M , in state p Q , on the input a Σ { ε } and with A Γ as topmost stack symbol, may read a , change the state to q , pop A , replacing it by pushing α Γ . The ( Σ { ε } ) component of the transition relation is used to formalize that the PDA can either read a letter from the input, or proceed leaving the input untouched.

    In many texts the transition relation is replaced by an (equivalent) formalization, where

  • δ is the transition function, mapping Q × ( Σ { ε } ) × Γ into finite subsets of Q × Γ
  • Here δ ( p , a , A ) contains all possible actions in state p with A on the stack, while reading a on the input. One writes for example δ ( p , a , A ) = { ( q , B A ) } precisely when ( q , B A ) { ( q , B A ) } , ( q , B A ) δ ( p , a , A ) , because ( ( p , a , A ) , { ( q , B A ) } ) δ . Note that finite in this definition is essential.

    Computations

    In order to formalize the semantics of the pushdown automaton a description of the current situation is introduced. Any 3-tuple ( p , w , β ) Q × Σ × Γ is called an instantaneous description (ID) of M , which includes the current state, the part of the input tape that has not been read, and the contents of the stack (topmost symbol written first). The transition relation δ defines the step-relation M of M on instantaneous descriptions. For instruction ( p , a , A , q , α ) δ there exists a step ( p , a x , A γ ) M ( q , x , α γ ) , for every x Σ and every γ Γ .

    In general pushdown automata are nondeterministic meaning that in a given instantaneous description ( p , w , β ) there may be several possible steps. Any of these steps can be chosen in a computation. With the above definition in each step always a single symbol (top of the stack) is popped, replacing it with as many symbols as necessary. As a consequence no step is defined when the stack is empty.

    Computations of the pushdown automaton are sequences of steps. The computation starts in the initial state q 0 with the initial stack symbol Z on the stack, and a string w on the input tape, thus with initial description ( q 0 , w , Z ) . There are two modes of accepting. The pushdown automaton either accepts by final state, which means after reading its input the automaton reaches an accepting state (in F ), or it accepts by empty stack ( ε ), which means after reading its input the automaton empties its stack. The first acceptance mode uses the internal memory (state), the second the external memory (stack).

    Formally one defines

    1. L ( M ) = { w Σ | ( q 0 , w , Z ) M ( f , ε , γ ) with f F and γ Γ } (final state)
    2. N ( M ) = { w Σ | ( q 0 , w , Z ) M ( q , ε , ε ) with q Q } (empty stack)

    Here M represents the reflexive and transitive closure of the step relation M meaning any number of consecutive steps (zero, one or more).

    For each single pushdown automaton these two languages need to have no relation: they may be equal but usually this is not the case. A specification of the automaton should also include the intended mode of acceptance. Taken over all pushdown automata both acceptance conditions define the same family of languages.

    Theorem. For each pushdown automaton M one may construct a pushdown automaton M such that L ( M ) = N ( M ) , and vice versa, for each pushdown automaton M one may construct a pushdown automaton M such that N ( M ) = L ( M )

    Example

    The following is the formal description of the PDA which recognizes the language { 0 n 1 n n 0 } by final state:

    M = ( Q ,   Σ ,   Γ ,   δ ,   q 0 ,   Z ,   F ) , where

  • states: Q = { p , q , r }
  • input alphabet: Σ = { 0 , 1 }
  • stack alphabet: Γ = { A , Z }
  • start state: q 0 = p
  • start stack symbol: Z
  • accepting states: F = { r }
  • The transition relation δ consists of the following six instructions:

    ( p , 0 , Z , p , A Z ) , ( p , 0 , A , p , A A ) , ( p , ϵ , Z , q , Z ) , ( p , ϵ , A , q , A ) , ( q , 1 , A , q , ϵ ) , and ( q , ϵ , Z , r , Z ) .

    In words, the first two instructions say that in state p any time the symbol 5000000000000000000♠0 is read, one A is pushed onto the stack. Pushing symbol A on top of another A is formalized as replacing top A by AA (and similarly for pushing symbol A on top of a Z).

    The third and fourth instructions say that, at any moment the automaton may move from state p to state q.

    The fifth instruction says that in state q, for each symbol 7000100000000000000♠1 read, one A is popped.

    Finally, the sixth instruction says that the machine may move from state q to accepting state r only when the stack consists of a single Z.

    There seems to be no generally used representation for PDA. Here we have depicted the instruction ( p , a , A , q , α ) by an edge from state p to state q labelled by a ; A / α (read a; replace A by α ).

    Understanding the computation process

    The following illustrates how the above PDA computes on different input strings. The subscript M from the step symbol is here omitted.

    PDA and context-free languages

    Every context-free grammar can be transformed into an equivalent nondeterministic pushdown automaton. The derivation process of the grammar is simulated in a leftmost way. Where the grammar rewrites a nonterminal, the PDA takes the topmost nonterminal from its stack and replaces it by the right-hand part of a grammatical rule (expand). Where the grammar generates a terminal symbol, the PDA reads a symbol from input when it is the topmost symbol on the stack (match). In a sense the stack of the PDA contains the unprocessed data of the grammar, corresponding to a pre-order traversal of a derivation tree.

    Technically, given a context-free grammar, the PDA has a single state, 1, and its transition relation is constructed as follows.

    1. ( 1 , ε , A , 1 , α ) for each rule A α (expand)
    2. ( 1 , a , a , 1 , ε ) for each terminal symbol a (match)

    The PDA accepts by empty stack. Its initial stack symbol is the grammar's start symbol.

    For a context-free grammar in Greibach normal form, defining (1,γ) ∈ δ(1,a,A) for each grammar rule Aaγ also yields an equivalent nondeterministic pushdown automaton.

    The converse, finding a grammar for a given PDA, is not that easy. The trick is to code two states of the PDA into the nonterminals of the grammar.

    Theorem. For each pushdown automaton M one may construct a context-free grammar G such that N ( M ) = L ( G ) .

    The language of strings accepted by a deterministic pushdown automaton is called a deterministic context-free language. Not all context-free languages are deterministic. As a consequence, the DPDA is a strictly weaker variant of the PDA and there exists no algorithm for converting a PDA to an equivalent DPDA, if such a DPDA exists.

    A finite automaton with access to two stacks is a more powerful device, equivalent in power to a Turing machine. A linear bounded automaton is a device which is more powerful than a pushdown automaton but less so than a Turing machine.

    Generalized pushdown automaton (GPDA)

    A GPDA is a PDA which writes an entire string of some known length to the stack or removes an entire string from the stack in one step.

    A GPDA is formally defined as a 6-tuple:

    M = ( Q ,   Σ ,   Γ ,   δ ,   q 0 ,   F )

    where Q , Σ , Γ , q 0 , and F are defined the same way as a PDA.

    δ : Q × Σ ϵ × Γ P ( Q × Γ )

    is the transition function.

    Computation rules for a GPDA are the same as a PDA except that the a i + 1 's and b i + 1 's are now strings instead of symbols.

    GPDA's and PDA's are equivalent in that if a language is recognized by a PDA, it is also recognized by a GPDA and vice versa.

    One can formulate an analytic proof for the equivalence of GPDA's and PDA's using the following simulation:

    Let δ ( q 1 , w , x 1 x 2 x m ) ( q 2 , y 1 y 2 . . . y n ) be a transition of the GPDA

    where q 1 , q 2 Q , w Σ ϵ , x 1 , x 2 , , x m Γ , m 0 , y 1 , y 2 , , y n Γ , n 0 .

    Construct the following transitions for the PDA:

    δ ( q 1 , w , x 1 ) ( p 1 , ϵ ) δ ( p 1 , ϵ , x 2 ) ( p 2 , ϵ ) δ ( p m 1 , ϵ , x m ) ( p m , ϵ ) δ ( p m , ϵ , ϵ ) ( p m + 1 , y n ) δ ( p m + 1 , ϵ , ϵ ) ( p m + 2 , y n 1 ) δ ( p m + n 1 , ϵ , ϵ ) ( q 2 , y 1 )

    Stack automaton

    As a generalization of pushdown automata, Ginsburg, Greibach, and Harrison (1967) investigated stack automata, which may additionally step left or right in the input string (surrounded by special endmarker symbols to prevent slipping out), and step up or down in the stack in read-only mode. A stack automaton is called nonerasing if it never pops from the stack. The class of languages accepted by nondeterministic, nonerasing stack automata is NSPACE(n2), which is a superset of the context-sensitive languages. The class of languages accepted by deterministic, nonerasing stack automata is DSPACE(n⋅log(n)).

    Alternating pushdown automata

    An alternating pushdown automaton (APDA) is a pushdown automaton with a state set

  • Q = Q Q where Q Q = .
  • States in Q and Q are called existential resp. universal. In an existential state an APDA nondeterministically chooses the next state and accepts if at least one of the resulting computations accepts. In a universal state APDA moves to all next states and accepts if all the resulting computations accept.

    The model was introduced by Chandra, Kozen and Stockmeyer. Ladner, Lipton and Stockmeyer proved that this model is equivalent to EXPTIME i.e. a language is accepted by some APDA iff it can be decided by an exponential-time algorithm.

    Aizikowitz and Kaminski introduced synchronized alternating pushdown automata (SAPDA) that are equivalent to conjunctive grammars in the same way as nondeterministic PDA are equivalent to context-free grammars.

    References

    Pushdown automaton Wikipedia