Reputation: 47
I have been trying making a Turing machine graph recognizing the language :
{(ab)^n(ba)^n | n >0}
How to build the Turing machine graph for the above-mentioned language?
Upvotes: 0
Views: 150
Reputation: 350821
I would start removing pairs of characters from the outer sides of the input inwards:
Now you can either walk back to the extreme left and repeat, or you can perform the above procedure in reverse (so that you make use of the reversed traversal to also remove some stuff):
Then repeat from the top.
Here is a runnable implementation of that idea:
createTuring({
transitions: [
{ state: "start", read: "_", move: "R", nextState: "accept" },
{ state: "start", read: "a", write: "_", move: "R", nextState: "leftb2" },
{ state: "start", read: "b", move: "R", nextState: "reject" },
{ state: "leftb2", read: "b", write: "_", move: "R", nextState: "goright" },
{ state: "leftb2", read: "a_", move: "R", nextState: "reject" },
{ state: "goright", read: "ab", move: "R", nextState: "goright" },
{ state: "goright", read: "_", move: "L", nextState: "righta" },
{ state: "righta", read: "a", write: "_", move: "L", nextState: "rightb" },
{ state: "righta", read: "b_", move: "L", nextState: "reject" },
{ state: "rightb", read: "b", write: "_", move: "L", nextState: "righta2" },
{ state: "rightb", read: "a_", move: "L", nextState: "reject" },
{ state: "righta2", read: "_", move: "L", nextState: "accept" },
{ state: "righta2", read: "a", write: "_", move: "L", nextState: "rightb2" },
{ state: "righta2", read: "b", move: "L", nextState: "reject" },
{ state: "rightb2", read: "b", write: "_", move: "L", nextState: "goleft" },
{ state: "rightb2", read: "a_", move: "L", nextState: "reject" },
{ state: "goleft", read: "ab", move: "L", nextState: "goleft" },
{ state: "goleft", read: "_", move: "R", nextState: "lefta" },
{ state: "lefta", read: "a", write: "_", move: "R", nextState: "leftb" },
{ state: "lefta", read: "b_", move: "R", nextState: "reject" },
{ state: "leftb", read: "b", write: "_", move: "R", nextState: "start" },
{ state: "leftb", read: "a_", move: "R", nextState: "reject" },
],
initState: "start",
tape: "ababababbabababa",
});
<script src="https://trincot.github.io/turing.js"></script>
The above used transition table has explicit transitions to a reject state if the input does not match the pattern. If you are happy with a rejection that consists of just halting in any state that is not an accept state, you can remove those transitions from the table.
Upvotes: 0
Reputation: 28312
I'll leave defining states as an exercise but if you need help with that I can revisit this answer later. As a hint - you will need either one or a couple of states to handle each of the above steps.
Upvotes: 1