Produce a PDA to recognise the following language : the language of strings containing more a\'s than b\'s
I have been struggling with this
I'm assuming you mean strings of the form a^nb^m
, where n
>m
.
The idea is relatively easy, for a
you push it on the stack (in a loop), for b
you switch to a separate loop to pop a
from the stack. If the stack is ever empty, you give up with a FAIL. If in the first loop you get anything other than a
or b
, or in the second loop you get anything other than b
, you give up with FAIL.
At the end you try to pop another a
and if the stack is empty you give up with a FAIL (ie, you had at least as many b
's as a
's on the stack, possibly more). If not, SUCCESS.
Edit: As a side note, I'm not convinced this is the right site for this question, might be better on programmers. Not sure though so not voting to close.