r/AskComputerScience • u/Lakatos_Tajgetosz • Nov 19 '24
Automata Theory question. How to make a pushdown automata that accepts words that are made of 3 parts, and the 3rd part must contain the inverse of the first part.
So it must accept words that look like this: J-1KL, where J, L ∈ {0,3}* and K ∈ {a, b}*, |J|>0, |k|>0, |L|>0 and L must be a substring of J (anywhere), but they do not have to be the same.
My issue is that let's say we have w: "300a03003", then i push the "300" to the stack, read in the "a".
But then there is an issue. If i read in the rest "03003" and match it to the "003" in the stack, there is an issue, since the first "0" is matching, but then in order to check the second ("3" in the input, "0" in the stack) characters, i have to pop the fisrst "0" from the stack.
But right at this comparism, it will fail, since the second letters do not match, and i already popped the "0" from the stack, so the automata does not store the initial J part anymore.
I feel like i could do this with 2 stacks, but not with only 1.
Any ideas?
2
u/sepp2k Nov 19 '24 edited Nov 19 '24
I'm not sure I understood your problem correctly.
Is the PDA supposed to accept "300a03003" or not? According to your definition, it's not part of the language because the
LK part can't include 0s or 3s, right? So the PDA should reject it, which, if I'm understanding you correctly, it does. So what's the problem?2
u/RIP_lurking Nov 19 '24
Yeah, I don't think it's possible with just one stack. Can you use nondeterminism, though? If yes, then it's easy.
Also, I think you meant that J had to be a substring of L, not the other way around, no?
1
u/Dry_Economics1590 Sep 10 '26
Try „projection“