Problem 5. Fun with Encodings (10 points)
Consider a Turing machine which takes as input a natural number x and repeatedly decrements x (sets x =x -1) until x = 0. We use this simple process to illustrate the impact that the string encoding has on the runtime. To further highlight the differences, we require that when going from x to 0, the Turing machine goes through a series of checkpoints where only (x) is on the tape, then only (x -- 1) is on the tape, and so on until only (1) is on the tape, and finally only (0) is on the tape. Note that other strings may be on the tape in between (i) and (i -- 1), we just need to ensure that each checkpoint is hit.
(a) [2 pts.] First consider using a unary encoding. That is, if x = 5, (x) = 11111. We'll assume x = 0 is represented by a blank tape. Give an algorithm which follows the checkpoints as stated above. Analyze the running time in terms of (1) the length of the encoding of x ((x>|) and (2) the value of x (x).
Solution:
(b) [2 pts.] Now we update the notion of a checkpoint to enforce that the tape head is in the first (leftmost) cell when the encoding of each value is on the tape. Give an algorithm which follows this new notion of checkpoint. Analyze the running time in terms of (1) the length of the encoding of x and (2) the value of x.
Solution:
(c) [4 pts.] Now we consider a binary encoding. That is, if x = 5, (x) = 101. Give an algorithm which follows the original notion of checkpoint used in part (a). Analyze the running time in terms of (1) the length of the encoding of x and (2) the value of x.
Solution:
(d) [2 pts.] State the ordering of the algorithms from parts a, b, and c when measuring runtime in terms of the length of the encoding of x. Then state the ordering of the algorithms from parts a, b, and c when measuring runtime in terms of the value of x
Solution: