Está en la página 1de 7

Charotor Institute of Technology-Changa

Prepared by Trupti M. Kodinariya

P Problem
In computational complexity theory, P is the complexity class containing decision
problems which can be solved by a deterministic Turing machine using a polynomial
amount of computation time, or polynomial time.
P is known to contain many natural problems, including linear programming, calculating
the greatest common divisor, and finding a maximum matching.
P is often taken to be the class of computational problems which are "efficiently
solvable" or "tractable", although there are potentially larger classes that are also
considered tractable such as RP and BPP. Also, there exist problems in P which are
intractable in practical terms; for example, some require at least n1000000 operations.
Relationships to other classes
A generalization of P is NP, which is the class of languages decidable in polynomial time
on a non-deterministic Turing machine. We then trivially have P is a subset of NP. One
of the largest open problems currently in theoretical computer science is whether P = NP/
P is also known to be at least as large as L, the class of problems decidable in a
logarithmic amount of memory space. A decider using O(log n) space cannot use more
than 2O(log n)=nO(1) time, because this is the total number of possible configurations; thus, L
is a subset of P. Another important problem is whether L = P. We do know that P =
ALOGSPACE, the set of problems solvable in logarithmic memory by alternating Turing
machines. P is also known to be no larger than PSPACE, the class of problems decidable
in polynomial space. Again, whether P = PSPACE is an open problem. To summarize:

Here, EXPTIME is the class of problems solvable in exponential time. Of all the classes
shown above, only two strict containments are known:

P is strictly contained in EXPTIME. Consequently, all EXPTIME-hard


problems lie outside P, and at least one of the containments to the right of P
above is strict (in fact, it is widely believed that all three are strict).
L is strictly contained in PSPACE.

NP Problem
In computational complexity theory, NP ("Non-deterministic Polynomial time") is the set
of decision problems solvable in polynomial time on a non-deterministic Turing machine.
Equivalently, it is the set of problems that can be "verified" by a deterministic Turing
machine in polynomial time; more detail below.

Charotor Institute of Technology-Changa

Prepared by Trupti M. Kodinariya

Introduction and applications


The importance of this class of decision problems is that it contains many interesting
searching and optimization problems where we want to know if there exists a certain
solution for a certain problem.
As a simple example, consider the problem of determining whether a number n is a
composite number. For large numbers, this seems like a very difficult problem to solve
efficiently; the simplest approaches require time which is exponential in log n, the
number of input bits. On the other hand, once we've found a candidate factor of n, the
following function can quickly tell us whether it really is a factor:
boolean isNontrivialFactor(n, d)
if n is divisible by d and
d 1 and d n
return true
else
return false

If n is composite, then this function will return true for some input d. If n is prime,
however, this function will always return false, regardless of d. All problems in NP have
a deterministic function just like this, which accepts only when given both an input and
proof that the input is in the language. We must be able to check if the proof is correct in
polynomial time. We call such a machine a verifier for the problem.
If we have a nondeterministic machine, testing a number for compositeness is easy. It can
branch into n different paths in just O(log n) steps; then, each of these can call
isNontrivialFactor(n, d) for one d. If any succeed, the number is composite;
otherwise, it is prime.
Thus, the challenge of NP problems is to efficiently find the answer, given an efficient
(polynomial-time) way of verifying it once it is found. This challenge was solved (see
AKS Primality Test) for compositeness testing only in 2002; there is still no known
polynomial-time way to solve the more general factoring problem of determining
whether a number between 1 and m divides n.
Additional examples include:
The graph isomorphism problem of determining whether two graphs can be
drawn identically
The traveling salesman problem, where we want to know if there is a route of
some length that goes through all the nodes in a certain network
The boolean satisfiability problem, where we want to know if a certain formula in
propositional logic with boolean variables is satisfiable or not

Charotor Institute of Technology-Changa

Prepared by Trupti M. Kodinariya

Why some NP problems are hard to solve


Because of the many important problems in this class, there have been extensive efforts
to find algorithms that decide the problems in NP in time which is polynomial in
the input size, which is generally considered efficient. However, there are a large
number of problems in NP that defy such attempts, seeming to require
superpolynomial time. Whether these problems really aren't solvable in polynomial
time is one of the greatest open questions in computer science.
An important notion in this context is the set of NP-Complete decision problems, which
is a subset of NP and might be informally described as the "hardest" problems in NP. If
there is a polynomial-time algorithm for even one of them, then there is a polynomialtime algorithm for all the problems in NP. Because of this, and because dedicated
research has failed to find a polynomial algorithm for any NP-complete problem, once a
problem has been proven to be NP-complete this is widely regarded as a sign that a
polynomial algorithm for this problem is unlikely to exist.
Example
The decision version of the traveling salesperson problem is in NP. Given an input matrix
of distances between N cities, the problem is to determine if there is a route visiting all
cities with total distance less than k. A nondeterministic Turing machine can find such a
route as follows:

