# Turing machines

Why is Alan Turing often described as the father of Computer Science? Watch Marc Scott explain the significance of the Turing machine.
0.2
In this step, we’re going to have a look at Turing machines, which were hypothetical computers invented by Alan Turing in 1936. A Turing machine consists of an infinitely long tape. This tape is divided up into cells, and into each cell can be written a 1, a 0, or an empty space. Above the tape is a head that can either move left, right, and read the symbols written in the cells. The head is also capable of erasing and writing new values into the cells. The direction the head moves, which values it erases, and which values it writes in is dependent on a of instructions provided to the machine.
45.4
Here, the head is in state 2, and the instructions say that if it reaches 0, then erase it, write in a 1, move one cell to the right, and change your state to 5.
60.7
State 5 might read, if I’m reading a 1, erase it, write in a 0, and move one cell to the left, and change the state to 7. It seems incredible, but with such a simple system, Alan Turing proved that any problem that is computable can be computed by a Turing machine. So let’s build a Turing machine and see what this looks like. We’ve got our tape, our head, some initial instructions, and we’ll place some 1’s and 0’s on our tape to begin with. Now, the first symbol is a 0, and the instructions say that when reading a 0, it should write a 1 and move left.
102.1
Moving left, it then reads a 1, which, according to the instructions, means it should write a 0 and move left. It then reads another 1, writes a 0, and moves left. And finally, reads a blank, at which point the program halts. So this Turing machine is designed to flip bits. It changes 0’s to 1’s and 1’s to 0’s. The instructions for this Turing machine only had one state, but more complex Turing machines can be built using multiple states. Let’s have a look at one of these now. We start in state A, with a head position underneath the first symbol.
145
Looking at the instructions, we see that in state A, with a symbol of 0, there’s no write, and the head should move to the right, and the Turing machine should remain in state A. Next it reads a 0 and moves to the right, then reads a 1 and moves to the right again. Now it’s reading a blank, which means it moves to the left, but it also changes to state B. Looking at the instructions for state B, if it’s reading a 1, it erases it and writes a 0, and then moves left, staying in state B. Next it reads a 0, which means it writes a 1, moves left, and switches to state C.
184.8
In state C, there were no write actions to be done. The head just keeps moving right until it eventually reaches a blank, at which point it moves left, and the program halts. Now it’s your turn to have a go. Get yourself a piece of paper, a pencil, and an eraser, and copy out the tape, the head, and the numbers as you see them on the screen. Then run the instructions two more times and see if you can figure out what this Turing machine does. Help each other out, and share your answers in the comment section.
While Babbage and Lovelace can be considered the parents of computers and programming, Alan Turing is often called the father of computer science. During the war effort, Turing worked on cracking encrypted messages used by the German armed forces, and helped design machines to make this possible.
It was when working on a mathematical problem concerning Decidability and The Halting Problem, though, that Turing realised he needed a mathematical description of a machine that could solve algorithms. These machines came to be known as Turing machines, and you are going to take a closer look at them in this step.
A Turing machine consists of an infinitely long tape, which has been divided up into cells. Each cell can contain either a 1, a 0, or an empty space. Above one cell of the tape is a head, which can either move left or right, and can read the symbols written in the cells. The head is also capable of erasing symbols and writing new symbols into the cells.
The direction that the head moves, which values it erases, and which values it writes in, are dependent on a set of instructions provided to the machine.
In the machine shown below, the head is in state 2, and the instructions say that if it reads a 0, then erase it, write in a 1, move one cell to the right and change your state to 5. (There’ll also be instructions in the case it reads a 1.)

## 4.7

57 Reviews
State 5 might say, if you’re reading a 1, erase it, write a 0, and move one cell to the left. Then go to state 7.
It seems incredible, but Alan Turing proved that any problem that is computable can be computed by a Turing machine using this simple system.
Now you are going to build a Turing machine and see how that might work.
You have your tape, your head, some initial instructions, and you will place some 1s and 0s on your tape to begin with.
The first symbol seen by the head is a 0, and the instructions say that when reading a 0, it should write a 1 and move left.
Moving left, it then reads a 1, which according to the instructions means it should write a 0 and move left.
It then reads another 1, writes a 0 and moves left, and finally reads a blank at which point the program halts.
So this Turing machine is designed to flip bits. It changes 0s to 1s and 1s to 0s.
The instructions for this Turing machine only had one state, but more complex Turing machines can be built using multiple states. You are going to have a look at one of these now.
You start in state A, with the head positioned underneath the first symbol. Looking at the instructions, you will see that in state A, with a symbol of 0, there’s no write instruction, the head should simply move to the right, and the Turing machine should remain in state A.
Next, it reads another 0 and again moves to the right. Then, it reads a 1, and moves to the right again. Now, it reads a blank, which means it’s got to move to the left, but it also changes to state B.
Looking at the instructions for state B, if it’s reading a 1, it erases it and writes a 0, and then moves left, staying in state B. Next, it reads a 0, which means it writes a 1, moves left and switches to state C.
In state C, there are no write actions perform. The head just keeps moving right until it eventually reaches a blank, at which point it moves left and the program halts.
Now it’s your turn to have a go. Get yourself a piece of paper, a pencil, and an eraser, and copy out the tape, the head, and the numbers exactly as you see them on the screen. With the machine in this state, run through the instructions again, and then once more. See if you can figure out what this Turing machine does.

Created by