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

浪子不回头ぞ 提交于 2020-01-06 04:46:10

问题


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:


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.



来源:https://stackoverflow.com/questions/2082438/pushdown-automaton-for-an-bnm-cm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!