Professional Documents
Culture Documents
Unit 3 Notes
Unit 3 Notes
Prepared By:
Mr.M.Shanmugam, AP/CSE
Verifiedby: Approvedby:
UNIT-III
Turing machine s: Turing machine s as Language Acceptors – Turing machine s for Accepting Regular
Languages – Turing machine for Addition and Subtraction.
2 MARKS
the tape has a leftmost cell but is in finite to the right. Each cell of the tape may hold exactly one of a
finite number of tape symbol s.
9. Define subroutines?
As with programs, a “modular” or “top-down” design is facilitated if we use subroutines to define
elementary processes. A Turing machine can simulate any type of subroutine found in programming
languages, including recursive procedures and any of the known parameter-passing mechanisms.
A TM subroutine have to design initial state and a designated return state which has no move and
which will be used to effect a return to the calling routine. To design a TM that “calls” the subroutine, a
new set of state s for the subroutine is made, and a move from the return is effected by the move from the
return state .
10. Write about the storage in the finite Control(FC)? (APR2017)
the finite control can be used to hold a finite amount of information. the state is written as a pair of
elements, one exercising control and the o the r storing a symbol . It should be emphasized that this
arrangement is for conceptual purposes only. No modification in the definition of the Turing machine
has been made.
the tape has a leftmost cell but is in finite to the right. Each cell of the tape may hold exactly one of a
finite number of tape symbol s. Initially, the n leftmost cells, for some finite n≥0, hold the input, which
is a string of symbol s chosen from a subset of the tape symbol s called the input symbol s. the
remaining infinity of cells each hold the blank, which is a special tape symbol that is not an input symbol .
In one move the Turing machine , depending upon the symbol scanned by the tape head and the
state of the finite control,
1. Changes state ,
2. Prints a symbol on the tape cell scanned, replacing what was written the re, and
3. Moves its head left or right one cell.
Formally, a Turing machine (TM) is
denoted M = (Q, Σ, Γ, δ, q0, B, F)
Where
Q is the finite set of state s,
Γ is the finite set of allowable tape
symbol s, B, a symbol of Γ, is the blank,
Σ, a subset of Γ not including B, is the set of input symbol s,
δ is the next move function, a mapping from Q x Γ to Q x Γ x {L,
R}. q0 in Q is the start state ,
F⊆Q is the set of final state s.
An Instantaneous Description (ID) of the Turing machine M is denoted by α1qα2. Here q, the current
state of M is in Q; α1α2 is the string in Γ* that is the contents of the tape up to the rightmost non blank
symbol or the symbol to the left of the head, whichever is rightmost. Finally, the tape head is assumed
to be scanning the leftmost symbol of α2 or if α2= ε, the head is scanning a blank.
We define a move of M as follows. Let X1X2………XI-1qxi…….Xn be an ID. Let (qi, Xi) = (p, y, L). If i-1=n,
the n take xi as B(blank). If i=1, the n the re is no next ID, as the tape head is not allowed to fall off the left
end of the tape. If i>1, the n we write
X1X2……..XI-1qxi…..Xn├X1X2……XI-2pXI-1YXi+1…..Xn ------------------------------ 1
If δ(q,xi)=(p,y,R), thg en change of ID is
X1X2……..XI-1qXI…..Xn├X1X2……XI-1YpXi+1..Xn --------------------------------------- 2
If i-1=n, the string Xi Xn is empty and the right side of 2 is longer that left side.
the language accepted by M, denoted L(M), is the set of words in Σ * that cause M to enter a final state
when placed, justified at the left on the tape of M, with M in state q0, and the tape head of M at the
leftmost cell. the language accepted by M = (Q, Σ, Γ, δ, q0, B, F)is
{w | w in Σ * and q0w | * α1 p α2 for some p in F and α1 and α2 in Γ* }.
It is convenient to single out a subclass of the recursively enumerable sets called the recursive sets, which
are those languages accepted by at least one Turing machine that halts on all inputs.
the Turing machine as a computer of integer functions
In addition to being a language acceptor, the Turing machine may be viewed as a computer of functions
from integers to integers. the approach is to represent integers in unary; the integer i≥0 is represented by
the string 0i. If a function has k arguments, i1, i2,…. , ik, the n the se integers are initially placed on the tape
separated by 1’s as 0i110i21…10ik.
If the TM halts (whe the r or not in an accepting state ) with a tape consisting of 0m for some m, the n we
say that f(i1,i2,….,ik)=m, where f is the function of k arguments computed by this Turing machine . Note
that one TM may compute a function of one argument, a different function of two arguments, and so on.
Also note that if TM M computes function f of k arguments, the n feed not have a value for all different k –
tuples of integers i1,….,ik.
If f(i1,i2,………ik) is defined for all i1,…..ik the n we say f is a total recursive function. the total recursive
functions correspond to recursive languages, since the y are computed by TM that always halt. the
common arithmetic functions on integers, such as multiplication, n!, [log 2n] and 22n are total recursive
functions.
A function f(i1,…ik) computed by a Turing machine is called a partial recursive function. the y are similar to
r.e languages as the y are computed by TM that may or may not halt on a given input.
Example: F: N->N
F(x) =x+1(note: blank space replaced by zero) (APR-22) (OCT-22)
Solution
Assume that the input is encoded in unary form. Find first blank (B) and changes it as 0.
Let M= (Q, Σ, Γ, δ, q0, B, F)
Where
Q= {q0, q1}
Σ= {0}
Γ= {0, B}
{q0}=Initial
state F= {q1}
δ transition function,
Inputs
state s
0 B
q0 (q0,0,R) (q1,0,R)
q1 - -
Let us consider output x=3. This can be encoded as 03 and placed on the
tape (q0,000B) ├ (q0,000B)
├ (q0, 000B)
├ (q1, 0000B)
Note
If found 0-> no state
change If found 1 -> state
changed
If found ‘B’-> state changed control transferred to towards left cell.
the machine halts an accepting state q1 computing the successor of x. This can be shown in following figure.
0 0 0 B B……………..
the first blank symbol is replaced by 0 and the state is changed to q1 which is the acceptance state . the
machine halts as state q1 leaving the output x+1 on the tape.
Concept
From the state q0 on input symbol , it moves right until it sees a blank symbol without changing
the tape symbol or state . On seeing the first blank symbol it is changed to 0, moves right and enters in a
halt string. the tape now will contain the output.
3. Explain the technique for TM Construction in detail? (10 MARKS) (NOV 2017)
Designing Turing machine s by writing out a complete set of state s and a next – move function is a
noticeably unrewarding task. In order to describe complicated Turing machine constructions we need
some “higher – level” conceptual tools.
1. Storage in finite control
2. Multiple tracks
3. Checking off symbol s
4. Shifting over
5. Subroutines
Multiple tracks
We can imagine that the tape of the Turing machine is divided into k tracks, for any finite k. This
arrangement is shown in Figure with k=3. the symbol s on the tape are considered k- tuples, one comp
one nt for each track.
Shifting over
A Turing machine can make a space on its tape by shifting all non-blank symbol s a finite number of cells
to the right. the tape head makes an excursion to the right, repeatedly storing the symbol s read in its
finite control and replacing the m with symbol s read from cells to the left. the TM can the n return to
the vacated cells and print symbol s of its choosing. If space is available, it can push blocks of symbol s
left in a similar manner.
Subroutines (OCT-22)
As with programs, a “modular” or “top-down” design is facilitated if we use subroutines to define elementary
processes. A Turing machine can simulate any type of subroutine found in programming languages,
including recursive procedures and any of the known parameter-passing mechanisms.
A TM subroutine have to design initial state and a designated return state which has no move and which
will be used to effect a return to the calling routine. To design a TM that “calls” the subroutine, a new set of
state s for the subroutine is made, and a move from the return is effected by the move from the return
state .
4. Explain various types of Turing machine with neat sketch. (10MARKS) (APR2015) (APR-22) (OCT-22)
the variations or modifications of the Turing machine s are
1. Two-way in finite Tape
2. Multi-Tape Turing machine s
3. Non-Deterministic Turing machine s
4. Multi-Dimensional Turing machine s
5. Multi-Head Turing machine s
6. Off-Line Turing machine s
At any time, only a finite number of rows in any dimension contain non-blank symbol s. This rows each
have only a finite no. of non-blank symbol s.
9. Construct Turing machine for binary language of palindrome strings. (10 MARKS)(NOV2016)(APR-22)
the TM scans the first symbol of input tape (a or b), erases, that is replaces it with Blank symbol B and
changes state (q1, or q2). TM scans the remaining part without changing the tape symbol until it
encounters blank symbol B. the n the read write head moves to the left. If the rightmost symbol tallies
with the leftmost symbol (Which can be erased but remembered), the rightmost symbol is erased o the
rwise TM halts. the read write head moves to the left until blank B is encountered. the above steps are
repeated after changing the state s suitably.
Transition Table:
Transition Functions:
δ(q0,a) = (q1,B,R)
δ(q0,b) = (q2,B,R)
δ(q1,a) =(q1,a,R)
δ(q1,b) =(q1,b,R)
δ(q1,B) =(q3,B,L)
δ(q2,a) =(q2,a,R)
δ(q2,b) =(q2,b,R)
δ(q2,B) =(q4,B,L)
δ(q3,a) =(q5,B,L)
δ(q5,a) =(q5,a,L)
δ(q5,b) =(q5,b,L)
δ(q5,B) =(q0,B,R)
δ(q4,b) =(q6,B,L)
δ(q6,a) =(q6,a,L)
δ(q6,b) =(q6,b,L)
δ(q6,B) =(q0,B,R)
δ(q0,B) =(q7,B,R)
Transition Diagram:
10. Design Turing machine for the following language { an bn cn, n≥1}. (10MARKS)(APR 2016)
(NOV2017) (OCT-22)
Step 3-4
4. Mark 'b' as 'Y' and move one step right.
5. Reach unmarked 'c' and pass every 'b' and 'Z'(in case) on the way to 'c'.
6. Mark 'c' as 'Z' and move one step left cause now we have to repeat process.
7. Reach unmarked 'X' and pass every 'Z', 'b', 'Y', 'a' on the way to 'X'.
8. Move to 'a' and repeat the process.
Step 5-9
9. Step 1-4 are repeated.
Step 10
10. When TAPE header reaches 'X' and next symbol is 'Y' that means 'a's are finished.
11. Check for 'b's and 'c's by going till BLANK (in right) and passing 'Y' and 'Z' on the way.
12. If no 'b' and 'c' are not found that means string is accepted.
2. Following Steps:
a. Mark 'b' with 'Y' and move towards un marked 'c'.
b. Move towards unmarked 'c' by passing all 'b's.
c. To move towards unmarked 'c' also pass all 'Z's if exist.
3. Following Steps:
a. Mark 'c' with 'Z' and move towards first 'X' (in left).
b. Move towards first 'X' by passing all 'Z's, 'b's, 'Y's and 'a's.
c. When 'X' is reached just move one step right by doing nothing.
4. To check all the 'a's,'b's and 'c's are over add loops for checking 'Y' and 'Z' after" weget 'X' followed by
'Y'". To reach final state (qf) just replace BLANK with BLANK and move ei the r direction.
12. Construct a Turing machine that canmultiply2integers. (10MARKS) (NOV2016)
Turing machine for Regular languages
Regular languages can be represented through finite automata and similarly can be
represented through Turing machine .
This machine must accept all strings starting from a and ending with b. e.g, ab,aab, abab etc.
Start:
Starts the machine
a,a,R:
Read a from input tape and write a and move Right on input tape.
state 2:
Read a from input tape and write a and move Right on input tape. the re is a loop of a, a, R on state
2.
If read b from input tape, the n write b and move right and halts the machine by accepting the
string.
If the re is any a on accept state the n again control moves to the state 2, enforcing the machine to
not end with a.
Question: String ab can be ready by this Turing machine or not? If it can be read the n what will be
the path?
Answer:
Yes, this string can be read by the Turing machine in the Path of machine execution is mentioned
below.
Path: start > 2 > accept.
Question: String ba can be ready by this Turing machine or not? If it can be read the n what will be
the path?
Answer: Sorry this string can’t be read by this Turing machine because this machine only can read
the strings that are started with alphabet a
Question: String abbba can be ready by this Turing machine or not? If it can be read the n what will
be the path?
Answer:
Answer: Sorry this string can’t be read by this Turing machine because this machine only can read
the strings ended with alphabet b.
Path: start > 2 > accept > accept > accept > 2. Here, 2 is the ending state but actual ending state is
“accept”.
Question: String ababab can be ready by this Turing machine or not? If it can be read the n what will
be the path?
Answer:
Yes, this string can be read by the Turing machine in the Path of machine execution is menti one d
below.
Path: start > 2 > accept > 2 > accept > 2 > accept.
Question: String abbbb can be ready by this Turing machine or not? If it can be read the n what will
be the path?
Answer:
Yes, this string can be read by the Turing machine in the Path of machine execution is menti one d
below.
Path: start > 2 > accept > accept > accept > accept.
Question: String baabbb can be ready by this Turing machine or not? If it can be read the n what will
be the path?
Answer: Sorry this string can’t be read by this Turing machine because this machine only can read
the strings that are started with alphabet a.
Question: String aababb can be ready by this Turing machine or not? If it can be read the n what will
be the path?
Answer: Yes, this string can be read by the Turing machine in the Path of machine execution is
mentioned below.
Path: start > 2 > 2 > accept > accept > accept.
Turing machine for Subtraction
PONDICHERRY UNIVERSITY QUESTIONS
2 MARKS
10 MARKS
MAY 2018
1. Construct Turing machine for L={0n 1n /n>=1}(11makrs)
(OR)
2. Construct a Turing machine that can find the reverse of a binary string(11marks)
MAY 2019
1. Design a Turing machine which accepts strings which begin with a letter followed by letter or Digits.