I having trouble constructing NPDAs for these two languages:
$L_1 = \{a^nb^m \mid 2n \le m \le 3n\}$
$L_2 = \{a^nb^mc^k \mid n = m \: or \: m \ne k\}$
Would these be the proper states for the first one?
- $q_0$ – reading $a$’s (initial state)
- $q_1$ – reading $b$’s and popping $A$’s
- $q_2$ – reading $b$’s
- $q_f$ – final state
Would these be the proper states for the second one?
- $q_0$ – reading $a$’s (initial state)
- $q_1$ – reading $b$’s and popping $A$’s
- $q_2$ – reading $b$’s and pushing $B$’s
- $q_3$ – reading $c$’s
- $q_f$ – final state
I do not think I am approaching this properly. This is not non deterministic right? How should I do this?
Hint for (a): I think you need more states than you said. Here's my idea.
Every time the machine reads an
a, it should push a token on the stack. Eventually there will be $n$ tokens on the stack.When the machine starts seeing
bs it should use its finite control to keep count of how many it has seen. After it reads 2bs, it should nondeterministically decide between:b, then resetting the counter to 0 and popping a token from the stack, orb.The computation that chooses (1) every time will empty the stack after reading exactly $3n$
bs; the computation that chooses (2) every time will empty the stack after reading exactly $2n$bs; a computation that chooses some of each will empty the stack after reading some intermediate number ofbs. So if the number ofbs is in the right range, some computation will make the right sequence of choices and empty the stack just as the input ends.