[英]PDA for {a^n b^m | n<=m<=2n}
Can someone help me design PDA for {a^nb^m |有人可以帮我为{a^nb^m | 设计PDA吗? n<=m<=2n}.
n<=m<=2n}。 Can you please design one with explanation.
你能设计一个解释一下吗?
The idea here is this: read every a and push a symbol onto the stack for each one.这里的想法是:读取每个 a 并将一个符号压入堆栈。 Then, when you start reading b's, at each step, nondeterministically choose whether to read a single b and pop one stack symbol, or whether two read two b's and pop one stack symbol.
然后,当您开始读取 b 时,在每一步中,不确定地选择是读取单个 b 并弹出一个堆栈符号,还是读取两个 b 并弹出一个堆栈符号。 Then, make the PDA accept if the input is exhausted and the stack is empty.
然后,如果输入已用完且堆栈为空,则使 PDA 接受。
NPDAs accept if at least one path ends up accepting;如果至少一条路径最终接受,则 NPDA 接受; so, as long as some pattern of guessing to read one or two b's for each stack symbol gets the right value of m, the string is accepted.
因此,只要某种猜测模式为每个堆栈符号读取一个或两个 b 得到正确的 m 值,就可以接受该字符串。 It should be clear that for any value of m such that n <= m <= 2n, there is a solution to the linear system:
应该清楚的是,对于任何 m 值,使得 n <= m <= 2n,线性系统有一个解:
x + 2y = m
x + y = n
Here, x is the number of times the NPDA should guess that it reads one b, and y is the number of times the NPDA should guess that it reads two b's.这里,x 是 NPDA 应该猜测它读取一个 b 的次数,y 是 NPDA 应该猜测它读取两个 b 的次数。 We can subtract the 2nd from the 1st:
我们可以从第一个中减去第二个:
y = m - n
Because y must be nonnegative, we get our first condition, n <= m.因为 y 必须是非负数,所以我们得到第一个条件,n <= m。 Plugging this back into the 2nd origination equation gives:
将其代入第二个起源方程给出:
x + m - n = n
<=> x = 2n - m
Again, because x must be nonnegative, this gives our second condition, m <= 2n.同样,因为 x 必须是非负数,这给出了我们的第二个条件,m <= 2n。
Nondeterministically, push one or two a
s into the stack in each reading of an a
and then match the incoming b
s with the pushed a
s.不确定地,在每次读取
a
a 时将一个或两个a
推入堆栈,然后将传入的b
与推入a
匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.