At each city it visits it "guesses" the next city to visit, until it has visited every
vertex. If it gets stuck, it stops immediately.
At the end it verifies that the route it has taken has cost less than k in O(n) time.

One can think of each guess as "forking" a new copy of the Turing machine to follow
each of the possible paths forward, and if at least one machine finds a route of distance
less than k, that machine accepts the input.
What makes this a natural decision version of the problem is that, if we could solve this
problem quickly, we could use binary search to solve the original computation problem
(finding the route and its exact length) quickly as well.

NP-hard Problem
In computational complexity theory, NP-hard (Non-deterministic Polynomial-time hard)
refers to the class of decision problems that contains all problems H, such that for every
decision problem L in NP there exists a polynomial-time many-one reduction to H,
written
. Informally, this class can be described as containing the decision
problems that are at least as hard as any problem in NP. This intuition is supported by the
fact that if we can find an algorithm A that solves one of these problems H in polynomial

Charotor Institute of Technology-Changa

Prepared by Trupti M. Kodinariya

time, we can construct a polynomial time algorithm for any problem L in NP by first
performing the reduction from L to H and then running the algorithm A.
So, formally, a language L is NP-hard if L' in NP,
L is in NP, then L is called NP-complete.

. If it is also the case that

The notion of NP-hardness plays an important role in the discussion about the
relationship between the complexity classes P and NP. The class NP-hard can be
understood as the class of problems that are NP-complete or harder.
A common mistake is to think that the "NP" in "NP-hard" stands for "non-polynomial".
Although it is widely suspected that there are no polynomial-time algorithms for these
problems, this has never been proved. Furthermore, it must also be taken into
consideration, that polynomial complexity problems are a subset of NP complexity
problems and therefore contained in the NP-hard complexity class.
Examples
An example of an NP-hard problem is the decision problem SUBSET-SUM which is this:
given a set of integers, does any non empty subset of them add up to zero? That is a
yes/no question, and happens to be NP-complete.
There are also decision problems that are NP-hard but not NP-complete, for example the
halting problem. This is the problem "given a program and its input, will it run forever?"
That's a yes/no question, so this is a decision problem. It is easy to prove that the halting
problem is NP-hard but not NP-complete. For example the Boolean satisfiability problem
can be reduced to the halting problem by transforming it to the description of a Turing
machine that tries all truth value assignments and when it finds one that satisfies the
formula it halts and otherwise it goes into an infinite loop. It is also easy to see that the
halting problem is not in NP since all problems in NP are decidable and the halting
problem is not.
Alternative definitions
An alternative definition of NP-hard that is often used replaces polynomial-time manyone reductions with polynomial-time Turing reductions. This notion of NP-hardness can
be formulated for function problems and not just decision problems.
In this sense, the problem H is NP-hard if and only if every decision problem L in NP can
be solved in polynomial time by an oracle machine with an oracle for H. (Informally we
can think of such a machine as an algorithm that can call a subroutine for solving H and
solves L in polynomial time if the subroutine call takes only one step to compute.) If we
find a polynomial-time algorithm for an NP-hard problem then we have a polynomialtime algorithm for all problems in NP-easy and indeed for all problems in NP.

Charotor Institute of Technology-Changa

Prepared by Trupti M. Kodinariya

Whether this definition of NP-hardness is equivalent to the one at the beginning of this
article (for the case of decision problems) is still an open problem and is discussed in
more detail in the article on NP-completeness.

