Professional Documents
Culture Documents
Turning Machine
Now, we will see how this turing machine will works for 0011. Initially, state is q0 and head points to 0
as:
The move will be δ(q0, 0) = δ(q1, A, R) which means it will go to state q1, replaced 0 by A and head will
move to the right as:
The move will be δ(q1, 0) = δ(q1, 0, R) which means it will not change any symbol, remain in the same
state and move to the right as:
The move will be δ(q1, 1) = δ(q2, B, L) which means it will go to state q2, replaced 1 by B and head will
move to left as:
Now move will be δ(q2, 0) = δ(q2, 0, L) which means it will not change any symbol, remain in the same
state and move to left as:
The move will be δ(q2, A) = δ(q0, A, R), it means will go to state q0, replaced A by A and head will move
to the right as:
The move will be δ(q0, 0) = δ(q1, A, R) which means it will go to state q1, replaced 0 by A, and head will
move to right as:
The move will be δ(q1, B) = δ(q1, B, R) which means it will not change any symbol, remain in the same
state and move to right as:
The move will be δ(q1, 1) = δ(q2, B, L) which means it will go to state q2, replaced 1 by B and head will
move to left as:
The move δ(q2, B) = (q2, B, L) which means it will not change any symbol, remain in the same state and
move to left as:
Now immediately before B is A that means all the 0’s are market by A. So we will move right to ensure
that no 1 is present. The move will be δ(q2, A) = (q0, A, R) which means it will go to state q0, will not
change any symbol, and move to right as:
The move δ(q0, B) = (q3, B, R) which means it will go to state q3, will not change any symbol, and move
to right as:
The move δ(q3, B) = δ(q3, B, R) which means it will not change any symbol, remain in the same state and
move to right as:
The move δ(q3,Δ) = (q4,Δ,R) which means it will go to state q4 which is the HALT state and HALT state
is always an accept state for any TM.
• The tape head will read out the sequence up to the Δ characters.
• If the tape head is readout 'aba' string then TM will halt after reading Δ.
• Now, we will see how this turing machine will work for aba.
• Initially, state is q0 and read head points to a as:
The move will be δ(q0, a) = δ(q1, A, R) which means it will go to state q1, replaced a by A and head will
move to right as:
The move will be δ(q1, b) = δ(q2, B, R) which means it will go to state q2, replaced b by B and head will
move to right as:
The move will be δ(q2, a) = δ(q3, A, R) which means it will go to state q3, replaced a by A and head will
move to right as:
The move δ(q3, Δ) = (q4, Δ, S) which means it will go to state q4 which is the HALT state and HALT state
is always an accept state for any TM.
q0 (q1, A, R) – –
q1 – (q2, B, R) –
q2 (q3, A, R) – –
q3 – – (q4, Δ, S)
q4 – – –
The move will be δ(q0, 0) = δ(q1, A, R) which means it will go to state q1, replaced 0 by A and head will
move to the right as:
The move will be δ(q1, 0) = δ(q1, 0, R) which means it will not change any symbol, remain in the same
state and move to the right as:
The move will be δ(q1, 1) = δ(q2, B, R) which means it will go to state q2, replaced 1 by B and head will
move to right as:
The move will be δ(q2, 1) = δ(q2, 1, R) which means it will not change any symbol, remain in the same
state and move to right as:
The move will be δ(q2, 2) = δ(q3, C, R) which means it will go to state q3, replaced 2 by C and head will
move to right as:
Now move δ(q3, 2) = δ(q3, 2, L) and δ(q3, C) = δ(q3, C, L) and δ(q3, 1) = δ(q3, 1, L) and δ(q3, B) =
δ(q3, B, L) and δ(q3, 0) = δ(q3, 0, L), and then move δ(q3, A) = δ(q0, A, R), it means will go to state q0,
replaced A by A and head will move to right as:
The move will be δ(q0, 0) = δ(q1, A, R) which means it will go to state q1, replaced 0 by A, and head will
move to right as:
The move will be δ(q1, B) = δ(q1, B, R) which means it will not change any symbol, remain in the same
state and move to right as:
The move will be δ(q1, 1) = δ(q2, B, R) which means it will go to state q2, replaced 1 by B and head will
move to right as:
The move will be δ(q2, C) = δ(q2, C, R) which means it will not change any symbol, remain in the same
state and move to right as:
The move will be δ(q2, 2) = δ(q3, C, L) which means it will go to state q3, replaced 2 by C and head will
move to left until we reached A as:
immediately before B is A that means all the 0's are market by A. So we will move right to ensure that no
1 or 2 is present. The move will be δ(q2, B) = (q4, B, R) which means it will go to state q4, will not
change any symbol, and move to right as:
The move will be (q4, B) = δ(q4, B, R) and (q4, C) = δ(q4, C, R) which means it will not change any
symbol, remain in the same state and move to right as:
The move δ(q4, X) = (q5, X, R) which means it will go to state q5 which is the HALT state and HALT
state is always an accept state for any TM.
The same TM can be represented by Transition Diagram:
This means: When the machine is in a given state (Q) and reads a given symbol ( ) from the tape, it
replaces the symbol on the tape with some other symbol ( ), goes to some other state (Q), and moves the
tape head one square left (L) or right (R).
where the x's are the symbols on the tape, qm is the current state, and the tape head is on the square
containing xk (the symbol immediately following qm).
A move of a Turing machine can therefore be represented as a pair of instaneous descriptions, separated
by the symbol " ".
abbabq5babb abbabcq8abb
Types of Turing Machine :-
1. Multiple track Turing Machine:
1. A k-tack Turing machine(for some k>0) has k-tracks and one R/W head that reads and writes all of
them one by one.
2. A k-track Turing Machine can be simulated by a single track Turing machine
2. Two-way infinite Tape Turing Machine:
1. Infinite tape of two-way infinite tape Turing machine is unbounded in both directions left and right.
2. Two-way infinite tape Turing machine can be simulated by one-way infinite Turing
machine(standard Turing machine).
3. Multi-tape Turing Machine:
1. It has multiple tapes and controlled by a single head.
2. The Multi-tape Turing machine is different from k-track Turing machine but expressive power is
same.
3. Multi-tape Turing machine can be simulated by single-tape Turing machine.
4. Multi-tape Multi-head Turing Machine:
1. The multi-tape Turing machine has multiple tapes and multiple heads
2. Each tape controlled by separate head
3. Multi-Tape Multi-head Turing machine can be simulated by standard Turing machine.
5. Multi-dimensional Tape Turing Machine:
1. It has multi-dimensional tape where head can move any direction that is left, right, up or down.
2. Multi dimensional tape Turing machine can be simulated by one-dimensional Turing machine
6. Multi-head Turing Machine:
1. A multi-head Turing machine contain two or more heads to read the symbols on the same tape.
2. In one step all the heads sense the scanned symbols and move or write independently.
3. Multi-head Turing machine can be simulated by single head Turing machine.
7. Non-deterministic Turing Machine:
1. A non-deterministic Turing machine has a single, one way infinite tape.
2. For a given state and input symbol has atleast one choice to move (finite number of choices for the
next move), each choice several choices of path that it might follow for a given input string.
3. A non-deterministic Turing machine is equivalent to deterministic Turing machine.
• Turing Machine accepts the recursively enumerable language. It is more powerful than any other
automata such as FA, PDA, and LBA. It computes the partial recursive function.
• It can be further divided into Deterministic Turing Machine(DTM) or Non-Deterministic
Machine(NTM). By default, Turing Machine is DTM, and the power of DTM and NTM are the same.
• This machine acts as a Recognizer or Acceptor and as an Enumerator.
• The machine is said to be as acceptor which accepts or recognizes the strings of a recursively
enumerable language (L) over the input alphabet(∑ ) and the machine is said to be as enumerator
which enumerates the string of recursively enumerable language over the input alphabet ∑.
Undecidable language-
• A decision problem P is said to be undecidable if the language L of all
yes instances to P is not decidable or a language is undecidable if it is not decidable.
• An undecidable language maybe a partially decidable language or something else but not
decidable. If a language is not even partially decidable , then there exists no Turing machine
for that language.
Recursive language(REC)-
• A language ‘L’ is said to be recursive if there exists a Turing machine which will accept all the
strings in ‘L’ and reject all the strings not in ‘L’.
• The Turing machine will halt every time and give an answer(accepted or rejected) for each and
every string input.
• A language ‘L’ is decidable if it is a recursive language. All decidable languages are recursive
languages and vice-versa.
One way to solve decidability problems is by trying to reduce an already known undecidable problem to
the given problem. By reducing a problem P1 to P2, we mean that we are trying to solve P1 by using the
algorithm used to solve P2.
If we can reduce an already known undecidable problem P1 to a given problem P2 , then we can surely
say that P2 is also undecidable. If P2 was decidable, then P1 would also be decidable but that becomes a
contradiction because P1 is known to be undecidable.
1. Given a Turing machine ‘M’, we need to find out whether a state ‘Q’ is ever reached when a
string ‘w’ is entered in ‘M’. This problem is also known as the ‘State Entry problem’.
Solution :-
1. Now let’s try to reduce the Halting problem to the State Entry problem.
2. A Turing machine only halts when a transition function ? (qi,a) is not defined. Change every
undefined function ?(qi,a) to ?(qi,a) = (Q, a, L or R). Note that the state Q can only be reached
when the Turing machine halts.
3. Suppose we have an algorithm for solving the State Entry problem which will halt every time and
tell us whether state Q can be reached or not.
4. By telling us that we can or cannot reach state Q every time, it is telling us that the Turing machine
will or will not halt, every time.
5. But we know that is not possible because the halting problem is undecidable.
6. That means that our assumption that there exists an algorithm which solves the State Entry
problem and halts and gives us an answer every time, is false.
7. Hence, the state entry problem is undecidable.
2. Given two regular languages L1 and L2, is the problem of finding whether a string ‘w’ exists in
both L1 and L2, a decidable problem or not.
Solution :-
1. First we make two Turing machines TM1 and TM2 which simulate the DFAs of languages L1 and
L2 respectively.
2. We know that a DFA always halts, so a Turing machine simulating a DFA will also always halt.
3. We enter the string ‘w’ in TM1 and TM2. Both Turing machines will halt and give us an answer.
4. We can connect the outputs of the Turing machines to a modified ‘AND’ gate which will output
‘yes’ only when both the Turing machines answer ‘yes’. Otherwise it will output ‘no’.
5. Since this system of two Turing machines and a modified AND gate will always stop, this problem
is a decidable problem.
6. There are a lot of questions on this topic. There is no universal algorithm to solve them.
7. *The words ‘language’ and ‘problem’ can be used synonymously in Theory of computation. For
eg. The ‘Halting problem’ can also be written as ‘L = {<M, w> | Turing machine ‘M’ halts on
input ‘w’}’. Here ‘L’ is a language.
Halting Problem of TMs
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 −
2. Table Form :
Let’s consider following examples.
Example-1:
Explanation –
• Step-1:
We will start with tile in which numerator and denominator are starting with same number, so we can
start with either 1 or 2.
Lets go with second tile, string made by numerator- 10111, string made by denominator is 10.
• Step-2:
We need 1s in denominator to match 1s in numerator so we will go with first tile, string made by
numerator is 10111 1, string made by denominator is 10 111.
• Step-3:
There is extra 1 in numerator to match this 1 we will add first tile in sequence, string made by
numerator is now 10111 1 1, string made by denominator is 10 111 111.
• Step-4:
Now there is extra 1 in denominator to match it we will add third tile, string made by numerator is
10111 1 1 10, string made by denominator is 10 111 111 0.
• Final Solution - 2 1 1 3
Explanation –
• Step-1:
We will start from tile 1 as it is our only option, string made by numerator is 100, string made by
denominator is 1.
• Step-2:
We have extra 00 in numerator, to balance this only way is to add tile 3 to sequence, string made by
numerator is 100 1, string made by denominator is 1 00.
• Step-3:
There is extra 1 in numerator to balance we can either add tile 1 or tile 2. Lets try adding tile 1 first,
string made by numerator is 100 1 100, string made by denominator is 1 00 1.
• Step-4:
There is extra 100 in numerator, to balance this we can add 1st tile again, string made by numerator is
100 1 100 100, string made by denominator is 1 00 1 1 1. The 6th digit in numerator string is 0 which
is different from 6th digit in string made by denominator which is 1. So not in MPCP.
•If there is match in input string w, then Turing machine M halts in accepting state.
•This halting state of Turing machine is acceptance problem ATM. We know that acceptance
problem ATM is undecidable.
• Therefore PCP problem is also undecidable.
To force simulation of M, we make 2 modifications to Turing Machine M and one change to our PCP
problem.
a) M on input w can never attempt to move tape head beyond left end of input tape.
b) If input is empty string € we use _ .
c) PCP problem starts match with first domino [u1/v1] This is called Modified PCP problem.
d) MPCP = {[D] | D is instance of PCP starts with first domino}
Construction Steps –
a) Put [# / (#q0w1w2..wn#)] into D as first domino, where is instance of D is MPCP. A partial match
is obtained in first domino is # at one face is same #symbol in other face.
b) Transition functions for Turing Machine M can have moves Left L, Right R. For every x, y z in
tape alphabets and q, r in Q where q is not equal to qreject. If transition(q, x) = (r, y, R) put domino
[qx / by] into D and transition(q, x) =(r, y, L) put domino [zqx / rzy] into D.
c) For every tape alphabet x put [x / x] into D. To mark separation of each configurations put [# / #]
and [# / _#] into D .
d) To read input alphabets x even after Turing Machine is accepting state put [xqa / qa] and [qax /
qa]and [qa# / #] into D. These steps concludes construction of D.
Since this instance of MPCP, we need to convert this to PCP.
Converting Modified PCP(MPCP) to PCP :-
Given two sequence of strings w1,w2,w3…..wn and x1,x2,x3….xn over ⅀ such that
wi1,wi2,wi3….wik = xi1,xi2,xi3…..xik
• Using the diagram, we assume that P and NP are not the same set, or, in other words, we assume
that P≠NP. This is our apparently-true, but yet-unproven assertion.
• Of course, another interesting aspect of this diagram is that we’ve got some overlap
between NP and NP-Hard. We call NP-Complete when the problem belongs to both of these sets.
• So we’ve mapped P, NP, NP-Hard and NP-Complete to “easy”, “medium”, “hard” and “hardest”.
• Here, we generally prefer not to use units like “seconds” or “milliseconds”.
• Instead, we prefer proportional expressions like n,n2 ,log2(n), and nn, using Big-O notation.
• Those mathematical expressions give us a clue about the algorithmic complexity of a problem.
Problem Definitions
some common Big-O values:
• O(1) – constant-time
• O(log2(n)) – logarithmic-time
• O(n) – linear-time
• O(n2) – quadratic-time
• O(nk) – polynomial-time
• O(kn) – exponential-time
• O(n!) – factorial-time
where k is a constant and n is the input size. The size of n also depends on the problem definition. For
example, using a number set with a size of n , the search problem has an average complexity between
linear-time and logarithmic-time depending on the data structure in use.
Polynomial Algorithms
1) The first set of problems are polynomial algorithms that we can solve in polynomial time, like
logarithmic, linear or quadratic time.
2) If an algorithm is polynomial, we can formally define its time complexity as:
T(n)=O(C*nk) where C>0 and k>0 where C and k are constants and n is input size.
3) In general, for polynomial-time algorithms k is expected to be less than n.
4) Many algorithms complete in polynomial time:
• All basic mathematical operations; addition, subtraction, division, multiplication
• Testing for primacy
• Hashtable lookup, string operations, sorting problems
• Shortest Path Algorithms; Djikstra, Bellman-Ford, Floyd-Warshall
• Linear and Binary Search Algorithms for a given set of numbers
a) All of these have a complexity of O(nk) for some k, and that fact places them all in P.
b) Each input is a polynomial, multiplying them will still be a polynomial.
c) For example, in graphs, we use E for edges and V for vertices, which gives O(E*V) for Bellman-
Ford’s shortest path algorithm.
d) Even if the size of the edge set is E=V2, the time complexity is still a polynomial, O(V3), so we’re still
in n.
NP Algorithms
NP-Hard Algorithms
a) Our last set of problems contains the hardest, most complex problems in computer science.
b) They are not only hard to solve but are hard to verify as well.
c) In fact, some of these problems aren’t even decidable.
d) Among the hardest computer science problems are:
• K-means Clustering
• Traveling Salesman Problem, and
• Graph Coloring
• These algorithms have a property similar to ones in NP-Complete – they can all be reduced to any
problem in NP.
• Because of that, these are in NP-Hard and are at least as hard as any other problem in NP.
• A problem can be both in NP and NP-Hard, which is another aspect of being NP-Complete.
• Since NP and NP-Complete problems can be verified in polynomial time, proving that an
algorithm cannot be verified in polynomial time is also sufficient for placing the algorithm in NP-
Hard.
So, Does P=NP?
A question that’s fascinated many computer scientists is whether or not all algorithms in belong to:
a) It’s an interesting problem because it would mean, for one, that any NP or NP-Complete problem
can be solved in polynomial time.
b) For our definitions, we assumed that P!=NP, however ,P=NP may be possible. If it were so, aside
from NP or NP-Complete problems being solvable in polynomial time, certain algorithms in NP-
Hard would also dramatically simplify.
c) For example, if their verifier is NP or NP-Complete, then it follows that they must also be solvable
in polynomial time, moving them into P=NP=NP-Complete as well.
d) We can conclude that P=NP means a radical change in computer science and even in the real-
world scenarios. Currently, some security algorithms have the basis of being a requirement of too
long calculation time. Many encryption schemes and algorithms in cryptography are based on
the number factorization which the best-known algorithm with exponential complexity.
e) If we find a polynomial-time algorithm, these algorithms become vulnerable to attacks.
f) All NP-Complete problems are NP-Hard but all NP-Hard problems are not NP-Complete.
g) Briefly we can conclude a generalized classification as follows:
1) P, problems are quick to solve
2) NP, problems are quick to verify but slow to solve
3) NP-Complete, problems are also quick to verify, slow to solve and can be reduced to any
other NP-Complete problem
4) NP-Hard problems are slow to verify, slow to solve and can be reduced to any
other NP problem