Single state PDA for $L = \{ a^nb^n \mid n\ge 0 \}$

824 Views Asked by At

I've read in various threads on stack exchange as well as other webpages that every CFL has a corresponding PDA with just one state. I've studied PDA from Peter Linz's Automata book. However there is no mention of a single state PDA. In the text, they have mentioned a method for 3 state PDA and in the exercises they have reduced it to 2 states.

For a single state, I've come up with the idea of using multiple initial symbols on the stack so that I can simulate two different states in a single state in the following way:

Initially stack contains $xy$.

$\delta (a,xy,ay)$ #with $x$ gone from stack, a langauge such as $a^nb^na^mb^m$ won't be accepted.

$\delta (a,a,aa)$

$\delta (b,a,\lambda)$

Accept if we get the $y$ on stack at the end of the input. I don't know if such assumptions and operations are allowed on a PDA. In any case, how do I represent the above language in a single state PDA?

Regarding accessing two elements from top prior to any operation: I would think of $\delta(a,xy,ay)$ as $\delta(a,x,M)$, $\delta(y,M,N)$, $\delta(a,N,ay)$.

1

There are 1 best solutions below

3
On

In the definition of a PDA with one state, you can read only the top most element of the stack. Thus you cannot read $xy$ in your first transition. (it is actually equivalent but unless you state it the PDA read only 1 element).

Moreover I don't see how the xy allow you to disregard for example $a^2b^1a^3b^4$?

Forget your $y$. Say that the initial stack symbol is $x$. You want to remember the number of a you read before reading the same number of $b$. what you can do is: when your read a $a$ and $x$ is on the top of the stack push a $A$ and $x$ on top of it. You can do that with a transition $\delta(a,x,xA)$.

At some point you choose non deterministically that you read the last $a$, so you don't push $x$ again. You have the transition $\delta(a,x,A)$.

Now you have a stack containing only $A$'s and you just have to pop them each time you see a $b$. hence $\delta(b,A,\lambda)$.

Accept with the empty stack.

Notice that you cannot read $b$ when $x$ is on top, hence you always start be reading multiple $a$. Also you cannot read $a$ when $x$ is not on top, hence after the last $a$ you read only $b$.