NP-Complete Problem
In complexity theory, the NP-complete problems are the most difficult problems in NP
("non-deterministic polynomial time") in the sense that they are the ones most likely not
to be in P. The reason is that if you could find a way to solve any NP-complete problem
quickly (in polynomial time), then you could use that algorithm to solve all NP problems
quickly. The complexity class consisting of all NP-complete problems is sometimes
referred to as NP-C. A more formal definition is given below.
One example of an NP-complete problem is the subset sum problem which is: given a
finite set of integers, determine whether any non-empty subset of them sums to zero. A
supposed answer is very easy to verify for correctness, but no one knows a significantly
faster way to solve the problem than to try every single possible subset, which is very
slow.
Formal definition of NP-completeness
A decision problem C is NP-complete if it is complete for NP, meaning that:
1. it is in NP and
2. it is NP-hard, i.e. every other problem in NP is reducible to it.
"Reducible" here means that for every problem L, there is a polynomial-time many-one
reduction, a deterministic algorithm which transforms instances l L into instances c
C, such that the answer to c is YES if and only if the answer to l is YES. To prove that a
NP problem A is in fact a NP-complete problem it is sufficient to show that an already
known NP-complete problem reduces to A.
A consequence of this definition is that if we had a polynomial time algorithm for C, we
could solve all problems in NP in polynomial time.
Nobody has yet been able to prove whether NP-complete problems are in fact solvable in
polynomial time, making this one of the great unsolved problems of mathematics.
A problem satisfying condition 2 but not necessarily condition 1 is said to be NP-hard.
Informally, an NP-hard problem is "at least as hard as" any NP-complete problem, and
perhaps harder. For example, choosing the perfect move in certain board games on an
arbitrarily large board is NP-hard or even strictly harder than the NP-complete
problems.

Charotor Institute of Technology-Changa

Prepared by Trupti M. Kodinariya

Example problems
An interesting example is the graph isomorphism problem, the graph theory problem of
determining whether a graph isomorphism exists between two graphs. Two graphs are
isomorphic if one can be transformed into the other simply by renaming vertices.
Consider these two problems:

Graph Isomorphism: Is graph G1 isomorphic to graph G2?


Subgraph Isomorphism: Is graph G1 isomorphic to a subgraph of graph G2?

The Subgraph Isomorphism problem is NP-complete. The Graph Isomorphism problem


is suspected to be neither in P nor NP-complete, though it is obviously in NP. This is an
example of a problem that is thought to be hard, but isn't thought to be NP-complete.
The easiest way to prove that some new problem is NP-complete is first to prove that it
is in NP, and then to reduce some known NP-complete problem to it. Therefore, it is
useful to know a variety of NP-complete problems. The list below contains some wellknown problems that are NP-complete when expressed as decision problems.

Boolean satisfiability problem (SAT)


Fifteen puzzle
Knapsack problem
Hamiltonian cycle problem
Traveling salesman problem
Subgraph isomorphism problem
Subset sum problem
Clique problem
Vertex cover problem
Independent set problem
Graph coloring problem

Imperfect solutions
At present, all known algorithms for NP-complete problems require time that is
superpolynomial in the input size. It is unknown whether there are any faster algorithms.
Therefore, to solve an NP-complete problem for any nontrivial problem size, generally
one of the following approaches is used:

Approximation: An algorithm that quickly finds a suboptimal solution that is


within a certain (known) range of the optimal one.
Probabilistic: An algorithm that can be proven to yield good average runtime
behavior for a given distribution of the problem instancesideally, one that
assigns low probability to "hard" inputs.
Special cases: An algorithm that is provably fast if the problem instances belong
to a certain special case. Fixed-parameter algorithms can be seen as a
generalization of this approach.
6

Charotor Institute of Technology-Changa

Prepared by Trupti M. Kodinariya

Heuristic: An algorithm that works "reasonably well" on many cases, but for
which there is no proof that it is both always fast and always produces a good
result.

With respect to other reductions


In the definition of NP-complete given above, the term "reduction" was used in the
technical meaning of a polynomial-time many-one reduction.
Another type of reduction is polynomial-time Turing reduction. A problem X is
polynomial-time Turing-reducible to a problem Y if, given a subroutine that solves Y in
polynomial time, you could write a program that calls this subroutine and solves X in
polynomial time. This contrasts with many-one reducibility, which has the restriction that
the program can only call the subroutine once, and the return value of the subroutine must
be the return value of the program.
Another type of reduction that is also often used to define NP-completeness is the
logarithmic-space many-one reduction which is a many-one reduction that can be
computed with only a logarithmic amount of space. Since every computation that can be
done in logarithmic space can also be done in polynomial time it follows that if there is a
logarithmic-space many-one reduction then there is also a polynomial-time many-one
reduction. This type of reduction is more refined than the more usual polynomial-time
many-one reductions and it allows us to distinguish more classes such as P-complete.
Whether under these types of reductions the definition of NP-complete changes is still an
open problem.

También podría gustarte