A pushdown automaton (PDA) is an automaton that extends a finite state machine by adding memory in the form of a stack. It can interpret context-free grammars.
Recall that the main limitation of FSAs is that they are memoryless, that is, they cannot count or keep any past information from previous states. PDAs aim to fix this by allowing a stack with unlimited memory. The restriction now is that memory can only be access in a LIFO (last in first out) order.
Like finite state automata, a PDA can be both deterministic (DPDA) or non-deterministic (NPDA), however, the most commonly used one is the non-deterministic version. This because, unlike finite automata, which have non-deterministic versions being equally as powerful as deterministic version, a non-deterministic PDA is strictly more powerful and a deterministic PDA. Equivalently, there are some NPDAs for which there is no equivalent DPDA.
Definition
Non-deterministic Pushdown Automata (NPDA) ^definition-dfa
A (non-deterministic) PDA is defined as a 6-tuple:
- = An input alphabet
- = The stack alphabet, which can be different from .
- A set of states,
- An initial state,
- A state transition function, which takes the current state (), the next character of the input string () and the symbol on the stack head (), to return another state (, and optionally pushes to the stack:
- A set of accept states,
Behaviour
- A PDA checks both the current symbol in the input string and the current symbol on the stack top (head). Hence, if either of them are not-defined in the transition function for the current state, the PDA automatically rejects the string.
%%🖋 Edit in Excalidraw, and the light exported image%%
- The stack can be non-empty when the machine ‘halts’ (accepts or rejects).
Stack Transitions
If we look at the rightmost argument of the transition function and the optional that gets pushed to the stack:
- So the PDA scans for . If it sees at the top of the stack, it gets popped off and then gets pushed on to the stack
Epsilon Transitions
We can also use to not pop off or push
- adds to the stack without removing anything off.
- removes without adding anything to the stack
%%🖋 Edit in Excalidraw, and the light exported image%%
Keeping Count
Remember how finite automata are memoryless?, that is, they cannot remember any past states. For example, a finite automata can recognise the language by explicitly checking each character (using 6 states). It cannot however, recognise the language , because by the time it gets to the 1’s, it has ‘forgotten’ how many zeroes were there before, so it cannot properly match the number of zeroes with the number of ones.
A PDA can use its stack to keep count of things, kind of. It cannot actually store a variable that increments, but it can match items. For example, take the language . To accept such a language, a PDA needs to be able to find equal amounts of 0’s and 1’s. We can do this by pushing 1’s onto the stack, and then whenever we encounter a 0, pop off a 1. If we end up with the stack being empty, we have an equal number of zeroes and ones.
To check if a stack is empty, we add a sentinel value at the beginning (this is because the stack alphabet can be different from the tape/input alphabet). Here, I’ve decided to use \$$ but the symbol can be anything. Then, just before the accept state, we check if the $$ is left in the stack.
%%🖋 Edit in Excalidraw, and the dark exported image%%
Conversion From CFG To PDA
#todo Lecture 19
Theorems
Example
PDA that recognises
Find a PDA for the language below:
Solution
%%🖋 Edit in Excalidraw, and the light exported image%% This PDA works by adding 's to the stack, and then removing one for each it encounters after. The very first state is an accept state so that it can accept (given in when )
Resources
- A two-stack PDA is actually equivalent to a Turing Machine. See https://stackoverflow.com/questions/62083942/can-a-pda-with-two-stacks-accept-re-language#tosee okay, but if a NTM is as strong as a TM, but a NPDA is stronger than a DPDA, why does adding a second stack make the NPDA ‘weaker’?