2

What would the state diagram look like for a Turing Machine that computes the next string in lexicographical order over alphabet Σ = {1, 2, 3}? String size is 4, i.e ---1, ---2, ---3, --11, --12, etc...

Already tried figuring it out from Michael Sipser's Introduction to Theory of Computation with no luck. Also tried to look it up online, again with no luck.

Thanks in advance!

1 Answers1

1

If I have understood correctly, you want a TM to take as input a string over {1, 2, 3} of length up to four, and to overwrite this number with the string over the same alphabet which comes next in lexicographic order. Here is a strategy for this problem.

  1. move right three times so we're looking at the fourth symbol on the tape.
  2. if this is blank, our input is malformed and we die. otherwise, if the symbol is 1, write 2 and halt-accept; if 1, write 2 and halt-accept; if 3, write 1 and move left in state "carry2"
  3. if this is blank, 1 or 2, write 1, 2 or 3, respectively, and halt-accept. if 3, write 1 and move left in state "carry3"
  4. if this is blank, 1 or 2, write 1, 2 or 3, respectively, and halt-accept. if 3, write 1 and move left in state "carry4"
  5. if this is blank, 1 or 2, write 1, 2 or 3, respectively, and halt-accept. if 3, the input was the number 3333 and there is no lexicographically larger 4-digit string over {1, 2, 3}… so either crash or wrap and write ---1 to the tape.

Note that this does not verify the tape contents are sane... since we are using blanks to encode "missing" high-order digits we can just reasonably assume there's nothing after position 4 on the tape (defining what our TM does carefully to avoid implying we did anything after there). Furthermore, we are not sanitizing the front, so mixing symbols and blanks improperly could be an issue... so we could either run some steps first to validate the input or just require the input be well-formed when we get it.

Patrick87
  • 27,682
  • 3
  • 38
  • 73