Unit V - Toc
Unit V - Toc
UNIT V - UNDECIDABILITY
Unsolvable Problems and Computable Functions -PCP-MPCP- Recursive and recursively
enumerable languages - Properties - Universal Turing machine - Tractable and
Intractable problems - P and NP completeness - Kruskal's algorithm - Travelling
Salesman Problem- 3-CNF SAT problems.
.1 PARTIAL SOLVABILITY
Problem types
There are basically three types of problems namely
• Decidable / solvable / recursive
• Undecidable / unsolvable
• Semi decidable / partial solvable / recursively enumerable
i. Solvable Problem
A problem is said to be solvable if there exists an algorithm that can solve it in a finite amount of time,
i.e., for any input of the problem, the algorithm can produce the correct output in a finite number of
steps.
For example, the problem of finding the sum of two integers is solvable, since there exists a
simple algorithm that can add two integers in a finite number of steps.
ii. Unsolvable Problem
A problem is said to be unsolvable if there does not exist any algorithm that can solve it in a finite amount of
time.
One well-known example of an unsolvable problem is the Halting problem, which asks whether a given
program will eventually halt or run forever.
It has been proven that there is no algorithm that can solve the Halting problem for all possible inputs.
1
IV AIML AIPC701- Theory of Computation
Consider a Turing machine, M that halts with either “yes” or “no” after computing the input.
.2 UNSOLVABLE PROBLEMS
• If a language is recursive then it is called decidable language and if the language is not recursive then such a
language is called undecidable language.
• The class of decidable problems are also called as solvable problems and the class of undecidable
problems is called unsolvable problems.
.2.1 Decidability Problems Concerning Regular Languages
• The decidability problems concerning regular languages can be understood with the help of following
theorems.
2
IV AIML AIPC701- Theory of Computation
• Similarly obtain the set of strings which T(M2) accepts and T(M1) rejects. That is
• If these two sets are empty then it shows that L(M1) and L(M2) are equivalent and can be simulated by
Turing Machine for the set of languages as
• This shows that two DFA's are equivalent or not is a recursive problem.
Proof: (ii)
• Let M be the NFA and input word w which decides if M accepts w. Convert this NFA to DFA. Then run the
algorithm for DFA on Turing machine T(M). The Turing Machine T(M) accepts w if and only if M reaches a
final state on w otherwise rejects. This shows that NFA accepts a word or not is recursive.
Theorem 2: Prove that following decision problem is recursive: DFA accepts a word or not.
Proof:
• Let M be the DFA and input word w which decides if M accepts w. Simulate an algorithm for DFA to run on
Turing machine T(M). The Turing Machine T(M) accepts w if and only if M reaches a final state on w
otherwise rejects. This shows that DFA accepts a word or not is recursive.
.2.2 Decidability Problems Concerning Context Free Languages:
The undecidable problems about CFG are
i. Whether or not two different context free languages define the same language?
ii. Whether given CFL is ambiguous or not?
iii. Whether complement of given CFL is context free language?
iv. Whether the intersection of two context free languages is context free?
There is no algorithm to answer these questions. Hence these problems are known as undecidable problems.
.3 UNSOLVABLE PROBLEM ABOUT TURING MACHINE
• The undecidable problem about Turing machine is given by halting problem. Let us understand this
.3.1 Halting Problem:
Q1. Explain the Halting problem. Is it decidable or undecidable Problem? [Nov/DEC 2011,
Nov/Dec 2012] (or) State and prove the halting problem. [Nov/Dec 2022, May/June 2016]
• The halting problem is the problem of finding if the program/machine halts or loop forever.
• The halting problem is un-decidable over Turing machines.
Description
• Consider the Turing machine, M and a given string w, the problem is to determine whether M halts by
either accepting or rejecting w, or run forever.
Example
while (1)
{
prinf(“Halting problem”);
}
3
IV AIML AIPC701- Theory of Computation
• The above code goes to an infinite loop since the argument of while loop is true forever.
• Thus, if doesn't halt.
• Hence Turing problem is the example for undecidability.
• This concept of solving the halting problem being proved as undecidable was done by Alan Turing in
1936.
• The undecidability can be proved by reduction technique.
Representation of the halting set
The halting set is represented as,
1, if M halts on input w
h(M,w) = f(x) =
0, otherwise
where,
M Turing Machine
w Input string
Construction of H2
4
IV AIML AIPC701- Theory of Computation
Construction of H3
.4 COMPUTABLE FUNCTIONS:
• The problem of finding out whether a given problem is solvable or not is based on evaluation of function on
the set of natural number or by a given alphabet.
• Let us start by defining three important types of functions
5
IV AIML AIPC701- Theory of Computation
7
IV AIML AIPC701- Theory of Computation
NO
NO
NO
• Hence M3, M2, M1 halt with either YES or NO on all possible inputs.
• Thus, the union of two recursive languages is also recursive.
Property - 2: A language is recursive if and only if both it and its complement are recursively enumerable.
Proof:
• Let L and L be two recursively enumerable languages accepted by the Turing machines M1 and M2. If a
string, w є L, it is accepted by M1 and M1 halts with answer “YES”. Else M1 enters into infinite loop.
• If a string, w є L [w ∉ L], then it is accepted by M2 and M2 halts with answer “YES”. Otherwise M2 loops
forever.
• The Turing machine, M3 that simulates M1 and M2 simultaneously is given as
• From the above design of TM, if w є L, if w C L, then M1 accepts w and halts with “YES”.
• If w є L , then M2 accepts w [w є L] and halts with “YES”.
• Since M1 and M2 are accepting the complements of each other, one of them is guaranteed to halt for
every input, w є ∑*.
• Hence M3 is a Turing machine that halts for all strings.
• Thus if the language and its complement are recursively enumerable, then they are recursive.
8
IV AIML AIPC701- Theory of Computation
Property — 3: The complement of a recursive language is recursive.
Proof:
• Let L be a recursive language accepted by the turning machine, M1.
• Let L be a recursive language accepted by the Turing machine M2.
• The construction of MI and M2 are given as,
• Here the output of M1 and M2 are written on the input tape of M3.
• The turning machine, M3 returns “YES”, if at least one of the outputs of M1 and M2 is “YES”.
• The M3 decides on L1 U L2 that halts with the answer, “YES” if w є L1 or w є L2.
• Else M3 loops forever if both M1 and M2 loop forever.
• Hence the union of two recursively enumerable languages is also recursively enumerable.
9
IV AIML AIPC701- Theory of Computation
10
IV AIML AIPC701- Theory of Computation
• Here the output of MI and M2 are written the input tape of M3. The machine, M3 returns “YES” if both the
outputs of M1 and M2 is “YES”.
• If at least one of M1 or M2 is NO it rejects “w” and never halts.
• Thus, M3 decides on L1 n L2 that halts if and only if w є L1 and w є L2. Else M3 loops forever along with M1
or M2 or both.
• Hence the intersection of two recursively enumerable languages is recursively enumerable.
Example:
DOMINOs FORM
1 Consider the set of dominos. Does the PCP have a solution?
11
IV AIML AIPC701- Theory of Computation
Solution:
we need to find a sequence of dominos such that the top and bottom strings are the same.
12
IV AIML AIPC701- Theory of Computation
1 11 111
2 100 001
3 111 11
Then the solution is
w1w2w3 = x1x2x3
11100111 = 11100111
That means it is essential to have w1 and xi at the beginning of the list.
5.4.1. Theorem: Prove that MPCP reduces to PCP.
Q8. Prove that ”MPCP reduces to PCP”. [Nov/Dec 2015, Apr/May 2021]
Proof: To prove that modified PCP is decidable we have to show that PCP is decidable. That is MPCP reduces to
PCP.
While proving this we will consider some instance of MPCP with ∑. Then we construct an instance of PCP by
introducing new symbol *. The construction PCP will be done by following method.
- Let we are given an instance of MPCP with lists A = w1, w2, .... wk and B = xl, x2,…xk. Now we will
insert new symbols * and $ in ∑.
D= z0,z1, .... zk +1 as follows
i. For i = 1, 2, 3, ...... k. Assign wi = yi * and xi = *zi.
For example, consider
List A List C
zi
1 11 111 1 1*1* *1*1*1
2 100 001 2 1*0*0* *0*0*1
3 111 11 3 1*1*1* *1*1
13
IV AIML AIPC701- Theory of Computation
ii. Now assign y0 = * y1 and z0 = z1. That means first pair and zeroth pair should be same except that zeroth pair
has extra * at the beginning of the string from first list. Whereas from the second list zeroth and first pair
must be the same.
For example, consider
List C
zi yi zi
0 *1*1* *1*1*1
1 1*1* *1*1*1 1 1*1* *1*1*1
* *
2 1 0 0* *0*0*1 2 *0*0*1
* *
3 1 1 1* *1*1 3 *1*1
iii. Now construct the last pair yk +1 and zk +1 put yk • i = $ and Zk • l = * $
For example,
List C List D
i yi zi
0 *1*1* *1*1*1
1 1*1* *1*1*1
2 1*0*0* *0*0*1
3 1*1*1* *1*1
4 $ *$
iv. Now suppose i1, i2, .... im is a solution to the given MPCP with lists A and B. Then we can replace w1, wi1,
.... Wim = x1, xi1, .... xim by * y1, yi1, .... yim= zi, zi1, ......... zim*.
For example, if above problem has a solution (1,2,3) then * yi, y2, y3 = z1, Z2, Z3 *
i.e * 1*1*1*0*0*1*1*1* = * 1*1*1*0*0*1*1*1*
v. But since y0 = * y1 and zo = z1 we can fix the initial * by replacing first index by 0 then we have yo
y1 yi1 .... yim = zo zi zi1,….zim*.
For example,
yo y2 y3
*1*1* 1*0*0* 1*1*1*
ZO Z2 Z3
*1*1*1 *0*0*1 *1*1
yo yz y3 = z0 Z2 Z3 *.
*1*1* 1*0*0*1*1*1* = * 1*1*1*0*0*1*1*1*
vi. Now we can take care of final * by appending the index k + 1. i.e. yk + i = $ and Zk +1 = * $. Then we have
y0 yr yi1 .... you yk + i = zo zi zi1,...... zim Zk +1•
For example,
y0 y2 y3 y4
*1*1* 1*0*0* 1*1*1* $
Z0 ZZ Z3 Z4
*1*1*1 *0*0*1 *1*1 *$
14
IV AIML AIPC701- Theory of Computation
yo yz y3 yr = Z0 z2 z3 Z4
*1*1* 1*0*0*1*1*1*$ = * 1*1*1*0*0*1*1*1*$
Thus 0, i1,12, ... im, k +1 has a solution to the instance of PCP.
vii. Similarly we can show that if constructed instance of PCP has a solution, then original MPCP also have a
solution. The solution of PCP must begin with index 0 and end with index k + 1. Thus solution to PCP can be 0, i1,
i2, .... im, k +1. We can claim that i1,12,… . im is a solution to the instance of PCP. (i.e. remove * $ and $ from
the strings)
So, for PCP
y0 y1 yil .... yim yk + 1 = Z0 zl zi1, Ztm Zk + 1.
which follows that w1 wi1 wi2 ..... Wim - x1 xil xi2 xim
Thus a solution to the PCP instance implies a solution to MPCP instance. Hence reduction of MPCP to PCP
confirms that if PCP were decidable then MPCP would also be decidable.
Example:
1. Let A= {001, 0011, 11, 101} and B={01, 111, 111, 010}. Does a pair (A,B) have post correspondence
(PC) solution? Does the pair (A,B) have modified posts correspondence (MPC) solution?
Solution: The solution can be (3,4,1) ie a3 a4 a1 = b3 b4 b1
11101001 = 11101001
Consider
List A List C
yi
1 001 01 1 0*0*1* *0*1
2 0011 111 2 0*0*1*1* *1*1*1
3 11 111 3 1*1* *1*1*1
4 101 010 4 1*0*1* *0*1*0
Assign y0 = * y1 and Z0 = Z1
List C List D
i yi zi
0 *0*0*1* *0*1
1 0*0*1* *0*1
2 0*0*1*1* *1*1*1
3 1*1* *1*1*1
4 1*0*1” *0*1*0
15
IV AIML AIPC701- Theory of Computation
2. State whether the instances of the post correspondence problem (PCP) have a solution. The
following are the instances with ∑ = {0,1} [Nov/Dec 2022]
Index List A List B
1 10 01
2 110 011
3 110 01
4 000 00
5 10 010
In case the PCP has a solution, describe the post correspondence solution with justification.
Solution:
Step 1: Start with tile in which numerator and denominator are starting with same number, so we can start
with tile 4. String made by numerator and denominator is
A4 000
B4 00
Step 2: We need 0’s in denominator to match 0’s in numerator. So we will go with tile 2. String made by
numerator and denominator is
A4A2 000110
B4B 00011
2
Step 3: We need 0’s in denominator to match 0’s in numerator. We will go with tile 1. String made by
numerator and denominator is
A4A2A1 00011010
B4B2Al 0001101
Step 4: There is extra 0’s in numerator to match this with 0 in denominator. We will add tile 5.
String made by numerator and denominator is
Assign yo = * y1 and zo = z1
If * y0, yi, y2, y3 ..... yk = zo,z1, z2, Z3 ....... zk * the MCP has solution. Consider the solution (4, 2, 1, 5) then
* y4 y2 y1 y5= z4 Z2 Z1 z5
17
IV AIML AIPC701- Theory of Computation
∑={a,b}
ґ={a,b,X,B}
w=aba
18
IV AIML AIPC701- Theory of Computation
19
IV AIML AIPC701- Theory of Computation
20
IV AIML AIPC701- Theory of Computation
Yes Yes
X
Q12. Prove that the diagonalization language (L d) is not a recursively enumerable. [April/May
2018] (or) State and prove that “Diagonalization language is not recursively enumerable”.
[Nov-Dec 2021] (or) Prove that Ld is not Recursively Enumerable [Apr/May 2004, 2005, 2006,
Nov/Dec 2004, 2005, 2008J (or) Define the language Ld. Show that Ld is not recursively
enumerable?
The language Ld, the “diagonalization” language, is the set of strings wi such that wi is not in L(Mi).
L(Mi) =Φ if wi is valid Turing machine code.
That is, Ld consists of all strings w such that the Turing Machine M whose code in w does not accept the input w.
It is clear that the below table tells for all i and j, whether the Turing Machine Mi accepts input string wj:
• if (i,j)= 1 means "yes it is accepted" and
• if (i,j)= 0 means "no it doesn't" accepted or rejected.
21
IV AIML AIPC701- Theory of Computation
We may think of the ith row as the characteristic vector for the language L(Mi); that is, the 1's in this row
22
IV AIML AIPC701- Theory of Computation
23
IV AIML AIPC701- Theory of Computation
24
AIPC701- Theory of Computation
IV AIML
• We define Lu, the universal language, to be the set of binary strings that encode, a pair (M, w), where M is a
TM with the binary input alphabet, and w is a string in (0+1)*, such that w is in L(M).
• That is, Lu is the set of strings representing a TM and an input accepted by that TM.
• We shall show that there is a TM U, often called the universal Turing machine, such that, Lu = L(U). Since the
input to U is a binary string, U is in fact some M in the list of binary-input Turing machines.
• It is easiest to describe U as a multi tape Turing machine.
• The transitions of M are stored initially on the first tape, along with the string w.
• A second tape used to hold the simulated tape of M, using the same format as for the code of M. That is,
tape symbol Xi of M will be represented by 0i, and tape symbols will be separated by single l's.
• The third tape holds the state of M, with state qi where i is represented by 0's.
• The UTM is a recognizer but not a decider.
25
AIPC701- Theory of Computation
IV AIML
Q15. Explain the difference between Turing Machine and Universal Turing Machine.
Turing Machine Universal Turing Machine
1. It is a mathematical model of computation it Universal Turing Machine is like a single Turing
manipulates symbols on the tape according Machine that has a solution to all problem that is
to the rules defined computable
2. A program can be compared to a Turing Programmable Turing Machine is called Universal
Machine Turing Machine
3. Turing machine's temporary storage is tape. Universal Turing Machine contains Turing
The infinite cells of the Turing machine can Machine description as input along with an input
contain input symbols and blanks. string, runs the Turing Machine on the input and
returns the result.
4. Turing machines help us understand the Although developed for theoretical reasons, it
fundamental limitations of mechanical helped in the development of stored program
computation power computers
5. A Turing machine is a formal model of a Universal Turing Machine provides a solution to
computer with a fixed program problems that are computable
6. It does not minimize the space complexity It minimizes space complexity
7, Transition function which Turing Machine The transition function is Q x TQ x T {L, R},
performs is defined as: δ X T -> Q X T X {L,R}, where Q is a finite set of states, T is the tape of the
where 6 is the transition function alphabet
8. In the set theory point of view, all Turing Universal Turing Machine is a subset of all the
machines forma set of the all the device that Turing Machines
accepts type 0 grammar
26
AIPC701- Theory of Computation
Definition of P
• “p” stands for polynomial.
• Problems that can be solved in polynomial time.
• The polynomial time is nothing but the time expressed in terms of polynomial.
• Examples — Kruskal problem, searching of key element, sorting of elements, All pair shortest path.
Definition of NP
• It stands for “non-deterministic polynomial time”.
• Note that NP does not stand for “non-polynomial”.
27
AIPC701- Theory of Computation
• The NP class problems are those problems that can be solved in non-deterministic polynomial time but can
be verified in polynomial time.
• Examples — Travelling Salesperson problem, graph coloring problem, Knapsack problem, Hamiltonian
circuit problems.
For example:
Consider an example of sudo-ku game. In order to solve this entire puzzle, the algorithm would have to
check each 3 X 3 matrix to see which numbers are missing then each row, then each column and then make
sure there are no repetitions of any digit from 0 — 9. This becomes more complex because the number of digits
that are missing is inconsistent in each row, column and matrix. Solving this problem is not possible in
polynomial time. But once we get the solution, then verifying this solution is possible within very less time.
Thus verification of solution of this problem is possible in polynomial time.
• The NP class problems can be further categorized into NP complete and NP hard Problems.
NP
• All NP-complete problems are NP-hard but all NP-hard problems cannot be NP-complete.
• The NP complete problems are intersection of NP class problems and NP hard problems.
• Normally the NP complete problems are decision problems (For example — is a graph Euler graph or
not?)
• The NP hard problems are optimization problems (For example — shortest path problem)
• The NP class problems are the decision problems that can be solved by non-deterministic polynomial
algorithm.
5.14.1 Computational complexity
• The computational problem is an infinite collection of instances with a solution for every instance.
• In computational complexity the solution to the problem can be "yes" or "no" type. Such type of
problems are called decision problem. The computational problems can be function problem. The
function problem is a computational problem where single output is expected for every input. The
output of such type of problems is more complex than the decision problem.
• The computational problems also consists of a class of problems, whose output can be obtained in
polynomial time.
Complexity classes —
• The complexity classes is a set of problems of related complexity.
• It includes function problems, P classes, NP -classes, optimization problem.
Intractability -
• Problems that can be solved by taking a long time for their solutions is known as intractable
problems.
• If NP is not same as P then NP complete problems are called intractable problems.
• The P class problems are considered as tractable problems.
5.14.2 Example of P class problem
Kruskal's algorithm:
• In Kruskal's algorithm the minimum weight is obtained.
• In this algorithm also the circuit should not be formed.
• Each time the edge of minimum weight has to be selected, from the graph.
• It has edges of minimum weights to be adjacent.
• Let's solve one example by Kruskal's algorithm
Example:
1. Find the Minimum Spanning Tree for the following graph using Kruskal's algorithms.
29
AIPC701- Theory of Computation
Solution:
Step 1: Initial configuration Step 2: Select an edge e — g
b b
a e d
f
Total Weight = 0 Total Weight = 1
Step 3: Select an edge a — e Step 4: Select an edge e — f
b b
Total Weight = 3
Total Weight = 5
Step 5: Select an edge e — c Step 6: Select an edge c - b
b
Total Weight = 10
Total Weight = 7
Step 7: Select an edge c -d
Total Weight = 13
Action of Kruskal's algorithm
Edge Weight Action
(e,g) 1 ACCEPTED
(a,e) 2 ACCEPTED
(e,f) 2 ACCEPTED
(e,c) 2 ACCEPTED
(b,c) 3 ACCEPTED
(c,d) 3 ACCEPTED
(d,g) 3 REJECTED
30
AIPC701- Theory of Computation
2 3
• The tour path will be a-b-d-e-c-a and total cost of tour will be 16.
• This problem is NP problem as there may exist some path with shortest distance between the cities.
• If you get the solution by applying certain algorithm then travelling salesman problem is NP complete
problem.
• If we get no solution at all by applying an algorithm then the travelling salesman belongs to NP hard
class.
5.14.4 Difference between P and NP class
P NP
An algorithm in which for given input the An algorithm is called non deterministic
definite output gets generated is called polynomial time algorithm (NP class) when for
polynomial time algorithm (P class) given input there are more than one paths that the
algorithm can follow. Due to which one cannot
determine which path is to be followed after
particular stage.
Time is fixed. Time is not fixed.
In polynomial time, the input is fixed. In NP, the input is not fixed.
Use a deterministic Turing machine They can only be solved deterministically in
exponential time
Every problem which is a P class is also in NP Every problem which is in NP class is not in the P
class. class.
The process is fixed. The process is not fixed.
31
AIPC701- Theory of Computation
All P problems are deterministic in nature. P All the NP problems are non-deterministic in
Selection sort, Linear search. NP problems which, given a proposed solution, we can
efficiently check if it works.
Example: Prime number is a relatively easy
TSP, Knapsack problem.
problem to solve.
Example: Travelling salesman problem
5.15 SAT PROBLEM
• SAT(Boolean Satisfiability Problem) is the problem of determining if there exists an interpretation that
satisfies a given boolean formula.
• It asks whether the variables of a given boolean formula can be consistently replaced by the values TRUE or
FALSE in such a way that the formula evaluates to TRUE.
• If this is the case, the formula is called satisfiable.
• On the other hand, if no such assignment exists, the function expressed by the formula is FALSE for all
possible variable assignments and the formula is unsatisfiable.
Example: An example of a Boolean expression is x^ (y v z). The subexpression y v z is true whenever either
variable y or variable z has the value true, but the subexpression is false whenever both y and z are false. The
larger subexpression (y v z) is true exactly when y v z is false, that is, when both y and z are false. If either y or
z or both are true, then (y v z) is false.
Finally, consider the entire expression. Since it is the logical AND of two subexpressions, it is true exactly
when both subexpressions are true. That is, x^ (y v z) is true exactly when x is true, y is false, and z is false.
5.15.2 CNF - SAT Problem
• This problem is based on Boolean formula. The Boolean formula has various Boolean operations such as
OR (+), AND (.) and NOT. There are some notations such as (means implies) and (means if and
only if).
• A Boolean formula is in Conjunctive Normal Form (CNF) if it formed as collection of subexpressions.
These subexpressions are called clauses.
• For example This formula evaluates to 1, if b,c, d are 1.
32
AIPC701- Theory of Computation
• The CNF — SAT is a problem which takes Boolean formula in CNF form and checks whether any
assignment is there to Boolean values so that formula evaluates to 1.
NP Complete Problem
• For the proof of particular problem as NP complete problem we need to apply the reduction technique.
That means there are some problems which are already proved as NP complete problems and using
these problems we can prove that the problem in hand is NP complete.
Steps for proving NP Complete
Consider that we have to prove that B is in NP
Step 1: Select an NP complete language say A.
Step 2: Construct a function f that maps the members of A to members of B. Step 3:
Show that x is in A if and only if f(x) is in B.
Step 4: Now show that the function f can be computed in polynomial time.
Step 5: This if A is NP complete and it can be reduced to B in polynomial time, then B comes out to be NP
complete.
5.15.3 Prove that SAT problem is NP complete
Q18. Prove that SAT problem is NP complete.
Proof:
SAT is in NP:
• It any problem is in NP, then given a ’certificate’, which is a solution to the problem and an instance of the
problem(a boolean formula f) we will be able to check (identify if the solution is correct or not)
certificate in polynomial time. This can be do ne by checking if the given assignment of variables satisfies the
boolean formula.
SAT is NP-Hard:
• In order to prove that this problem is NP-Hard then reduce a known problem, Circuit-SAT in this case to
our problem. The boolean circuit C can be corrected into a boolean formula as:
i. For every input wire, add a new variable yi.
ii. For every output wire, add a new variable Z.
iii. An equation is prepared for each gate.
iv. These sets of equations are separated by o values and adding D Z at the end.
This transformation can be done in linear time or polynomial time.
The following propositions now hold:
If there is a set of input, variable values satisfying the circuit then it can derive an assignment for the
formula f that satisfies the formula. This can be simulated by computing the output of every gate in the
circuit.
If there is a satisfying assignment for the formula f, this can satisfy the boolean circuit after the
removal of the newly added variables.
For Example: If below is the circuit then:
33
AIPC701- Theory of Computation
Fig: Reducing circuit satisfiability to formula satisfiability. The formula produced by the reduction
algorithm has a variable for each wire in the circuit.
circuit would have the corresponding formula x4
x4=x3
x5 = (x1 V x2)
x6 = x4
x7 = (x1 ^ x2 ^ x4)
x8 = (x5 V x6)
x9 = (x6 V x7)
x10 = (x7 ^ x8 ^ x9)
f = x5 ^ x4 ^ x6 ^ x7 ^ x8 ^ x9 ^ x10
Thus if we could solve the Boolean satisfiability problem in polynomial time, we could solve the circuit
satisfiability problem in polynomial time (and by extension any NP problem in polynomial time). Hence SAT is
also an NP complete problem.
5.16 3-CNF SATISFIABILITY
Q19. Prove that 3 -SAT problem is NP complete.
• If the Boolean expression consists of exactly 3 OR ‟ed variables per clause with all the clauses being
AND'ed, then the expression is said to be in 3-CNF form (conjunctive normal form).
Problem
• Given a 3-CNF expression, find an assignment of the literals that satisfies the expression, i.e., causes the
expression to evaluate to 1. It can be shown that 3-CNF is also NP-complete by reducing general Boolean
satisfiability to 3-CNF.
Proof
• The reduction is performed in three steps:
Step 1: Convert clauses into a binary parse tree
• Since each Boolean operator is a binary operator, we simply construct a binary parse tree where the nodes
are the operators and the literals are leaves.
• In the case of clauses with multiple literals, we simply add associative parentheses as needed to make
binary clauses.
34
AIPC701- Theory of Computation
• We then construct a new expression, similarly to the above reduction from circuit satisfiability to
Boolean satisfiability, by AND'ing the clauses representing each node with the final output.
• Since for any assignment of p, one of the clauses will evaluate to the origin al and the other will
evaluate to 1 (thus not changing the final result of the original expression).
• If the clause contains 1 literal, then create four AND'ed clauses that contain p and p and q and q.
• In other words, for the clause (xi) replace it with
(xi V p V q) ^ (xi V p V q) ^ (xi V p V q) ^ (xi V p V q)
• Again, since any assignment of p and q will make one of the clauses evaluate to the original and all the
others evaluate to 1.
• This procedure can be done in polynomial time since the first step adds at most one variable and one clause
per operator in the original expression, the second step adds at most 8 clauses (since for 3 literals the
truth table has 8 rows), and the third step adds at most 4 clauses.
•
• Thus the product of these steps remains a constant factor. Since the procedure basically applies the laws
of discrete math, the final 3-CNF expression will be satisfiable if and only if the original Boolean
expression is satisfiable.
35
AIPC701- Theory of Computation
UNIT V - UNDECIDABILITY
Two Marks
1. Define Solvable.
A problem is said to be solvable if there exists an algorithm that can solve it in a finite amount of time, i.e.,
for any input of the problem, the algorithm can produce the correct output in a finite number of steps. For
example, the problem of finding the sum of two integers is solvable, since there exists a simple algorithm that can
add two integers in a finite number of steps.
2. Define Unsolvability. (Or) What is unsolvable problem? Give example. [Apr. / May 2019]
A problem is said to be unsolvable if there does not exist any algorithm that can solve it in a finite
amount of time. One well-known example of an unsolvable problem is the Halting problem, which asks
whether a given program will eventually halt or run forever. It has been proven that there is no algorithm that
can solve the Halting problem for all possible inputs.
3. Define Semi decidable (or) partial solvable.
• A problem, P is said to be semi decidable, if P is recursively enumerable.
• A problem is RE if M terminates with “YES” if it accepts w C L; and doesn't halt if w C L.
• Then the problem is said to be partial solvable / Turing acceptable.
4. When a problem is said to be decidable and give an example of undecidable problem. [Nov/Dec-
2003,20 12, 2015, May-06,05]
A problem whose language is recursive is said to be decidable. Otherwise, the problem is undecidable. The
class of problems which can be answered as “Yes” are called solvable or decidable. The class of problems which can
be answered as “No” are called undecidable problems.
Following are undecidable problems.
i) Whether the language accepted by a TM is empty.
ii) Whether the language accepted by a TM is regular language.
iii)Whether the language accepted by a TM is context free language.
5. When we say a problem is decidable (Or) Define Decidable Problem?
A problem whose language is recursive is said to be decidable. Otherwise the problem is said to be
undecidable. Decidable problems have an algorithm that takes as input an instance of the problem and
determines whether the answer to that instance is “yes” or “no”.
37
AIPC701- Theory of Computation
• There is a Turning Machine (M), over an alphabet ∑(a,b), the problem is : does M halt when it is given w
as an input string.
• A halting problem is undecidable.
14. What are some other well-known undecidable problems related to a Turing Machine?
The Membership, Finiteness, and Emptiness of a Turing Machine are all well-known undecidable
problems related to a Turing Machine.
15. When a language is said to be recursive? Is it true that every regular set is not recursive?
[Nov/Dec 2005, Apr/May 2021]
• A language L is said to be recursive if there exists a Turing machine M that accepts every string of the
language L, and goes to halt state or else rejects those strings that are not in the language L.
• If the input is accepted, M halts with the answer,” YES”
• w C L the Turing machine doesn't accept the string.
• If w C L, then M halts with answer, “NO”.
• The recursive languages are called Turing decidable languages
• Recursive language will halt on every input.
Accept
Input String Reject
YES (if w є L)
Input String Loop Forever(i f w ∉ L)
38
AIPC701- Theory of Computation
39
AIPC701- Theory of Computation
Accept
w
Input String Reject
For instance: for given input whether the TM will eventually halt is or not? This is undecidable and
hence is not recursively enumerable.
27. What are the properties of recursive and recursively enumerable language? [Nov-Dec20 17]
1. The union of two recursive language is recursive.
2. The language L and its complement L are recursively enumerable, then L is recursive.
3. The complement of a recursive language is recursive.
4. The Union of two recursively enumerable languages is recursively enumerable.
5. The intersection of two recursive language is recursive.
6. The intersection of two recursively enumerable language is recursively enumerable.
28. Show that the complement of a recursive language is recursive. [Dec-04, may-05] Proof
• Let L be a recursive language accepted by the turning machine, M1.
• Let L be a recursive language accepted by the Turing machine M2.
• The construction of M1 and M2 are given as,
41
AIPC701- Theory of Computation
• In the modified PCP, there is the additional requirement on a solution that the first pair on the A and B lists
must be the first pair in the solution.
• More formally, an instance of MPCP is two lists A=w1, w2.... wk and B=x1, x2. xk and a solution is a list
of 0 or more integers i1 ,i2,. im such that
wi1, wi2..... wim, = xi1, xi2,…. xim.
• Note that the pair (w1, x1) is forced to be at the beginning of the two strings, even though the index 1 is not
mentioned at the front of the list that is the solution.
• Also, unlike PCP, where the solution has to have at least one integer on the solution list, in MPCP, the
empty list could be a solution if wi = xi (but those instances are rather uninteresting and will not figure in our
use of MPCP).
It is clear that the below table tells for all i and j, whether the Turing Machine Mi accepts input string Wj:
• if (i,j)= 1 means "yes it is accepted" and
• if (i,j)= 0 means "no it doesn't" accepted or rejected.
We may think of the ith row as the characteristic vector for the language L(M;); that is, the 1's in this row
indicate the strings that are members of this language.
42
IV AIML AIPC701- Theory of Computation
43
IV AIML AIPC701- Theory of Computation
47. What are the features of Universal Turing machine? [May 2007]
Following are the features of Universal Turing machine (UTM).
Universal Turing machine is a kind of turing machine can simulate any other turing machine. In other
words, UTM is a single machine used to compute any computable sequence.
Another interesting feature of UTM is that it has an ability to manipulate an unbounded amount of data
in finite amount of time.
48. What are the concepts used in UTMs?
• Stored program computers.
• Interpretive Implementation of Programming languages.
• Computability.
49. What are the two classes of problems that are solved by the Turing machine?
The two classes of problems that can be solved by the Truing machines are as follows.
1. Those problems that have an algorithm
2. Those that are only solved by Turing machine.
50. What is the weak-form of Turing thesis?
A Turing Machine can compute anything that can be computed by a general purpose digital computer.
51. What is the strong-form of Turing thesis?
A Turing Machine can compute anything that can be computed. This is the strong form of Turing thesis.
52. What are the reasons for a TM not accepting its input?
i) The TM may halt in a non final state.
ii) The TM may enter into an indefinite loop.
53. Give the difference between Turing Machine and Universal Turing Machine.
Turing Machine Universal Turing Machine
1. It is a mathematical model of computation it Universal Turing Machine is like a single Turing
manipulates symbols on the tape according Machine that has a solution to all problem that is
to the rules defined computable
2. A program can be compared to a Turing Programmable Turing Machine is called Universal
Machine Turing Machine
3. Turing machine's temporary storage is tape. Universal Turing Machine contains Turing Machine
The infinite cells of the Turing machine can description as input along with an input string, runs the
contain input symbols and blanks. Turing Machine on the input and returns the
result.
4. Turing machines help us understand the Although developed for theoretical reasons, it
fundamental limitations of mechanical helped in the development of stored program
computation power computers
5. A Turing machine is a formal model of a Universal Turing Machine provides a solution to
computer with a fixed program problems that are computable
6. It does not minimize the space complexity It minimizes space complexity
44
IV AIML AIPC701-Theory of Computation
7, Transition function which Turing Machine The transition function is QxT —> Qx T x {L, R},
performs is defined as: δ X T -> Q X T X {L,R}, where Q is a finite set of states, T is the tape of the
where ó is the transition function alphabet
8. In the set theory point of view, all Turing Universal Turing Machine is a subset of all the
machines forma setof the all the device that Turing Machines
accepts type 0 grammar
45
IV AIML AIPC701- Theory of Computation
1. Search problems
The answers in a search problem can be arbitrary strings. Search problems can be represented as search relations
(relations that consist of all the instance -solution pairs).
2. Counting problems
These problems ask for the number of solutions for a particular search problem. They are represented by a function
f from {0,1}* to the nonnegative integers.
3. Optimization problems
Such problems seek to find the best possible solution from the set of all the possible solutions to a search
problem. These problems can be represented by their search relations.
4. Function problems
In these problems, for every input, there is a single output expected. These outputs are far more co mplex than the
outputs for decision problems. The answer can't just be ‟yes‟ or ‟no‟.
59. What is meant by computational complexity?
• Computational complexity refers to the complexity of an algorithm. It is the amount of resources that are
needed to run the algorithm and specifically focuses on time and memory requirements.
• The computational complexity of a problem is essentially the complexity of the best algorithms that make
it possible to solve the problem.
46
IV AIML AIPC701- Theory of Computation
63. Mention the features of P class.
The solution to P problems is easy to find.
P is often a class of computational problems that are solvable and tractable. Tractable means that the problems
can be solved in theory as well as in practice. But the problems that can be solved in theory but not in practice
are known as intractable.
64. Define the class NP problem. [Nov/Dec-13, Nov-Dec 2019]
The NP stands for non-deterministic polynomial time. That means all the problems in this class are
solved in non-deterministic polynomial time. The problems belonging to this class are - Traveling
salesperson problems, graph coloring problem and Knapsack problem.
65. Give examples for NP-complete Problems.
The NP- complete problems are — Traveling salesperson problems, graph coloring problem, 0/1
knapsack problem, Hamiltonian circuit problem.
66. Mention the features of NP class.
The solutions of the NP class are hard to find since they are being solved by a non -deterministic
machine but the solutions are easy to verify.
Problems of NP can be verified by a Turing machine in polynomial time.
67. Mention the difference between P and NP problems. [May-2012, Apr/May 2021]
P NP
An algorithm in which for given input the An algorithm is called non deterministic polynomial
definite output gets generated is called time algorithm (NP class) when for given input there are
polynomial time algorithm (P class) more than one paths that the algorithm can follow. Due to
which one can not determine which path is to be
followed after particular stage.
Time is fixed. Time is not fixed.
In polynomial time, the input is fixed. In NP, the input is not fixed.
Use a deterministic Turing machine They can only be solved deterministically in exponential
Time
Every problem which is a P class is also in Every problem which is in NP class is not in the P class.
NP class.
The process is fixed. The process is not fixed.
All P problems are deterministic in nature. All the NP problems are non-deterministic in nature.
P problems can be efficiently solved. NP problems which, given a proposed solution, we can
efficiently check if it works.
Selection sort, Linear search. TSP, Knapsack problem.
Example : Prime number is a relatively easy Example: Travelling salesman problem
problem to solve.
47
IV AIML AIPC701- Theory of Computation
ii) Every problem in NP can also solved in polynomial time.
69. Write the significance of NP problems. [Nov/Dec 2022]
• NP- problems are significant because all NP- problems are thought of having similar hardness, in that
process solving one implies that others are solved as well.
• If some NP- problems are proven to be in P, then all of NPs are proven to be in P.
• Because, note that any NP language can be reduced to an NP -complete language. Use this reduction and
the algorithm for the given NP-complete problem to solve any problem in NP. Hence all of them will
have polynomial time solutions.
70. What is an NP-complete problem?
• An NP-hard problem also in NP is called NP-complete. That is, one of the NP problems is as hard as every
other problem in NP, and solving that problem will solve all NP problems.
• All NP-complete problems are NP-hard but all NP-hard problems cannot be NP-complete.
• The NP complete problems are intersection of NP class problems and NP hard problems.
71. Define NP Complete class.
A problem is NP-complete if it is both NP and NP-hard. NP-complete problems are the hard problems
in NP.
72. What are the features of NP Complete?
NP-complete problems are special as any problem in NP class can be transformed or reduced into NP-
complete problems in polynomial time.
If one could solve an NP-complete problem in polynomial time, then one could also solve any NP
problem in polynomial time.
73. Give examples for NP — Complete Problem. [Nov/Dec 2014]
Some example problems include: Decision
version of 0/1 Knapsack.
Hamiltonian Cycle.
Satisfiability.
Vertex cover.
74. Give the difference between NP hard and NP complete.
NP hard NP complete
In NP-Hard, Time is unknown. In NP-Complete Time is not fixed.
The input in the NP-hard problem is undefined. The input in the NP-complete problem is not
fixed.
Not all NP-hard problems are NP-complete. All NP-complete problems are NP-hard.
The process is undefined. The process is not fixed.
NP-hard problems that are, in a certain sense, are NP-complete problems are the toughest
atleast as difficult to solve as any other NP-problem problems that are in NP.
Example: Vertex cover problem,Halting problem. Example: Determine whether a Boolean
formula is satisfiable or not, Circuit-
satisfiability problem
48
IV AIML AIPC701- Theory of Computation
NP HARD is not a decision problem.
NP COMPLETE is exclusively a decision
problem.
49
IV AIML AIPC701- Theory of Computation
84. What is meant by Reduction.
A reduction is a way of converting one problem into another problem such that a solution to the second
problem can be used to solve the first problem. We say the first problem reduces to the second problem.
85. What is primitive recursive function? [May-June 2017] (or) Define the primitive recursion
operation. [Nov-Dec 2018]
Function is considered primitive recursive if it can be obtained from initial functions and through finite
number of composition and recursion steps.
86. Identify whether 'Tower of Hanoi' problem is tractable or intractable. Justify your answer.
[May-June 2016]
'Tower of Hanoi' problem is intractable.
Intractable Problem: a problem that cannot be solved by a polynomial-time algorithm. The lower bound is
exponential.
Towers of Hanoi: we can prove that any algorithm that solves this problem must have a worst-case running time
that is at least 2n_J,
87. Show that AMBIGUITY problem is undecidable.
Consider the ambiguity problem for CFGs. Use the “yes -no” version of AMBIGUITY. An algorithm for
FIND is used to solve AMBIGUITY. FIND requires producing a word with two or more parses if one exists
and answers “no” otherwise. By the reduction of AMBIGUITY to FIND we conclude there is no algorithm for
FIND and Hence no algorithm for AMBIGUITY.
88. Define problem solvable in polynomial Time.
A Turing Machine M is said to be of time complexity T(n) if whenever m given an input w of length n, m
halts after making atmost T(n) moves, regardless of whether or not m accepts.
89. What are the major problems in Computational Complexity?
There are several major problems in computational complexity theory that remain open and actively
researched. Here are a few examples:
• P versus NP problem
• Complexity of specific problems
• Circuit lower bounds
• De-randomization
• Quantum complexity theory
90. Define trivial property.
A property is trivial if it is either empty of is all RE languages.
91. Define Rice Theorem.
Rice's Theorem: Any non trivial property of the languages accepted by Turing machines is undecidable. Fc
instance, the net of codes for Turing machines whose language is empty is undecidable by Rice's theorem. I fact,
this language is not RE, although its complement — the set of codes for TM's that accepts at least on string —
is RE but not recursive
50
IV AIML AIPC701- Theory of Computation
92. What do you mean SAT problem?
• SAT(Boolean Satisfiability Problem) is the problem of determining if there exists an interpretation that
satisfies a given Boolean formula.
• It asks whether the variables of a given Boolean formula can be consistently replaced by the values
TRUE or FALSE in such a way that the formula evaluates to TRUE.
• If this is the case, the formula is called satisfiable.
• On the other hand, if no such assignment exists, the function expressed by the formula is FALSE for all
possible variable assignments and the formula is unsatisfiable.
93. What is meant by CNF - SAT Problem?
• This problem is based on Boolean formula. The Boolean formula has various Boolean operations such as
OR (+), AND (.) and NOT. There are some notations such as (means implies) and (means if and
only if).
• A Boolean formula is in Conjunctive Normal Form (CNF) if it formed as collection of subexpressions.
These subexpressions are called clauses.
• For example
51