Professional Documents
Culture Documents
Lecture #3
Sarmad Abbasi
Virtual University
Theory of Computation
1 / 40
Lecture 3: Overview
Theory of Computation
2 / 40
Turing Machines
Let us once again make sure we understand what a Turing machine is?
Formally a Turing machine M is a 7-tuple, (Q, , , , q0 , qa , qr ), where
Q, , are all finite sets.
1
Theory of Computation
3 / 40
Theory of Computation
4 / 40
Turing Machines
Let us intuitively see what each state is doing. Let us look at q0 . When
the machine is in q0 represents the fact that the last scanned symbol
was not a 1. Note that
(q0 , 0) = (q0 , 0, R)
so if the machine reads a 0 it simply stays in the state q0 and moves
right (without changing the input). However, when the machine sees a
1 it changes its state to q1 as
(q0 , 1) = (q1 , 1, R).
When the machine is in the state q1 that represents the fact that the
last scanned symbol was a 1. Thus if the machine is in the state q1
and sees a 1 it stays in q1 and if it sees a 0 it goes back to q0 .
(q1 , 0) = (q0 , 0, R) and (q1 , 1) = (q1 , 1, R)
Sarmad Abbasi (Virtual University)
Theory of Computation
5 / 40
Turing Machines
Theory of Computation
6 / 40
Theory of Computation
7 / 40
State Diagrams
Clearly, mark the initial state, the accept and the reject state. In
this course we will always mark the accept state with qa and reject
state with qr .
For each state (other than the accept and reject states) there
should be as many arrows coming out of the state as there are
symbols in the work alphabet.
Theory of Computation
8 / 40
Configurations
Its state.
It head position.
Theory of Computation
9 / 40
Configurations
We will represent a configuration in a very special way. Suppose is
the tape alphabet. Let u, v and q be a state of the Turing
machine. Then the configuration
uqv
denotes
1
It is assumed that the tape contents are all blanks after the last symbol
of v .
Let us look at some examples:
Theory of Computation
10 / 40
Configurations
Let us see the following picture.
The machine is in state q7 . The tape contents are 101101111 and the
tape head is currently reading the fifth symbol with is a 0.
So in this case, the first four symbols constitute of u and the last five
symbols constitute of v . So, this configuration will be written as
1011q7 01111
Theory of Computation
11 / 40
Configurations
Now, let us go the other way. Suppose I tell you that a machine is in
configuration
0abbaq3 bba01
Can you draw a picture? The tape contents are easily recovered by
ignoring the state in the configuration. So, the tape contents are
0abbabba01 and the machine is in state q3 . Lastly, it is reading the 6th
symbol on the tape.
Theory of Computation
12 / 40
Configurations
Theory of Computation
13 / 40
Configurations
Theory of Computation
14 / 40
Theory of Computation
15 / 40
Theory of Computation
16 / 40
Theory of Computation
17 / 40
Theory of Computation
18 / 40
Theory of Computation
19 / 40
Theory of Computation
20 / 40
Summary:
uaqi bv yields uqj acv
if (qi , b) = (qj , c, L).
and
uaqi bv yields uacqj v
if (qi , b) = (qj , c, R).
Theory of Computation
21 / 40
Theory of Computation
22 / 40
Theory of Computation
23 / 40
Theory of Computation
24 / 40
each Ci `M Ci+1 .
Ck is an accepting configuration.
Theory of Computation
25 / 40
Language accepted by a TM
Theory of Computation
26 / 40
Language accepted by a TM
Theory of Computation
27 / 40
Language accepted by a TM
Theory of Computation
28 / 40
Language accepted by a TM
Theory of Computation
29 / 40
Language accepted by a TM
Does a TM only accept or reject inputs? No. Lets consider M 0 :
Theory of Computation
30 / 40
Language accepted by a TM
Theory of Computation
31 / 40
Language accepted by a TM
We have
L(M) = {x{0, 1} : x ends with a 0}.
L(M 0 ) = {x{0, 1} : x ends with a 0}.
Both accept the same language. However, the first machine M will
reject all inputs which do not end with a 0. Whereas, M 0 will go into a
infinite loop on all such inputs.
We prefer M to M 0 .
Theory of Computation
32 / 40
Language accepted by a TM
Theory of Computation
33 / 40
Designing TMs
Theory of Computation
34 / 40
Designing TMs
Let = {0}.
n
L2 = {02 : n 0}.
We want to design a TM M2 such that
L(M2 ) = L2 .
Hence we want a TM M2 that accepts all the inputs in L2 .
In order to solve this problem we must first understand the language
L2 .
L2 = {0, 00, 0000, 00000000, 0000000000000000, . . . , }
Theory of Computation
35 / 40
Designing TMs
To design a TM we must have a plan in mind. How will we solve this
problem? Note that a TM can only have finite number of states and
therefore it cannot remember much. It does not even know how to
count (unless you teach it).
If I have some number of 0s and I cross each alternate one I will cut
the number of 0s into half.
Informal description of the M2 .
1
Sweep from the left to the right crossing off each other 0.
If there were more then one 0s and the number was odd, reject.
Theory of Computation
36 / 40
Designing TMs
Theory of Computation
37 / 40
Designing TMs
Theory of Computation
38 / 40
Designing TMs
Theory of Computation
39 / 40
Designing TMs
Theory of Computation
40 / 40