This is a pretty good summary of the classes of algorithms and an open problem related to them:
Alt: diagrams showing from P to NP-Hard under p=np and p!=np models, with a brief description of each and an example of each.
Great summary; thank you
Some computing problems are “easy”* to solve. We call these P.
Some problems let us easily check a proposed solution if we’re given one. We call these NP.
All problems in P are also in NP, since checking a solution proposal works is never harder than solving the problem starting from nothing.
We suspect but can’t prove that some problems in NP are not in P.It turns out that it’s possible to translate any problem in NP into the boolean satisfiability problem (SAT) using an easy algorithm, so this problem effectively is an upper bound on how hard it could be to solve problems in NP - we could always translate them into SAT and solve that instead if that sequence is easier.
We call SAT, and any problem that it can be translated into easily in the same way, the problem class NP-hard.
NP-complete is just those NP-hard problems which are also in NP, which is many but not all of them.*: require asymptotically polynomial running time
Some problems get harder to do on bigger numbers. Like breaking a number into factors; the bigger the number, the harder it is to find the factors. Contrast this with, say, telling whether the number is even, which is easy even for very very large numbers.
There is a certain measure of how quickly problems get harder with bigger numbers called Polynomial Time; this is the P in P, NP, etc. I will omit the details of what polynomial time means exactly because if you don’t know from the name, then the details aren’t particularly important. It’s just a certain measure of how quick or hard the problem is to solve.
So for the various types of problems:
- P - The list of problems that can be solved quickly. For example, telling if a number is even.
- NP - The list of problems where you can check the answer quickly. For example, factoring a number.
- NP Complete - A list of special NP problems where we know how to “translate” any NP problem into one of these NP complete problems. Solving a Peg Solitaire game is NP complete.
- NP Hard - Problems at are as hard as NP Complete or harder. The travelling salesman problem (finding the shortest route that visits a list of cities) and the halting problem (figuring out if a computer program will get stuck in an infinite loop) are NP Hard.
I can only explain P, NP, and, NP-complete since those are on my exam. Firstly, P and friends are “sets” meaning they hold a collection of something. In this case it is the set of all problems that satisfy certain properties. A problem is something that requires an algorithm to reach a solution for any input. An algorithm is a protocol to complete some sort of procedure… it’s a series of steps. What’s important in P and NP is the number of steps this algorithm completes relative to the input size. We call this runtime. For example, n^2 is polynomial runtime, because as the input grows, the runtime grows exponentially. If the runtime is exponential, like 2^n, then it seemingly doubles or triples every time you increase the input - which for all things computer, is not nice. Any problem that has a known algorithm already to find a solution efficiently (in polynomial time) is in P. If the problem doesn’t, then it may be in NP. If a problem has an efficient “verifier” or something that can take a problem, its input, its solution, and “verify” that the solution is correct for all inputs, then it is in NP. However, this verifier has to be efficient. If something is in NP then we know of a sanity check to test if our solution from some kind of magic and otherworldly algorithm is correct. Naturally, if something is in P, it is also going to be in NP - but I think that’s because the algorithm is only returning true or false, which are called decision algorithms. An example would be: can I color this graph with 3 colors so that two nodes on an edge have different colors?
Lastly, the concept of “polynomial reducibility” becomes relevant. Basically, mathematicians think there is some sort of invisible problem out there that is represented by NP Complete. Like, the Question to all Life, the Universe, and Everything. The reason they think this is because quite a lot of problems seem to be the same problems. As in - rephrasing another problem brings you to another problem you’re familiar with. This is important since if you’re trying to find an efficient algorithm to X and know Y is “the same problem” then find an algorithm to Y, well, you’ve found an algorithm for X too. Since our algorithm has to be “efficient” or polynomial, something is reducible if there is a sort of pre-processing and post-processing step to convert an input to X to an input for Y in polynomial time. The common analogy is that Y is a black box, it computes an answer but can only speak a certain language. So, you translate your native language (problem X) to its language (problem Y), let it compute its answer, then translate its response back.
What this boils down to is, NP-complete is a class of problems to which there isn’t a readily available efficient algorithm for any of them, since they’re all the same NP problem essentially, and finding an algorithm to one means you find one to all of them. NP-C contains quite a lot of problems and most are seemingly unrelated. However, since no algorithm has been found to solve any efficiently, it might seem that none exists. Therefore, if you discover that an NP problem you’ve been so enthusiastically working on a solution for is polynomially reducible to something in NP complete, you should just give up, because other smarter and more talented people have already given a crack at it and failed.
This video helped me get questions relating to P vs NP correct in my Complexity and Computation undergrad class.