【发布时间】:2019-06-25 22:36:03
【问题描述】:
为该语言构建 NPDA: L={w:w∈{a,b}^*,a的个数至少是b的个数}
【问题讨论】:
标签: automata non-deterministic pushdown-automaton
为该语言构建 NPDA: L={w:w∈{a,b}^*,a的个数至少是b的个数}
【问题讨论】:
标签: automata non-deterministic pushdown-automaton
我们的策略可以是这样的:
为什么会这样?如果我们的 a 多于 b,我们最终会在堆栈中得到 a。如果 a 和 b 的数量相同,我们最终会在堆栈上得到 Z。如果 b 比 a 多,我们最终会在堆栈中得到 b。因此,当输入用尽时,我们接受顶部的 a 或 Z。
q e s q' s'
q0 a Z q0 aZ
q0 a a q0 aa
q0 a b q0 -
q0 b Z q0 bZ
q0 b a q0 -
q0 b b q0 bb
q0 - a q1 a
q0 - Z q1 Z
q1 - a q1 -
如果输入字符串的 a 至少与 b 一样多,则此 PDA 以空堆栈结束 q1。
【讨论】:
L = {w:w∈{a,b}^*}
所以在这种情况下,堆栈将从 z 开始,然后压入符号“a”,然后弹出符号“b”。
而且,最小的字符串也是字符串'ab';
So the transitions function in this case would be as follows:
δ(q0, a, z) = (q0, az) => a,z/az
δ(q0, b, a) = (q1, ε) => b,a/ε
δ(q1, ε, z) = (q2, z) => ε/z
Here the state q0 would be the start state and state q2 would be the final state.
【讨论】: