Skip to content

CIS 2620 Notes 5.1

Published: at 09:22 PM

Table of Contents

Open Table of Contents

Turing Machines

Let’s take the language AA of palindromes, where Σ=a,b\Sigma = {a, b}. We know that AA is not regular, and it follows that there is no DFA for AA. However, that doesn’t mean we can’t design a machine that solves it. In particular, we can design a turing machine for it.

The components of a turing machine begin with its tape. The tape of a turing machine is an array of cells where each element can hold a symbol from a superset of Σ\Sigma, called the tape alphabet. This tape is potentially unbounded on the right, and plays the role of memory in a modern computer. Initially, the tape holds the input string, and has blanks to the right of it once it reaches the end.

Like a DFA, a TM has finitely many states QQ, one of which is labeled q0q_0. A turing machine also has a head, which is essentially a mobile pointer that points to a tape cell. Initially, the TM is in state q0q_0 and the head points to the left-most tape cell.

Like the DFA, the most important part of the TM are the transitions. A single transition of a TM will have the following structure: based on the current state and symbol read by head, overwrite the current symbol, move the head left/right, and update the state. This way, the machine can go back and forth on the tape, reading and writing cells.

Palindromes

Returning to our palindromes problem, we can think of a pretty simple high level algorithm to figure out whether a string is a palindrome or not:

But we need to consider more than just that: When should we stop while moving back to the left? How do we check that two symbols match?

Let us begin at state q0q_0. If the head reads aa from here, then we replace it with # and move the head one step to the right, and go to state q1q_1. However, if we read bb, we go to state q2q_2.

WLOG, let us say we had an aa. Now, we can skip right until the end of the input, which we know we have reached when we encounter a _\_, at which point we will move left and to a new state q3q_3. From here, if we read a bb, then clearly this is not a palindrome, and we want to reject this string. We therefore send it to qrq_r, which is a rejecting state, which will automatically reject the input.

However, if we read an aa, that means that the palindrome condition is fulfilled up until this point. Therefore, we replace the tape cell with a _\_ and send it to state q4q_4, which will move left skipping over aa and bb until it reads a #, at which point it will go back one right.

Here is a drawing of such a TM. Note that the transitions out of q2q_2 are symmetric to the ones we just described, just for bb instead of aa.

Turing Machine Drawing

Now, we need to think about what our accepting states are. This is a difficult question. If we do a few examples in our head, we can see that odd length strings and even length strings are treated a bit differently.

If we think about an even length string that is a palindrome, we can see that at the point after we have processed the first half of the characters, we will be left with a tape of the format (#)n(_)n(\char35)^n(\char95)^n. Therefore, we can say that at any point, if we read a _\_ from state q0q_0, we know it is a palindrome.

Furthermore, thinking about an odd length string, if the string is a palindrome, we will have it confirmed by the point we reach a tape string of the formal (#)nu(_)n(\char35)^n u (\char95)^n where uu is some character. Unlike the even length example, q0q_0 will continue processing uu as normal. However, we will have set uu to # by then. Therefore, after we start moving to the right trying to find a _\char95, we will reach the _\char95 immediately to the right, and then jump back left to the # we just created. At this point we will be at state q3q_3 or q5q_5. Therefore, we can say that from either of those states, if we read a #, then we can accept this string as a palindrome.

In a TM, there isn’t necessarily a concept of the end of an input string. Therefore, we instead must send the string here to an accepting state called qaq_a which, similar to the rejecting state qrq_r, will accept the string immediately.

Turing machine 2

Turing Machine Components

To recap the turing machine, a turing machine MM consists of: