Nepedia
Back to Discover
Advanced Reader
🔢

NP (complexity)

math Maturity 11-13 Next article →

In computational complexity theory, NP is a fundamental class used to classify decision problems. NP stands for nondeterministic polynomial time. A decision problem is a question that results in a simple "yes" or "no" answer. The class NP contains problems where a "yes" answer can be verified very efficiently. Efficiency is measured by polynomial time. This means the number of operations needed to check an answer grows at a manageable rate relative to the size of the problem.

P np np-complete np-hard
P np np-complete np-hard

There are two primary ways to define the mechanism of NP. The first is the verifier-based definition. In this view, a problem is in NP if a deterministic Turing machine can act as a verifier. This machine takes a problem instance and a piece of evidence, often called a witness or a certificate. If the witness proves the answer is "yes," the verifier confirms it in polynomial time. The second definition uses a nondeterministic Turing machine. This type of machine can make many guesses at once. It can solve an NP problem by nondeterministically selecting a certificate and then running a deterministic verifier on it. These two definitions are mathematically equivalent.

Complexity-classes-polynomial
Complexity-classes-polynomial

To see this mechanism in action, consider the subset sum problem. Imagine you are given a set of integers, such as {-7, -3, -2, 5, 8}. You must decide if any subset of these numbers sums exactly to zero. Finding such a subset might require checking every possible combination. As the set grows, the number of combinations increases exponentially, making it very difficult for a standard computer. However, if someone provides the subset {-3, -2, 5}, the verification is simple. You just add the numbers together to see if they equal zero. Because this addition happens in polynomial time, the subset sum problem is in NP.

Complexity theory organizes problems into several distinct stages and classes. The class P consists of all decision problems that can be solved deterministically in polynomial time. Because any problem that can be solved quickly can also be verified quickly, P is a subset of NP. A major unsolved question is whether P equals NP. Most scientists believe that P is smaller than NP, meaning some problems are easy to check but hard to solve. Another class is co-NP. This class contains problems where a "no" answer can be verified in polynomial time. For example, proving a number is not prime is in co-NP because you can simply provide a factor as a witness.

Complexity subsets pspace
Complexity subsets pspace

Within the NP class, there is a special group of the most difficult problems. These are called NP-complete problems. They represent the hardest challenges within NP. They possess a unique property: if a polynomial-time algorithm is found for even one NP-complete problem, then every problem in NP can be solved in polynomial time. This would prove that P = NP. Because researchers have failed to find such algorithms for decades, many experts assume that NP-complete problems truly require more than polynomial time to solve.

P np np-complete np-hard
P np np-complete np-hard

NP is also related to much larger complexity classes. It is known that NP is contained within PSPACE, which is the class of problems solvable using a polynomial amount of memory. NP is also a subset of EXPTIME, which includes problems solvable in exponential time. Some researchers also study the relationship between NP and BPP, a class involving probabilistic algorithms. However, it is not currently known if BPP is a subset of NP or vice versa. The study of these boundaries helps scientists understand the fundamental limits of computation.

Complexity subsets pspace
Complexity subsets pspace

Understanding NP helps computer scientists approach real-world problems effectively. When a problem is proven to be NP-complete, researchers stop searching for perfect, fast solutions. Instead, they focus on finding "good enough" solutions that work in polynomial time. While these solutions might not be optimal, they are practical for everyday use. This distinction between theoretical hardness and practical application is a vital part of modern computing and algorithm design.

657 words

Where will your curiosity go next?

Keep exploring at your chosen reading level.

🖼️ Images & Media (3)
File:P np np-complete np-hard.svg
P np np-complete np-hard.svg
File:Complexity subsets pspace.svg
Complexity subsets pspace.svg
File:Complexity-classes-polynomial.svg
Complexity-classes-polynomial.svg
More to explore

What is Nepedia?

A free, ad-free encyclopedia for children. Every article is written at five reading levels, so the same page works for a five-year-old and a fifteen-year-old — use the level switcher above to see this one change. No account needed to read.