NP Problem
NP Problem
Introduction
• In Computer Science, many problems are solved where the objective is to
maximize or minimize some values, whereas in other problems we try to find
whether there is a solution or not. Hence, the problems can be categorized
as follows −
• Optimization Problem
– Optimization problems are those for which the objective is to maximize or
minimize some values. For example,
– Finding the minimum number of colors needed to color a given graph.
– Finding the shortest path between two vertices in a graph.
• Decision Problem
– There are many problems for which the answer is a Yes or a No. These types of
problems are known as decision problems. For example,
– Whether a given graph can be colored by only 4-colors.
– Finding Hamiltonian cycle in a graph is not a decision problem, whereas checking
a graph is Hamiltonian or not is a decision problem.
What Is NP Problem?
• These are the decision problems which can be verified in
polynomial time. That means, if I claim that there is a
polynomial time solution for a particular problem, you ask me
to prove it. Then, I will give you a proof which you can easily
verify in polynomial time. These kind of problems are called
NP problems.
• Note that, here we are not talking about whether there is a
polynomial time solution for this problem or not. But we are
talking about verifying the solution to a given problem in
polynomial time.
What Is N and NP Class Problem?
• P-Class
– The class P consists of those problems that are solvable in polynomial
time, i.e. these problems can be solved in time O(nk) in worst-case,
where k is constant.
– These problems are called tractable, while others are called intractable
or superpolynomial.
• NP-Class
– The class NP consists of those problems that are verifiable in polynomial
time. NP is the class of decision problems for which it is easy to check
the correctness of a claimed answer, with the aid of a little extra
information. Hence, we aren’t asking for a way to find a solution, but
only to verify that an alleged solution really is correct.
– Every problem in this class can be solved in exponential time using
exhaustive search.
What Is NP Complete Problem?
• These are the problems which are both NP and NP-Hard. That
means, if we can solve these problems, we can solve any other
NP problem and the solutions to these problems can be verified
in polynomial time.
• In other words, NP-Complete is a complexity class which
represents the set of all problems X in NP for which it is possible
to reduce any other NP problem Y to X in polynomial time.
• Intuitively this means that we can solve Y quickly if we know
how to solve X quickly. Precisely, Y is reducible to X, if there is
a polynomial time algorithm f to transform instances y of Y to
instances x = f(y) of X in polynomial time, with the property that
the answer to y is yes, if and only if the answer to f(y) is yes.
Example NP Complete Problem?
What Is NP Hard Problem?
• These are at least as hard as the hardest problems in NP. If we can solve these
problems in polynomial time, we can solve any NP problem that can possibly
exist. Note that these problems are not necessarily NP problems. That means,
we may/may-not verify the solution to these problems in polynomial time.
• Intuitively, these are the problems that are at least as hard as the NP-
complete problems. Note that NP-hard problems do not have to be in NP,
and they do not have to be decision problems.
• The precise definition here is that a problem X is NP-hard, if there is an NP-
complete problem Y, such that Y is reducible to X in polynomial time.
• But since any NP-complete problem can be reduced to any other NP-
complete problem in polynomial time, all NP-complete problems can be
reduced to any NP-hard problem in polynomial time. Then, if there is a
solution to one NP-hard problem in polynomial time, there is a solution to all
NP problems in polynomial time.
Example NP Hard
What Is NP Hard Problem?