所以这就是我所困的地方,我必须构造一个PDA,该PDA接受条件为n(a)小于或等于2n(b)的来自{a,b} *的单词
答案 0 :(得分:0)
Put yourself into the frame of mind of a pushdown automaton. All you know how to do is read input and the stack, and then push/pop and change state based on what you see. If you start reading a string and need to tell whether it's in the language, what can you do?
It seems to me the best we can do starting out is to remember how many a
s we are reading. Until we see b
s, there's no reason to do anything else. That is, simply read a
s and push them on the stack. The following rules should suffice:
Q i s Q' s'
-- -- -- -- --
q0 a Z q0 aZ
q0 a a q0 aa
Now, what happens when we see a b
? If we want at least twice as many b
s as a
s, we can't just cross of a
s for each b
, since that would give at least as many b
s as a
s but not at least twice as many.
What if we cross off two a
s for each b
? Well, that gives us at least half as many b
s as a
s, which is the wrong direction. This suggests crossing off one a
for every two b
s, which turns out to be correct. The rules:
Q i s Q' s'
-- -- -- -- --
q0 b a q1 a
q1 b a q2 -
q2 b a q1 a
Note we created a new state q2
which has one rule in common with q0
but not the ones for reading a
s. Indeed, once we start reading b
s, we don't want to allow any more a
s to be read. Leaving out the rules will crash the automaton and reject the string.
If we have exactly twice as many b
s as a
s, we will end up in state q2
with no more input and an empty stack. If we have additional b
s, we need a rule to allow them. It suffices to add a self loop on state q2:
Q i s Q' s'
-- -- -- -- --
q2 b Z q2 Z
Taken together, these states and transitions should be pretty close to a working PDA for your language. Other options would have been to write a CFG first and then apply an algorithm to convert the CFG to a PDA, for example, a top-down or bottom-up parser.