5 Unit Theory
5 Unit Theory
L2= {d e f |m>=0}
m m m
L3= L1.L2
= {a b c d e f |m>=0 and n>=0} is also recursive.
n n n m m m
L1 says n no. of a’s followed by n no. of b’s followed by n no. of c’s. L2 says m no. of d’s followed
by m no. of e’s followed by m no. of f’s. Their concatenation first matches no. of a’s, b’s and c’s
and then matches no. of d’s, e’s and f’s. So it can be decided by TM.
Kleene Closure: If L1is recursive, its kleene closure L1* will also be recursive. For Example:
L1= {a b c |n>=0} n n n
Intersection and complement: If L1 and If L2 are two recursive languages, their intersection L1 ?
L2 will also be recursive. For Example:
L1= {a b c dm|n>=0 and m>=0}
n n n
L3=L1 ? L2
= { a b c d |n>=0} will be recursive.
n n n n
L1 says n no. of a’s followed by n no. of b’s followed by n no. of c’s and then any no. of d’s. L2 says
any no. of a’s followed by n no. of b’s followed by n no. of c’s followed by n no. of d’s. Their
intersection says n no. of a’s followed by n no. of b’s followed by n no. of c’s followed by n no. of d’s.
So it can be decided by turing machine, hence recursive.
Similarly, complement of recursive language L1 which is ?*-L1, will also be recursive.
Note: As opposed to REC languages, RE languages are not closed under complementation which
means complement of RE language need not be RE.
The below diagram shows the Turing machine for the language strings containing palindromes.
Example: Take the input string 1001.
given below is the instantaneous description for the input string 1001.
q0 1001
We start from state q0. We take the input string in our instantaneous description.
We convert the first one to ‘y’, and the state is mentioned after ‘y’.
Y00q4 1
Y001 q4
Y00q5 1
Y0q3 0Y
Yq3 00Y
q3 Y00Y
Yq0 00Y
YXq1 0Y
We accept the input if the instantaneous description finally had a q10 state. Otherwise, We reject the string.
It is a mathematical model of
Universal Turing Machine is like a single
computation it manipulates symbols
1. Turing Machine that has a solution to all
on the tape according to the rules
problem that is computable
defined
6) Halting Problem
Introduction
Halting means that the system will either accept or halt(reject) a certain input to avoid entering an infinite loop.
The decision of whether or not a specific Turning machine should halt is known as the Halting Problem of
Turning Machines.
The halting problem is one of the most well-known problems proven to be undecidable. In this article, we will
learn about the Halting Problem in the Theory of Computation.
Proof by Contradiction
Step 1: Assume we can create a machine called HM(P, I), where HM is the Halting machine, P is the program,
and I is the input. After receiving both inputs, the machine HM will output whether or not the program P
terminates.
Step 2: Now, create an inverted halting machine IM that takes a program P as input and,
Loops forever If HM returns YES.
Halts if HM returns NO.
Step 3:Now, take a situation where the program IM is passed to the IM function as an input. Here, we got a
contradiction. Let's understand how.
It is impossible for the outer function to halt if its inner function is in a loop(RHS), and it is likewise
impossible for the outer function to halt even if its inner function is halting(LHS). So both conditions are non-
halting for the IM machine, despite our above assumptions.
Hence, the halting problem is undecidable.
P Class
The P in the P class stands for Polynomial Time. It is the collection of decision problems(problems
with a “yes” or “no” answer) that can be solved by a deterministic machine in polynomial time.
Features:
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.
This class contains many problems:
1. Calculating the greatest common divisor.
2. Finding a maximum matching.
3. Merge Sort
NP Class
The NP in NP class stands for Non-deterministic Polynomial Time. It is the collection of decision
problems that can be solved by a non-deterministic machine in polynomial time.
Features:
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.
Example:
Let us consider an example to better understand the NP class. Suppose there is a company having a
total of 1000 employees having unique employee IDs. Assume that there are 200 rooms available for
them. A selection of 200 employees must be paired together, but the CEO of the company has the data
of some employees who can’t work in the same room due to personal reasons.
This is an example of an NP problem. Since it is easy to check if the given choice of 200 employees
proposed by a coworker is satisfactory or not i.e. no pair taken from the coworker list appears on the
list given by the CEO. But generating such a list from scratch seems to be so hard as to be completely
impractical.
It indicates that if someone can provide us with the solution to the problem, we can find the correct and
incorrect pair in polynomial time. Thus for the NP class problem, the answer is possible, which can be
calculated in polynomial time.
This class contains many problems that one would like to be able to solve effectively:
1. Boolean Satisfiability Problem (SAT).
2. Hamiltonian Path Problem.
3. Graph coloring.
Co-NP Class
Co-NP stands for the complement of NP Class. It means if the answer to a problem in Co-NP is No,
then there is proof that can be checked in polynomial time.
Features:
If a problem X is in NP, then its complement X’ is also in CoNP.
For an NP and CoNP problem, there is no need to verify all the answers at once in polynomial time,
there is a need to verify only one particular answer “yes” or “no” in polynomial time for a problem
to be in NP or CoNP.
Some example problems for CoNP are:
1. To check prime number.
2. Integer Factorization.
NP-hard class
An NP-hard problem is at least as hard as the hardest problem in NP and it is a class of problems such
that every problem in NP reduces to NP-hard.
Features:
All NP-hard problems are not in NP.
It takes a long time to check them. This means if a solution for an NP-hard problem is given then it
takes a long time to check whether it is right or not.
A problem A is in NP-hard if, for every problem L in NP, there exists a polynomial-time reduction
from L to A.
Some of the examples of problems in Np-hard are:
1. Halting problem.
2. Qualified Boolean formulas.
3. No Hamiltonian cycle.
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.
Features:
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.
All NP-hard problems are not in NP and it takes a long time to check
NP-hard
them.
NP Problem:
The NP problems set of problems whose solutions are hard to find but easy to verify and are solved
by Non-Deterministic Machine in polynomial time.
NP-Hard Problem:
A Problem X is NP-Hard if there is an NP-Complete problem Y, such that Y is reducible to X in
polynomial time. NP-Hard problems are as hard as NP-Complete problems. NP-Hard Problem need not
be in NP class.
If every problem of NP can be polynomial time reduced to it called as NP Hard.
A lot of times takes the particular problem solve and reducing different problems.
example :
1. Hamiltonian cycle .
2. optimization problem .
3. Shortest path
NP-Complete Problem:
A problem X is NP-Complete if there is an NP problem Y, such that Y is reducible to X in polynomial
time. NP-Complete problems are as hard as NP problems. A problem is NP-Complete if it is a part of
both NP and NP-Hard Problem. A non-deterministic Turing machine can solve NP-Complete problem
in polynomial time.
Example:
1. Decision problems.
2. Regular graphs.
To solve this problem, it do not have to be To solve this problem, it must be both NP and NP-
in NP . hard problems.
Not all NP-hard problems are NP-complete. All NP-complete problems are NP-hard