简体   繁体   中英

PDA for {a^n b^m | n<=m<=2n}

Can someone help me design PDA for {a^nb^m | 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. 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. Then, make the PDA accept if the input is exhausted and the stack is empty.

  • if you always choose to pop one stack symbol for each b read, then you get m = n
  • if you always choose to pop one stack symbol for every pair of b read, then you get m = 2n
  • if you sometimes choose to read one b and sometimes two, then you end up with n < m < 2n; n < m because sometimes you read more b than you had stack symbols for, m < 2n because sometimes you only read one b and popped from the stack

NPDAs accept if at least one path ends up accepting; 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. It should be clear that for any value of m such that n <= m <= 2n, there is a solution to the linear system:

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. We can subtract the 2nd from the 1st:

y = m - n

Because y must be nonnegative, we get our first condition, 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.

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.

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