What is a pushdown automaton?
A pushdown
A PDA's components
A PDA consists of three main components:
- An input string or tape
- A finite control unit
- A stack for memory
The stack has two functions: push and pop. At every step, the PDA makes a decision to push an element from the input, or pop an element from the stack. The stack contains a starting/stopping symbol ($ or Z) that indicates the end of a stack.
A PDA is a 7-tuple automata
: A set of states : A set of input symbols : A set of the stack elements : An initial state : A transition function, that is, the condition that allows the state to change : The initial/end stack element : A set of final states
Transition notations in PDA
There are several notations to show transitions. The following graph shows one of these transition notations in PDA:
Where
is the top two elements of the stack in the case of a push operation - ^ specifies to pop, the topmost element of the stack
Note: It is not necessary to consume the input to move to another state. We can also make a transition non-deterministically (a null transition) where
is ^.
Turnstile notations
The turnstile notation shows a transition without a graph. It uses instantaneous description (ID) to do so.
IDs include
is the state is the remaining input is the stack contents
For example,
In this transition, the state changes from
Examples
Let's see a few examples to clarify things further:
Palindromes
We can't specify
Let's suppose
The PDA above is a non-deterministic PDA that can make a null or epsilon transition. Here, the PDA keeps pushing the elements into the stack.
In the case of an even palindrome, it stops until the first half of the input is consumed. In the case of an odd palindrome, it looks for element
The PDA then compares the input with the stack elements and pops them if it finds a match. At the end of the input, if the stack only contains
The or condition
We now look at a slightly complex example.
Let's suppose the following:
As the language contains an or condition, the states change non-deterministically. That is, the
In the path above, the number of
- The
s are pushed on the stack one by one, and popped against the s. - If the stack becomes empty, even though
s are left in the input or s remain in the stack, the string is accepted. - The
s are just consumed without any action, as they are irrelevant to these types of strings.
In the path below, the number of
- The
s are pushed on the stack one by one, and the s are consumed without any action or change to the stack. This is because these are irrelevant to the strings. - As the input reaches the
s, the s are popped against the s. It checks whether the s are left in the input, or if the s remain in the stack. If so, the string is accepted.
Free Resources