ICS-252 Discrete Structure II
Lecture 11
Assistant Professor, Department of Computer Science & Engineering, University of Hail, KSA.
Email: s.hagahmoodi@uoh.edu.sa
Email: s.hagahmoodi@uoh.edu.sa
ICS‐252 Dr. Salah Omer, Assistant Professor, CSSE, University of Hail.
Outlines
•
Introduction to Turing Machine
•
Using Turing machines to recognize sets
•
Using Turing machines to recognize sets
(DMA 827-831)
•
Computing functions with Turing
Machines
•
Types of Turing Machines (DMA 831-837)
yp
g
(
)
Turing Machine
DFA:
1) The DFA cannot be used as general models of computation.
2) It does not have any memory 2) It does not have any memory
3) Can not compute functions such as the sum or product of two numbers.
Turing Machine: In 1930s Alan Turing invented a machine called Turing machine. It consists of
1) A control unit which is in one of finitely many different 1) A control unit, which is in one of finitely many different
states, together with a tape divided into cells, which is infinite in both directions.
3 ICS‐252 Dr. Salah Omer, Assistant Professor, CSSE, University of Hail.
Turing Machine
2) Turing machine has read and write capabilities on the tape as control unit moves back and forth along the tape.
Changing states depending on the tape symbol read. 3) Turing machine has memory and therefore are more
powerful than DFA.
4) Turing machine also can compute functions such as sum or product of two numbers.
5) Turing machine is most general model of computation, It can do whatever computer can do.
Turing Machine
An artistic representation of a Turing machine
5 ICS‐252 Dr. Salah Omer, Assistant Professor, CSSE, University of Hail.
Turing Machine
Definition: A Turing machine T= (S, I, f, s0) consists of a finite set S of states, an alphabet I containing the blank symbol B, a partial function f from S x I to S x I x {R, L}, and starting state s0.
Example 1:What is the final tape when the Turing machine T defined by the seven five-tuples (s0, 0, s0, 0, R), (s0, 1, s1, 1, R), (s0, B, s3, B, R), (s1, 0, s0, 0, R), (s1, 1, s2, 0, L), (s1, B, s3, B, R), (s2, 1, s3, 0, R) is run on the tape shown in figure 2 (a) (see at page DMA-829).
Solution:See at page DMA-829. Answer: (010000), Finally, in the seventh step the machine halts because there is no five-tuple beginning with the pair (s3, 0) in the given
description of the machine.
Using Turing Machines to recognize Sets
Definition: Let V be a subset of an alphabet I, A Turing machine T= (S, I, f, s0) recognizes a string x in V* if and only if T, starting in the initial position when x is written on the tape, halts in a final state. T is said to recognize a subset A of V* if x recognized by T if and only if x belongs subset A of V if x recognized by T if and only if x belongs to A.
Example 2:Find a Turing machine that recognizes the set of bit strings that have a 1 as their second bit, that is, the regular set (0 U 1)1(0 U 1)*
Solution: We want a Turing machine that, starting at the leftmost nonblank tape cell, moves right, and determines whether the second symbol is a 1. If the second symbol is 1, the machine should move into a final state. If the second symbol is not a 1, the machine should not halt or halt in a nonfinal state.
7 ICS‐252 Dr. Salah Omer, Assistant Professor, CSSE, University of Hail.
Using Turing Machines to recognize Sets
To construct such machine we include the following tuples (s0, 0, s1, 0, R) and (s0, 1, s1, 1, R)
To read the first symbol 0 or 1 and put Turing machine in state s1
state s1.
(s1, 0, s2, 0, R) and (s1, 1, s3, 1, R) To read the 2nd symbol
If the symbol is 1 then move to the s3,which is final state. If the symbol is 0 then move to the state s2. So it is not final
state, To solve this we include (s2, 0, s2, 0, R)
Because we do not want to recognize the empty string or string with one bit, therefore we included (s0, B, s2, 0, R)
Computing Functions withTuring Machines
The Turing machine T consisting of the 7 tuples listed above will terminate in the final state s3 m if and only if the bit string has at least two bits and the second bit of the input string is 1. if the bit string contains fewer than two bits or if string is 1. if the bit string contains fewer than two bits or if the 2nd bit is not 1, then the machine will terminate in the
nofinal state s2.
Computing Functions with Turing Machines: Consider a
Turing machine as a computer of functions from the set of K-tuples of non-negative integers to the set of non-negative integers (such functions are called number-theoretic
integers (such functions are called number theoretic functions), but we need a way to represent k-tuples of integers on a tape. For this we use unary representations of integers. We represent the no-negative integer n by a string of n+1 1s , so that for example 0 is represented by the string 1 and
9 ICS‐252 Dr. Salah Omer, Assistant Professor, CSSE, University of Hail.
Computing Functions withTuring Machines
5 is represented by the string 111111. To represent the k-tuple (n1, n2, n3,……… nk) , we use a string of n1 + 1 1s, followed by an asterisk, followed by a string of n2+1 1s, followed by an asterisk and so on, ending with a string of nk+1 1s. For an asterisk and so on, ending with a string of nk 1 1s. For example, to represent the four-tuple (2,0,1,3), we use the string 111 * 1 * 11 * 1111.
Example 4: Construct a Turing machine for adding two non-negative integers.
Solution: We need to build a Turing machine T that
Computing Functions withTuring Machines
It will work like this;
1) The machine starts at the leftmost 1 of the input string, and carries out steps to erase this 1.
2) Halt if n1= 0, so that there are no more 1s before the
asterisk, replaces the asterisk with the leftmost remaining 1. and then halts.
3) The following five-tuples can do this job; (s0, 1, s1, B, R) and (s1, *, s3, B, R) (s1, 1, s2, B, R) and (s2, 1, s2, 1, R) (s2, *, s3, 1, R)
11 ICS‐252 Dr. Salah Omer, Assistant Professor, CSSE, University of Hail.
Types of Turing Machines
Turing machine has the following types; 1) Turing machine with one dimensional tape
1 1 0 0 1 1
2) Turing machine with two dimensional tape
1 1 0 0 1 1
V V V V V
H 1 1 0 1
H 0 0 1 0
H 0 0 1 0
H 1 1 1 1
Types of Turing Machines
3) Turing Machines with Multiple Tapes
4) Nondeterministic Turing Machines: A nondeterministic Turing machine is a Turing machine which is like a
nondeterministic finite automata, at any state it is in and for , y the tape symbol it is reading, can take any action selecting from a set of specified actions rather than taking one definite predetermined action. Even in the same situation it may take different actions at different times. Here an action means the combination of writing a symbol on the tape, moving the tape head and going to a next state.
13 ICS‐252 Dr. Salah Omer, Assistant Professor, CSSE, University of Hail.
Home Work
Question 1:
see page 837.
Thank you for your Attention.
15