Jan-June 2025 Btcs 4 Sem v10 Btcs404 Btcs404 Unit5 Notes
Jan-June 2025 Btcs 4 Sem v10 Btcs404 Btcs404 Unit5 Notes
Turing Machine:
A Turing Machine is an accepting device which accepts the languages (recursive
enumerable set) generated by type 0 grammars. It was invented in 1936 by Alan Turi
Definition
A Turing Machine (TM) is a mathematical model which consists of an infinite length
tape divided into cells on which input is given. It consists of a head which reads the
input tape.
A state register stores the state of the Turing machine. After reading an input symbol
is replaced with another symbol, its internal state is changed, and it moves from one
to the right or left. If the TM reaches the final state, the input string is accepted,
otherwise rejected.
A TM can be formally described as a 7-tuple (Q, X, Ʃ, δ, q0, B, F) where:
o Q is a finite set of states
o X is the tape alphabet
o Ʃ is the input alphabet
o δ is a transition function; δ : Q × X → Q × X × {Left_shift, Right_shift}.
o q0 is the initial state
o B is the blank symbol
o F is the set of final states
Comparison with the previous automaton:
The following table shows a comparison of how a Turing machine differs from Finite
Automaton and Pushdown Automaton.
Machine Stack Data Structure Deterministic?
Finite Automation NA Yes
Pushdown Automation Last in First Out (LIFO) No
Turing Machine Infinite Tape Yes
Example of Turing Machine:
Turing Machine M = (Q, X, Ʃ, δ, q0, B, F) with
o Q = {q0, q1, q2, q3}
o X = {a, b}
o Ʃ = {1}
o q0 = {q0}
o B = blank symbol
o F = {qf}
o δ is given by:
Tape Alphabet Present State ‘q0’ Present State Present State
Symbol ‘q1’ ‘q2’
a 1Rq1 1Lq0 1Lqf
1
b 1Lq2 1Rq1 1Rqf
Here the transition 1Rq1 implies that the write symbol is 1, the tape moves right, and
the next state is q1. Similarly, the transition 1Lq 2 implies that the write symbol is 1,
the tape moves left, and the next state is q2.
Time and Space Complexity of a Turing Machine:
For a Turing machine, the time complexity refers to the measure of the number of
times the tape moves when the machine is initialized for some input symbols and the
space complexity is the number of cells of the tape written.
Time complexity all reasonable functions: T(n) = O(n log n)
TM's space complexity: S(n) = O(n)
Accepted Language and Decided Language:
A TM accepts a language if it enters into a final state for any input string ‘w’. A
language is recursively enumerable (generated by Type - 0 grammar) if it is accepted
by a Turing machine.
A TM decides a language if it accepts it and enters into a rejecting state for any input
not in the language. A language is recursive if it is decided by a Turing machine.
There may be some cases where a TM does not stop. Such TM accepts the language,
but it does not decide it.
Designing a Turing Machine:
The basic guidelines of designing a Turing machine have been explained below with
the help of a couple of examples.
2
o If M is in q0, on reading 0, it moves right, enters the state q 1 and erases 0. On
reading 1, it enters the state q2 and moves right.
o If M is in q1, on reading 0, it moves right and erases 0, i.e., it replaces 0’s by
B’s. On reaching the leftmost 1, it enters q 2 and moves right. If it reaches B,
i.e., the string comprises of only 0’s, it moves left and enters the state q3.
o If M is in q2, on reading either 0 or 1, it moves right. On reaching B, it moves
left and enters the state q 4. This validates that the string comprises only of 0’s
and 1’s.
o If M is in q3, it replaces B by 0, moves left and reaches the final state qf.
o If M is in q4, on reading either 0 or 1, it moves left. On reaching the beginning
of the string, i.e., when it reads B, it reaches the final state qf.
Hence, M = {{q0, q1, q2, q3, q4, qf}, {0, 1, B}, {1, B}, δ, q0, B, {qf}}.
Here, δ is given by:
Tape alphabet Present Present Present Present Present
symbol state ‘q0’ state ‘q1’ state ‘q2’ state ‘q3’ state ‘q4’
0 BRq1 BRq1 0Rq2 - 0Lq4
1 1Rq2 1Rq2 1Rq2 - 1Lq4
B BRq1 BLq3 BLq4 0Lqf BRqf
3
Note: Every Multi-tape Turing machine has an equivalent single-tape Turing
machine.
It is a two-track tape:
4
o Upper track: It represents the cells to the right of the initial head position.
o Lower track: It represents the cells to the left of the initial head position in
reverse order.
The infinite length input string is initially written on the tape in contiguous tape cells.
The machine starts from the initial state q0 and the head scans from the left end
marker ‘End’.
In each step, it reads the symbol on the tape under its head. It writes a new symbol on
that tape cell and then it moves the head either into left or right one tape cell. A
transition function determines the actions to be taken.
It has two special states called accept state and reject state. If at any point of time it
enters into the accepted state, the input is accepted and if it enters into the reject state,
the input is rejected by the TM. In some cases, it continues to run infinitely without
being accepted or rejected for some certain input symbols.
Note: Turing machines with semi-infinite tape are equivalent to standard Turing
machines.
Linear Bounded Automata:
A linear bounded automaton is a multi-track non-deterministic Turing machine with a
tape of some bounded finite length.
Length = function (Length of the initial input string, constant c)
Here, Memory information = c × Input information
The computation is restricted to the constant bounded area. The input alphabet
contains two special symbols which serve as left end markers and right end markers
which mean the transitions neither move to the left of the left end marker nor to the
right of the right end marker of the tape.
A linear bounded automaton can be defined as an 8-tuple (Q, X, Ʃ, q0, ML, MR, δ, F)
where:
o Q is a finite set of states
o X is the tape alphabet
o Ʃ is the input alphabet
o q0 is the initial state
o ML is the left end marker
o MR is the right end marker where MR ≠ ML
o δ is a transition function which maps each pair (state, tape symbol) to (state,
tape symbol, Constant ‘c’) where c can be 0 or +1 or -1.
o F is the set of final states.
A deterministic linear bounded automation is always context-sensitive and the linear
bounded automation with empty language is undecidable.
Language Decidability:
A language is called decidable or recursive if there is a Turing machine which accepts
and halts on every input string w. Every decidable language is Turing Acceptable.
5
A decision problem P is decidable if the language L of all yes instances to P is
decidable.
For a decidable language, for each input string, the TM halts either at the accept or the
reject state as depicted in the following diagram:
Example 1: Find out whether the following problem is decidable or not: Is a number ‘m’
prime?
Solution:
Prime numbers = {2, 3, 5, 7, 11, 13, ...}
Divide the number ‘m’ by all the numbers between ‘2’ and ‘√m’ starting from ‘2’.
If any of these numbers produce a remainder zero, then it goes to the “Rejected state”,
otherwise it goes to the “Accepted state”. So, here the answer could be made by ‘Yes’
or ‘No’.
Hence, it is a decidable problem.
Example 2: Given a regular language L and string w, how can we check if wϵ L?
Solution:
Take the DFA that accepts L and check if w is accepted.
6
2. If a language is decidable, then there is an enumerator for it.
Undecidable Language:
For an undecidable language, there is no Turing Machine which accepts the language
and makes a decision for every input string w (TM can make decision for some input
string though).
A decision problem P is called “undecidable” if the language L of all yes instances to
P is not decidable. Undecidable languages are not recursive languages, but sometimes,
they may be recursively enumerable languages.
Example:
The halting problem of Turing machine
The mortality problem
The mortal matrix problem
The Post correspondence problem, etc.
Turing Machine Halting Machine:
Input: A Turing machine and an input string w.
Problem: Does the Turing machine finish computing of the string w in a finite
number of steps? The answer must be either yes or no.
Proof: At first, we will assume that such a Turing machine exists to solve this
problem and then we will show it is contradicting itself. We will call this Turing
machine as a Halting machine that produces a ‘yes’ or ‘no’ in a finite amount of
time. If the halting machine finishes in a finite amount of time, the output comes as
‘yes’, otherwise as ‘no’. The following is the block diagram of a Halting machine:
7
Further, a machine (HM)2 which input itself is constructed as follows:
o If (HM)2 halts on input, loop forever.
o Else, halt.
Here, we have got a contradiction. Hence, the halting problem is undecidable.
machine, is undecidable.
or <M1> <M2> ∉ L
Property 2: For some M1 and M2 such that <M1> ∈ L and <M2> ∉ L
Proof:
8
Example 2: Find whether the lists M = (ab, bab, bbaaa) and N = (a, ba, bab) have a
Post Correspondence Solution?
Solution:
x1 x2 x3
M ab bab bbaaa
M a ba bab
In this case, there is no solution because: | x2x1x3 | = | y2y1y3 | (Lengths are not same).
Hence, it can be said that this Post Correspondence Problem is undecidable.
Universal Turing Machines:
Turing machines are abstract computing devices. Each Turing machine represents a
particular algorithm. Hence we can think of Turing machines as being "hard-wired".
Is there a programmable Turing machine that can solve any problem solved by a
"hard-wired" Turing machine? The answer is "yes", the programmable Turing
machine is called "universal Turing machine".
Basic Idea: The Universal TM will take as input a description of a standard TM and
an input w in the alphabet of the standard TM, and will halt if and only if the standard
TM halts on w.
The Church - Turing Thesis:
Intuitive notion of an algorithm: a sequence of steps to solve a problem.
Questions: What is the meaning of "solve" and "problem"?
Answers:
o Problem: This is a mapping. Can be represented as a function, or as a set
membership "yes/no" question.
o To solve a problem: To find a Turing machine that computes the function or
answers the question.
Church-Turing Thesis:
o Any Turing machine that halts on all inputs corresponds to an algorithm, and
any algorithm can be represented by a Turing machine. This is the formal
definition of an algorithm. This is not a theorem - only a hypothesis.
o In computability theory, the Church–Turing thesis (also known as the Church-
Turing conjecture, Church's thesis, Church's conjecture, and Turing's thesis) is
a combined hypothesis ("thesis") about the nature of functions whose values
are effectively calculable; i.e. computable.
o In simple terms, it states that "everything computable is computable by a
Turing machine."
Recursive and Recursively Enumerable Languages:
Remember that there are three possible outcomes of executing a Turing machine over
a given input. The Turing machine may:
o Halt and accept the input;
o Halt and reject the input; or
o Never halt.
A language is recursive if there exists a Turing machine that accepts every string of
the language and rejects every string (over the same alphabet) that is not in the
language. Note that, if a language L is recursive, then its complement -L must also be
recursive. (Why?)
9
A language is recursively enumerable if there exists a Turing machine that accepts
every string of the language, and does not accept strings that are not in the language.
(Strings that are not in the language may be rejected or may cause the Turing machine
to go into an infinite loop.)
Clearly, every recursive language is also recursively enumerable. It is not obvious
whether every recursively enumerable language is also recursive.
10