Computational complexity theory is part of the theory of computation dealing with the resources required during computation to solve a given problem. The most common resources are time (how many steps does it take to solve a problem) and space (how much memory does it take to solve a problem).
In this theory, the class P consists of all those decision problems that can be solved on a deterministic sequential machine in an amount of time that is polynomial in the size of the input; the class NP consists of all those decision problems whose positive solutions can be verified in polynomial time given the right information, or equivalently, whose solution can be found in polynomial time on a nondeterministic machine. Arguably, the biggest open question in theoretical computer science concerns the relationship between those two classes:
 Is P equal to NP?
Most people think that the answer is probably "no"; some people believe the question may be undecidable from the currently accepted axioms. A $1,000,000 USD prize has been offered for a correct solution.
If P = NP, P would encompass the NP and NPComplete areas.
An important role in this discussion is played by the set of NPcomplete problems (or NPC) which can be loosely described as those problems in NP that are the least likely to be in P. (See NPcomplete for the exact definition.) Theoretical computer scientists currently believe that the relationship among the classes P, NP, and NPC is as shown in the picture, with the P and NPC classes disjoint.
In essence, the P = NP question asks: if positive solutions to a YES/NO problem can be verified quickly, can the answers also be computed quickly? Here is an example to get a feeling for the question. Given two large numbers X and Y, we might ask whether Y is a multiple of any integers between 1 and X, exclusive. For example, we might ask whether 69799 is a multiple of any integers between 1 and 250. The answer is YES, though it would take a fair amount of work to find it manually. On the other hand, if someone claims that the answer is YES because 223 is a divisor of 69799, then we can quickly check that with a single division. Verifying that a number is a divisor is much easier than finding the divisor in the first place. The information needed to verify a positive answer is also called a certificate. So we conclude that given the right certificates, positive answers to our problem can be verified quickly (i.e. in polynomial time) and that's why this problem is in NP. It is not known whether the problem is in P. The special case where X=Y was first shown to be in P in 2002 (see references for "PRIMES in P" below).
Decision problems
More formally, a decision problem is a problem that takes as input some string and requires as output either YES or NO. If there is an algorithm (say a Turing machine, or a LISP or Pascal program with unbounded memory) which is able to produce the correct answer for any input string of length n in at most n^{k} steps, where k is some constant independent of the input string, then we say that the problem can be solved in polynomial time and we place it in the class P. Intuitively, we think of the problems in P as those that can be solved reasonably fast.
Now suppose there is an algorithm A(w,C) which takes two arguments, a string w which is an input string to our decision problem, and a string C which is a "proposed certificate", and such that A produces a YES/NO answer in at most n^{k} steps (where n is the length of w and k doesn't depend on w). Suppose furthermore that
 w is a YES instance of the decision problem if and only if there exists C such that A(w,C) returns YES.
Then we say that the problem can be solved in nondeterministic polynomial time and we place it in the class NP. We think of the algorithm A as a verifier of proposed certificates which runs reasonably fast. (Note that the abbreviation NP stands for "Nondeterministic Polynomial" and not for "NonPolynomial".)
NPcomplete
To attack the P = NP question, the concept of NPcompleteness is very useful. Informally, the NPcomplete problems are the "toughest" problems in NP in the sense that they are the ones most likely not to be in P. This is because any problem in NP can be transformed, in polynomial time, into an instance of any specific NPcomplete problem. For instance, the decision problem version of the travelling salesman problem is NPcomplete. So any instance of any problem in NP can be transformed mechanically into an instance of the travelling salesman problem, in polynomial time. So, if the travelling salesman problem turned out to be in P, P=NP! The travelling salesman problem is one of many such NPcomplete problems. If any NPcomplete problem is in P, then it would follow that P = NP. Unfortunately, many important problems have been shown to be NPcomplete and not a single fast algorithm for any of them is known.
The P = NP question has also been addressed using oracles.
Still harder problems
Although it is unknown whether P=NP, problems outside of P are known. The problem of finding the best move in Chess or Go (on an n by n board) is EXPTIMEcomplete. This means it requires exponential time, and so is outside P. The problem of deciding the truth of a statement in Presburger arithmetic is even harder. Fischer and Rabin proved in 1974 that every algorithm which decides the truth of Presburger statements has a runtime of at least 2^(2^(cn)) for some constant c. Here, n is the length of the Presburger statement. Hence, the problem is known to need more than exponential run time. Even more difficult are the undecidable problems, such as the halting problem. They cannot be solved in general given any amount of time.
All of the above discussion has assumed that P means "easy" and "not in P" means "hard". While this is a common and reasonably accurate assumption in complexity theory, it is not always true in practice, for several reasons:
 It ignores constant factors. A problem that takes time 10^{1000}n is P (it's linear time), but is completely intractable in practice. A problem that takes time 10^{10000}2^{n} is not P (it's exponential time), but is very tractable for values of n up into the thousands.
 It ignores the size of the exponents. A problem with time n^{1000} is P, yet intractable. A problem with time 2^{n/1000} is not P, yet is tractable for n up into the thousands.
 It only considers worstcase times. There might be a problem that arises in the real world such that most of the time, it can be solved in time n, but on very rare occasions you'll see an instance of the problem that takes time 2^{n}. This problem might have an average time that is polynomial, but the worst case is exponential, so the problem wouldn't be in P.
 It only considers deterministic solutions. There might be a problem that you can solve quickly if you accept a tiny error probability, but a guaranteed correct answer is much harder to get. The problem would not belong to P even though in practice it can be solved fast. This is in fact a common approach to attack NPcomplete problems.
 New computing models such as quantum computers, which also work probabilistically, may be able to quickly solve some problems not known to be in P; however, none of the problems they are known to be able to solve are NPcomplete.
Why do computer scientists think P ≠ NP?
Most computer scientists believe that P≠NP. A key reason for this belief is that after decades of studying these problems, nobody has been able to find a polynomialtime algorithm for an NPhard problem. However, as we'll explain in the next section, we do have polynomialtime algorithms to solve NPcomplete problems, under the assumption that P=NP.
Furthermore, it is often argued that the idea of problems that are hard to solve, but easy to verify the solutions for, matches our own realworld experience.
Polynomialtime algorithms
No one knows whether polynomialtime algorithms exist for NPcomplete languages. But if such algorithms do exist, we already know some of them! For example, the following algorithm correctly accepts an NPcomplete language, but no one knows how long it takes in general. This is a polynomialtime algorithm if and only if P = NP.
// Algorithm that accepts the NPcomplete language SUBSETSUM.
//
// This is a polynomialtime algorithm if and only if P=NP.
//
// "Polynomialtime" means it returns "YES" in polynomial time when
// the answer should be "YES", and runs forever when it's "NO".
//
// Input: S = a finite set of integers
// Output: "YES" if any subset of S adds up to 0.
// Otherwise, it runs forever with no output.
// Note: "Program number P" is the program you get by
// writing the integer P in binary, then
// considering that string of bits to be a
// program. Every possible program can be
// generated this way, though most do nothing
// because of syntax errors.
FOR N = 1...infinity
FOR P = 1...N
Run program number P for N steps with input S
IF the program outputs a list of distinct integers
AND the integers are all in S
AND the integers sum to 0
THEN
OUTPUT "YES" and HALT
If P = NP, then this is a polynomialtime algorithm accepting an NPComplete language. "Accepting" means it gives "YES" answers in polynomial time, but is allowed to run forever when the answer is "NO".
Perhaps we want to "solve" the SUBSETSUM problem, rather than just "accept" the SUBSETSUM language. That means we want it to always halt and return a "YES" or "NO" answer. Does any algorithm exist that can provably do this in polynomial time? No one knows. But if such algorithms do exist, then we already know some of them! Just replace the IF statement in the above algorithm with this:
IF the program outputs a complete math proof
AND each step of the proof is legal
AND the conclusion is that S does (or does not) have a subset summing to 0
THEN
OUTPUT "YES" (or "NO" if that was proved) and HALT
Logical characterizations
The P=NP problem can be restated in terms of the expressibility of certain classes of logical statements. All languages in P can be expressed in first order logic with the addition of a least fixed point operator (effectively, this allows the definition of recursive functions). Similarly, NP is the set of languages expressible in existential second order logic — that is, second order logic restricted to exclude universal quantification over relations, functions, and subsets. The languages in the polynomial hierarchy, PH, correspond to all of second order logic. Thus, the question "is P a proper subset of NP" can be reformulated as "is existential secondorder logic able to describe languages that firstorder logic with least fixed point cannot?"
P and NP trivia
The Princeton University computer science building has the question "P=NP?" encoded in binary in its brickwork on the top floor of the west side. If it is proven that P=NP, the bricks can easily be changed to encode "P=NP!". [1]
See also
External links and references

The Clay Math Institute Millennium Prize Problems
 A. S. Fraenkel and D. Lichtenstein, Computing a perfect strategy for n*n chess requires time exponential in n, Proc. 8th Int. Coll. Automata, Languages, and Programming, Springer LNCS 115 (1981) 278293 and J. Comb. Th. A 31 (1981) 199214.
 E. Berlekamp and D. Wolfe, Mathematical Go: Chilling Gets the Last Point, A. K. Peters, 1994. D. Wolfe, Go endgames are hard, MSRI Combinatorial Game Theory Research Worksh., 2000.

Neil Immerman. Languages Which Capture Complexity Classes. 15th ACM STOC Symposium, pp.347354. 1983.

Computational Complexity of Games and Puzzles

Manindra Agarwal, Nitin Saxena, Neeraj Kayal, "PRIMES is in P", Preprint, August 6, 2002

The "PRIMES is in P" FAQ

Scott Aaronson's Complexity Zoo
Last updated: 05132005 07:56:04