Professional Documents
Culture Documents
Lecture #2
Sarmad Abbasi
Virtual University
Theory of Computation
1/1
Lecture 2: Overview
Theory of Computation
2/1
Theory of Computation
3/1
Theory of Computation
4/1
Theory of Computation
5/1
Note that |xy | = |x| + |y |. Hence the length of the concatenation of two
strings is the sum of their individual lengths.
Theory of Computation
6/1
010113 = 010110101101011.
5 = .
110 = 1111111111.
abc 4 = abcabcabcabc.
Theory of Computation
7/1
Theory of Computation
8/1
A = {a, b} then
A3 = {aaa, aab, aba, abb, baa, bab, bba, bbb}.
Theory of Computation
9/1
Theory of Computation
10 / 1
k = 0 1 2 3
k 0
Thus is the set of all the strings over the alphabet . So, for
example, if = {0, 1} then {0, 1} denotes all the strings over the
alphabet {0, 1}. Examples of strings in {0, 1} are:
1
.
101000
11
101001001001001010011011010011101101001001000100001
Theory of Computation
11 / 1
Theory of Computation
12 / 1
Theory of Computation
13 / 1
Note that
1
Theory of Computation
14 / 1
11 Lp .
101 Lp .
10001 Lp .
10 Lp .
Theory of Computation
15 / 1
Consider a language for example Lp which is the set of all strings over
primes. It does not seem to be an easy task to tell if a number is prime.
So, it would be nice to have a machine that can tell us if a number is
prime. The machine can have some input device so that we can enter
a string x and ask it if x is a prime number (written in binary).
Theory of Computation
16 / 1
Theory of Computation
17 / 1
Theory of Computation
18 / 1
We need to specify what are the symbols that the user is allowed
to write on the input tape. In other words, we want to specify the
format in which the input will be given to the machine. This is done
by specifying an input alphabet .
Theory of Computation
19 / 1
Turing Machines
Formally a Turing machine M is a 7-tuple, (Q, , , , q0 , qa , qr ), where
Q, , are all finite sets.
1
Theory of Computation
20 / 1
Turing Machines
1
2
3
The tape is initially empty. The user can write an input only using
symbols of the input alphabet on the tape. The rest of the tape
is left blank. Hence 6 . Which means cannot be a part of
the input. Therefore, when the machine reads the first blank it
knows that the input has ended.
Q is the set of states that the machine can be in.
is the set of symbols that the machine is allowed to write on the
input tape. It can write a blank or any other symbol.
q0 is the start state of the machine. Each time the machine
performs a computation it starts from the start state.
qa is the accept state. When the machine enters qa it declares
that it has accepted the input.
qr is the reject state. When the machine enters qr it declares that
it has rejected the input.
is the transition function. It describes how the machine will
perform its computation.
Theory of Computation
21 / 1
Turing Machines
How does a Turing machine work? We have to understand how does it
take a single step. The transition function defines how it takes a
single step. The Turing machine looks at the current symbol under its
tape head and the state that it is in. Depending on that it decides the
following three things:
1
This is why the transition function has Q as its domain. It tells what
the machine should do in all possible situations.
The range of the transition function is Q {L, R}. Therefore, it
specifies all the three decisions that the machine has to make.
Theory of Computation
22 / 1
Theory of Computation
23 / 1
Turing Machines
The transition function is given by the following table.
state symbol next state replace with move
q0
0
qa
0
R
q0
1
qr
1
R
q0
qr
R
qa
0
qa
1
qa
qr
0
qr
1
qr
Why have we not specified many entries. That is because, they are
irrelevant. When the machine enters qa it accepts the input. When the
machine enters qr it rejects the input. Hence from these two states no
further computation happens.
Sarmad Abbasi (Virtual University)
Theory of Computation
24 / 1
Turing Machines
Let us look at what this machine will do on various inputs.
1
Theory of Computation
25 / 1
Turing Machines
This Turing machine will accept all the strings that start with a 0. Since
from the start state it goes to either the accept state or the reject state.
Hence, it only reads the first symbol of the input before accepting or
rejecting.
Theory of Computation
26 / 1
Theory of Computation
27 / 1
Turing Machines
The transition function is given by the following table.
state symbol next state replace with move
q0
0
q1
0
R
q0
1
q1
1
R
q0
qr
R
q1
0
q1
0
R
q1
1
q1
1
R
q1
q2
L
q2
0
qr
0
R
q2
1
qa
1
R
q2
qr
R
One again we have not specified what the machine does when it
reaches qa or qr . Let us see what this machine does.
Theory of Computation
28 / 1
Turing Machines
Let us look at what this machine will do on various inputs.
1
Theory of Computation
29 / 1
Turing Machines
Theory of Computation
30 / 1
Configurations
What will happen if we give 00101 as an input to M2 . We can
represent its initial configuration with
q0 00101
This means the machine is in the state q0 reading the symbol that is to
its left. The tape contents are 00101. Next it goes into state q1 and
moves right we can represent this by
0q1 0101
This means it is in state q1 reading a 0. The tape contents can be
easily obtained by ignoring the state in the configuration. Again since
2 (q1 , 0) = (q1 , 0, R) the head moves to the right so we get the next
configuration which is
00q1 0101
Sarmad Abbasi (Virtual University)
Theory of Computation
31 / 1
Configurations
Actually we realize that the tape head will keep moving to the right
without changing the contents till it reaches a blank. This is because,
2 (q1 , 0) = (q1 , 0, R) and 2 (q1 , 1) = (q1 , 1, R).
Hence the machine will eventually reach the configuration
00101q1
at this point the tape head is reading a blank. Now, if we look up the
transition function we observe that
2 (q1 , ) = (q2 , , L)
So the head has to move to the left now. Hence the machine goes into
the configuration
0010q2 1
and since 2 (q2 , 1) = (qa , 1, R) the machine eventually reaches
00101qa
and accepts this string.
Sarmad Abbasi (Virtual University)
Theory of Computation
32 / 1
Configurations
Can you tell which strings will be accepted by this Turing machine?
Yes, it accepts all strings that end with a 1. We can see this by
examining the transition function again.
Theory of Computation
33 / 1