Give a Turing machine program that accepts a language
Informally, we see that state is entered initially. changes the 0 to an , moves right and enters state . As long as in state reads 0's or 's, it goes right and enters when seeing a first 1. Before moving right, it changes this 1 to a . In state , checks if it reads a 1 and, if it is the case, it changes the 1 to a , moves left and enters state . In state , will go left as long as it reads 's or 0's. It changes the first encounters into an , moves right and enters state , so that, in that state, the 0 can be changed into an and a whole cycle is repeated. If after changing a 1 to a , finds no more 0's, then it checks that no more 1's remain and accepts if there are none. Other cases leads the machine to halt without accepting.
Our Turing machine needs to scan only the cells that initially contain the input word. is therefore of space complexity .
Let us assume the input is . During the first cycle, needs to scan one cell to change a 0 to an , cells to find the first 1, 2 cells to change two 1's to two 's and cells to go back. During the th cycle, it scans cells. After cycles, notes all the 0's have been exhausted, and just needs to check that 1's remain on the right (plus one cell to be sure it is a blank). The total number of scanned cells is: