简体   繁体   中英

PDA for L = {a^nb^m : m ≥ n, m-n is even}

Design a PDA for the following language

L = {a^nb^m : m ≥ n, mn is even}.

Let's start with a PDA for a^nb^m where m >= n. A PDA can push an a to the stack for every a it sees, pop ab for every b it sees, and if it runs out of b while there are still a on the stack, it rejects.

Now, what else do we need to do to exclude the case where m - n is odd? Well, m - n is odd means we have some b left over in the input. We can simply modify our accepting state so that on further b, it moves to a new state (encoding odd b) and then back to the accepting state on the next b, encoding the requirement that the residual b must be even.

A full PDA might look like this:

q    s    S    q'    S'
q0   a    Z    q0    aZ
q0   a    ax   q0    aax
q0   b    Zx   q2    Z
q0   b    ax   q1    x
q1   b    ax   q1    x
q1   b    Z    q2    Z
q2   b    Z    q1    Z

Check that to see if it works, there might be some bugs. The way to read this is:

From state q, on input s, with stack configuration S, the PDA can transition to state q' and update the stack configuration to S'.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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