![](/img/trans.png)
[英]construct a pushdown automata for L={a^mb^n where n<=m<=2n}?
[英]How to construct a pushdown automata for L={a^nb^m where n<=m<=2n}?
它應該在不使用 2 個堆棧的情況下構建。 我試過了,但如果沒有 2 個堆棧,我就無法做到。
策略如下:我們可以很容易地制作一個接受 a^nb^n 的 PDA,我們也可以很容易地制作一個接受 a^nb^2n 的 PDA。 我們的語言是這些語言的超集,它也接受 n 到 2n 之間的任何 b 數。 我們可以利用非確定性來實現這一點,如下所示:對於我們放入堆棧的每個 a,我們可以在彈出 a 之前不確定地決定是消耗一個還是兩個 b。 如果我們的 NPDA 選擇每次消耗一個,我們得到 a^nb^n。 如果它選擇每次消耗兩個,我們得到 a^nb^2n。 如果它選擇兩者中的一些,我們會在這些極端之間得到一些 b。 只有當我們用空堆棧耗盡輸入時,我們才會接受。
Q s S Q' S' Comment
q0 e e qA e Allow empty string to be accepted
q0 a x q0 ax Count a and push onto stack
q0 e x q1 x Transition to counting b
q1 b ax q1 x Mark off a single b for each a
q1 b ax q2 x Mark off the first of two b for this a
q1 e e qA e Allow string in language to be accepted
q2 b x q1 x Mark off the second of two b for this a
在這個 PDA 中,我們將q0
作為初始 state,將qA
作為接受 state。 在aabbb
上處理:
q0, aabbb, e
-> q0, abbb, a
-> q0, bbb, aa
-> q1, bbb, aa
-> q1, bb, a
-> q2, b, e
-> q1, e, e
-> qA, e, e
當然,有許多解析不會導致 qA,但在 NPDA 中,如果至少有一個,我們會接受。
此圖像包括該語言的圖形下推自動機
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.