Search code examples
computationnon-deterministicpushdown-automaton

Understanding the string pushed onto a stack in a NPDA


I'm learning about NPDA, and to be frank, I'm trying to understand what I'm looking at in this problem:

enter image description here

What exactly determined "aaz" or "aaa" being pushed onto the stack? Does it matter, as long as these are getting popped when a b is read?


Solution

  • "aaz" and "aaa" are distinguished since one replaces "z" and the other replaces "a" on top of the stack. Each has the effect of leaving the topmost stack symbol alone and pushing two more a's on top. The NPDA works by pushing two a's on the stack for every a seen, then popping off a single a for every b seen. If the stack ends up empty, you must have seen exactly twice as many b's as a's.