This is an old revision of the document!
Lab 02 - Turing Machines
Key concepts
- How is a Turing Machine (TM) defined?
- What is a configuration?
- How is the execution of a TM defined?
1. Intro
A Turing Machine consists of:
- an alphabet $ \Sigma$
- a set of states $ K$
- an initial state $ q_0$
- a transition function $ \delta : K \times \Sigma \rightarrow K \times \Sigma \times \{L,H,R\}$
- a set of final states $ F \subseteq K$
Which of the following components of an assembly language would best correspond to the above? $ K,\Sigma, \delta, q_0, F$
- the processor
- the memory
- registers
- assembly instructions
1. A few basic Turing Machines
1.1 What does the following TM do?
$ M=(K,\Sigma,q_0,\delta,F)$ where $ K=\{q_0,q_1,q_2\}$ , $ F=\{q_2\}$ , $ \Sigma=\{0,1,\#\}$ and $ \delta$ is defined as below:
| 0 | 1 | # | |
|---|---|---|---|
| $ q_0$ | $ (q_0,1,R)$ | $ (q_0,0,R)$ | $ (q_1,0,L)$ | 
| $ q_1$ | $ (q_1,0,L)$ | $ (q_1,1,L)$ | $ (q_2,,R)$ | 
- (Answers online) What does the following TM do? (bitwise complement)
- (Answers online) Write a TM which accepts only if the input is a binary encoding of a even natural number.
- (Answers online) Write a TM which adds 5 to a number encoded in binary on the tape. The machine will always accept.
- (Answers online) Check if a symbol is present on the tape.
- (Discussion) How would the following algorithm be represented as a Turing Machine:
Algorithm(vector V, integer M) {
   integer s = 0
   for-each x in V
      s += x
   if (x > 1000)
   then  return 1
   else  return 0
}
Helpful questions:
- how should the tape be organised?
- when should the machine accept?
- how wouldforeach x in Vbe implemented?
- how woulds += xbe implemented?
- how wouldif (x > 1000) then … else …be implemented ?
Homework:
- Write a TM which verifies if a string has the same number of ones and zeroes. Give hints - live (what should the machine do?)
- write a TM which accepts a given regular expression
- write a TM which reverses a given binary string (always accepts)