简体   繁体   English

关于 L = {a^nb^(2n) | PDA 的说明 n>=1}

[英]Clarification regarding PDA for L = {a^nb^(2n) | n>=1}

The solution says for every 'a' you read, push 2 a's into the stack .该解决方案说,对于您阅读的每个 'a',将 2 个 a's push 到 stack 中。 Finally when you encounter 'b' , pop an 'a'.最后,当你遇到 'b' 时,弹出一个 'a'。 But won't this give the output as a^nb^n?但这不会将输出作为 a^nb^n 吗? For example: Input = aabbbb On reading the a's , the stack will have four 4 a's , hence on popping one 'a' for every 'b' encountered , won't you get aaaabbbb?例如: Input = aabbbb 在读取 a's 时,堆栈将有四个 4 a's ,因此对于遇到的每个 'b' 弹出一个 'a' ,你不会得到 aaaabbbb 吗?

These a are different.这些a不同的。 One is from the input, another is for the stack.一个来自输入,另一个来自堆栈。 They are probably with different font in your document.它们可能在您的文档中使用不同的字体。 The push-down automaton has a stack.下推自动机有一个堆栈。 In this stack (Last In First Out: LIFO) it remembers information that it uses for guide of how to accept the input: Wikipedia .在此堆栈(后进先出:LIFO)中,它会记住用于指导如何接受输入的信息: Wikipedia

The idea is as follows:思路如下:

  • for every input character a push into the stack two t and move to the next character对于每个输入字符a将两个t推入堆栈并移动到下一个字符
  • for every character b one t from the stack has to be popped.对于每个字符b ,必须从堆栈中弹出一个t
  • constraints: you cannot have a after b , and you need at least one input character约束: b a并且至少需要一个输入字符
  • acceptance: no more input and an empty stack接受:没有更多的输入和一个空堆栈

Here the stack is used to remember how many b to pop: two times more then a .这里堆栈用于remember要弹出多少b :是a的两倍。

The strings which are generated by the given language are:由给定语言生成的字符串是:

L={abb,aabbbb,aaabbbbbb,….} L={abb,aabbbb,aaabbbbbb,….}

Here a's are followed by double the b's这里 a 后面是 b 的两倍

Whenever 'a' comes, push any character here let 't' two times in the stack and if 'a' comes again then the same process is repeated.每当 'a' 出现时,将任何字符推入栈中,让 't' 两次,如果 'a' 再次出现,则重复相同的过程。

When 'b' comes then pop one 't' from the stack each time.当'b' 出现时,每次从堆栈中弹出一个't'。

Finally at the end of the string, if nothing is left in the STACK, then we can declare that language is accepted in the PDA.最后在字符串的末尾,如果堆栈中没有任何内容,那么我们可以声明该语言在 PDA 中被接受。

The PDA for the problem is as follows:该问题的PDA如下:

The transition functions are:转换函数为:

δ(q0, a, Z) = (q0,ttZ)
δ(q0, a, t) = (q0,ttt)
δ(q0, b, t) = (q1,ε)
δ(q1, b, t) = (q1,ε)
δ(q1, ε, Z) = (qf,Z)

Explanation:解释:

Step 1 : Consider the string: "aabbbb" which satisfies the given condition.第 1 步:考虑满足给定条件的字符串:“aabbbb”。

Step 2 : For input 'a' and STACK alphabet Z, push two t's into the stack.第 2 步:对于输入 'a' 和 STACK 字母 Z,将两个 t 压入堆栈。

Step 3 : For input 'a' and STACK alphabet 't', again push two t's into the stack.第 3 步:对于输入 'a' 和堆栈字母 't',再次将两个 t 压入堆栈。 Push the two 't's into STACK: (a,t/ttt) and state will be q0.将两个 't' 推入堆栈: (a,t/ttt) 并且状态将为 q0。 Now the STACK has "tttt".现在堆栈有“tttt”。

Step 4 : For input 'b' and STACK alphabet 't', then Pop one 't' from STACK: (b,t/ε) and state will be q1.第 4 步:对于输入“b”和堆栈字母“t”,然后从堆栈中弹出一个“t”:(b,t/ε),状态将为 q1。

Step 5 : For input 'b' and STACK alphabet 't' and state q1, then Pop one 't' from STACK: (b,t/ε) and state will remain q1第 5 步:对于输入 'b' 和堆栈字母 't' 和状态 q1,然后从堆栈中弹出一个 't':(b,t/ε) 并且状态将保持 q1

Step 6 : For input 'b' and STACK alphabet 't', then Pop one 't' from STACK: (b,t/ε) and state will be q1第6步:对于输入'b'和堆栈字母't',然后从堆栈中弹出一个't':(b,t/ε),状态将为q1

Step 7 : For input 'b' and STACK alphabet 't' and state q1, then Pop one 't' from STACK: (b,t/ε) and state will remain q1第 7 步:对于输入 'b' 和堆栈字母 't' 和状态 q1,然后从堆栈中弹出一个 't':(b,t/ε) 并且状态将保持 q1

Step 8 : We reached end of the string, for input ε and STACK alphabet Z,第 8 步:我们到达字符串的末尾,输入 ε 和 STACK 字母 Z,

Go to final state(qf): (ε, Z/Z)进入最终状态(qf):(ε,Z/Z)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM