Pushdown automaton for (a^n b^n)^m c^m

2019-08-25 04:20发布

I'm stuck building the transition functions for this automaton.

I suppose I should stack a 1 for each a and unstack it for each b

The number of c's equals the number of ab pairs, so I think I should stack a 0 for each b I encounter. Thing is: how do I unstack 1s and add 0s at the same time?

1条回答
劫难
2楼-- · 2019-08-25 04:53

Don't push a 0 onto the stack each time you encounter a b. Instead, push a 0 onto the stack each time you encounter a b and the stack is empty or the top of the stack is a 0.

So, using your nomenclature for aabbabcc:

read a push 1
read a push 1
read b pop 1
read b pop 1
stack is empty so push 0
read a push 1
read b pop 1 
top of stack is 0 so push 0
read c pop 0
read c pop 0

Stack is empty so we accept this string.

查看更多
登录 后发表回答