0% found this document useful (0 votes)
97 views

Theory of Computation: Lecture #4

The lecture discusses Turing machines and their design. It provides examples of Turing machines that recognize different languages. These include languages like {w#w}, {ai bj ck: k = i x j} and {#x1#x2...#xl: xi are distinct strings}. High-level descriptions of Turing machines are given for these languages and how they work is explained. The concepts of configurations and multiple tape Turing machines are also introduced.

Uploaded by

Hasnain Haider
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
97 views

Theory of Computation: Lecture #4

The lecture discusses Turing machines and their design. It provides examples of Turing machines that recognize different languages. These include languages like {w#w}, {ai bj ck: k = i x j} and {#x1#x2...#xl: xi are distinct strings}. High-level descriptions of Turing machines are given for these languages and how they work is explained. The concepts of configurations and multiple tape Turing machines are also introduced.

Uploaded by

Hasnain Haider
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Theory of Computation

Lecture #4

Sarmad Abbasi

Virtual University

Sarmad Abbasi (Virtual University) Theory of Computation 1 / 26


Lecture 4: Overview

Quickly recall the definition of a Turing machine.


Look at some more examples of Turing machines.
Define the concept of a configuration.
Define what the language accepted by a TM.

Sarmad Abbasi (Virtual University) Theory of Computation 2 / 26


Designing TMs
Last time we looked at the language
n
A = {02 : n ≥ 0}
and we designed a TM for it.

Sarmad Abbasi (Virtual University) Theory of Computation 3 / 26


Designing TMs

Now let us look at another language B

B = {w#w : w ∈ {0, 1}∗ }.


In order to design a TM we must understand the language first.
Let us look at some examples of strings that are in B

0110#0110, 0#0, #, 000#000.

Sarmad Abbasi (Virtual University) Theory of Computation 4 / 26


Designing TMs

Let us look at some examples of strings that are not in B

1010#1100, 0110, #0, 1#, 000#000#, 0#0#0, .

Sarmad Abbasi (Virtual University) Theory of Computation 5 / 26


Designing TMs

The machine will do the following:


1 In the first pass the machine will make sure that the input is of the
form
w1 #w2
where w1 , w2 ∈ {0, 1}∗ .
2 Then the machine will repeatedly scan the input and match each
character of w1 with one character of w2 .

Sarmad Abbasi (Virtual University) Theory of Computation 6 / 26


Designing TMs

We define our TM M
1 Q = {q1 , . . . , q14 , qa , qr }
2 Σ = {0, 1, #}
3 Γ = {0, 1, #, x, }
4 q1 , qa , qr the start, accept and reject states respectively.
5 δ is given by the state diagram.
In this diagram we have not shown qr . All transitions not defined here
go to qr .

Sarmad Abbasi (Virtual University) Theory of Computation 7 / 26


Designing TMs

Transition diagram of the Turing Machine.

Sarmad Abbasi (Virtual University) Theory of Computation 8 / 26


Designing TMs

Let us look at the computation of this TM on the input

011#011.
As you can see in the first phase the machine has converted the input
into

11#011.
Now it is looking for a 0 in the second string. When it finds a 0 it
crosses it and starts all over again.
Next it crosses of the 1 and is looking for a 1 in the second string.......

x1#x11
and is looking for a 1.

Sarmad Abbasi (Virtual University) Theory of Computation 9 / 26


Designing TMs

It finds a 1 after the # and crosses it.

x1#xx1
Now it goes back and similarly matches the last 1 to finally reach

xx#xxx
Then it goes over the tape once and realizes that all things have been
matched so it accepts this input.

Sarmad Abbasi (Virtual University) Theory of Computation 10 / 26


Designing TMs

Put Animation here.

Sarmad Abbasi (Virtual University) Theory of Computation 11 / 26


Designing TMs

Let us look at the another language:

C = {ai bj c k : k = i × j i, j, k ≥ 1}.
Firstly all the strings in this language have a’s then b’s then c’s.
Some strings in the language are:

abc, aabbcccc, aaabbcccccc


Some strings not in the langauge are

ab, aabb, aabbccc, ba, cab,

Sarmad Abbasi (Virtual University) Theory of Computation 12 / 26


Designing TMs

Lets give an informal description of a TM that recognizes C.


On input w
1 Scan the input and make sure that w is of the form a∗ b∗ c ∗ if it is
not reject.
2 Cross off an a and scan to the right till a b occurs. Now, shuttle
between b’s and c’s crossing one b and one c till all b’s are
crossed off. If you run out of c’s reject.
3 If all a’s are crossed off. Check if all c’s are also crossed off. In
that case accept.
4 If there are more a0 s left. Restore all b’s and repeat.

Sarmad Abbasi (Virtual University) Theory of Computation 13 / 26


Designing TMs
On input
aabbbcccccc
We will first check if the string is of the form a∗ b∗ c ∗ and it is.
So in the next state we cross off an a

x 0 abbbcccccc.
Since there are three b’s we shuttle between b’s can c’s crossing them
off.
To get to

x 0 axxxxxxccc
Next there is still an a so we restore all the b’s to get

x 0 abbbxxxccc

Sarmad Abbasi (Virtual University) Theory of Computation 14 / 26


Designing TMs

Now, we cross of another a to get

x 0 xbbbxxxccc.
Now, shuttle between b’s and c’s crossing them off to get

x 0 xxxxxxxxxx
.
Now check if there are any a’s left. No so we accept.

Sarmad Abbasi (Virtual University) Theory of Computation 15 / 26


Designing TMs

One question.
Why is the left most x and x 0 .
The answer is that this way the machine will know that it has reached
the left end of the tape.

Sarmad Abbasi (Virtual University) Theory of Computation 16 / 26


Designing TMs

Why will this work.


Note for each a we are crossing off as many c’s as there are b’s. So if
the number of a’s is i and the number of b’s is j then each time

c’s are being crossed off.


So the total number of c’s crossed off is i × j.
Thus if the number of c’s is equal to

i ×j

we accept.

Sarmad Abbasi (Virtual University) Theory of Computation 17 / 26


Designing TMs

This is a high level description of a TM. It is your home work to convert


this high level description to a formal description.
In your home work you have to specify 7 things. The set of states, the
start, accept and reject state, the input alphabet, the work alphabet
and a transition function (for which you can draw a state diagram).

Sarmad Abbasi (Virtual University) Theory of Computation 18 / 26


Designing TMs

Let us look at another example given in the book.


The language

E = {#x1 #x2 # . . . #xl : each xi ∈ {0, 1}∗ and xi 6= xj for each i 6= j}

This problem is called element distinctness problem.


We want to make sure that all the strings x1 , . . . , xl are distinct.

Sarmad Abbasi (Virtual University) Theory of Computation 19 / 26


Designing TMs

Here is a high level description of the Turing machine M4 that accepts


E.
On input w
1 Place a mark on top of the left most tape symbol. If that symbol is
not # reject.
2 Scan right to the next # and place a second mark on top of it. If
no # is encountered and a blank is encountered accept.
3 By zig-zagging compare the two strings to the right of the marked
#. If they are equal reject.
4 Move the rightmost of the two marks to the next # symbol. If no #
is encountered move the left most marker to the next #. If no such
# is available all strings are compared, so accept.
5 Go to state 3

Sarmad Abbasi (Virtual University) Theory of Computation 20 / 26


Designing TMs

Suppose the input is


#0#10#11#000
We start by marking the first # sign. This means the first string has to
be compared will all the strings.

#0#1011#000
It is first compared with the second string.

#0#10#11#000
then

#0#10#11#000

Sarmad Abbasi (Virtual University) Theory of Computation 21 / 26


Designing TMs

then there are no more # signs. So we move onto 10.

#0#10#11#000
then
#0#10#11#000
then

#0#10#11#000
after comparing them we are done.

Sarmad Abbasi (Virtual University) Theory of Computation 22 / 26


Designing TMs

There is a simple algorithm behind this TM.


Let l be the number of strings on the tape.
for i = 1, 2, . . . , l
for j = i + 1, . . . , l
compare xi and xj if they are equal reject.
accept.

Sarmad Abbasi (Virtual University) Theory of Computation 23 / 26


Designing TMs

From now on. We will only give informal description of TM’s. But, you
should be able to convert any informal description to a formal one.
Most interesting TM have several states hundreds even thousands.
However, it will be clear that an informal description can be changed to
a formal one.

Sarmad Abbasi (Virtual University) Theory of Computation 24 / 26


Variants of TMs
Let us look at an example of a multi-tape Turing machine.
A k -tape TM is a 7-tuple:
1 Q is the set of states.
2 Σ
3 Γ
4 q0 , qa , qr .
5 δ is now a function from
Q × Γk → Q × Γk × {L, R}k .

Sarmad Abbasi (Virtual University) Theory of Computation 25 / 26


Variants of TM’s
Multiple head Turing machines.
A k -tape TM is a 7-tuple:
1 Q is the set of states.
2 Σ
3 Γ
4 q0 , qa , qr .
5 δ is now a function from
Q × Γk → Q × Γk × {L, R}k .

Sarmad Abbasi (Virtual University) Theory of Computation 26 / 26

You might also like