Reputation: 31
Can someone help me design PDA for {a^n b^m | n<=m<=2n}. Can you please design one with explanation.
Upvotes: 3
Views: 4744
Reputation: 330
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.
Upvotes: 0
Reputation: 28312
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.
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.
Upvotes: 7