r/computerscience • u/Wide0125 • Jun 19 '25
How are all NP problems reducible to NP-Complete?
I know that by definition, NP-Complete is the set of problems that is in NP and can be reduced to from every other NP problem. However, I can't seem to wrap my head around how so many different problems can all be reduced to a single problem.
36
Upvotes
15
u/Fresh_Meeting4571 Jun 19 '25
It’s easy to get some definitions or some of the “details” wrong, and some of the answers provided so far seem to do that. Here’s a “textbook” answer:
A problem is NP-complete if:
Any problem in NP => Problem A => Your problem
For this to work of course, you would need a “prototypical” NP-hard problem to start from. This is the SAT problem, which was shown by the Cook-Levin theorem to admit reductions from any problem in NP. How does that work? Well, it’s complicated, but it essentially uses the property that problems in NP have efficiently verifiable solutions.
I would urge you to check the book “Algorithms Illuminated” by Roughgarden and Sipser’s Theory of Computation book and read more about these topics.
Source: I am teaching NP-completeness at university.
Hope this helps.
73
u/umop_aplsdn Jun 19 '25
Circuit-SAT is an NP-complete problem. It asks, given a logical circuit with inputs and a boolean output, are there inputs that make the boolean output true?
Now imagine you have any problem in NP. Because it is in NP, given any problem instance, you can write a computer program that verifies it; i.e., the program returns true on an input if that input solves the problem, and false otherwise. A computer program runs on a microprocessor; i.e., a circuit. You can imagine now turning that computer program into a huge (polynomially sized) circuit that outputs true if there is a satisfying input. By this reduction, if you had an oracle that told you whether a Circuit-SAT instance was had inputs that make the output true, you can use that to solve any instance of the problem in NP!
It turns out that any circuit can be "flattened" into 3-SAT, and Karp showed that 3-SAT can be reduced to 20 other problems, showing that all of those problems are also NP-Hard (Karp's 21 problems). Those problems, 3-SAT, and Circuit-SAT are also in NP, so they are all NP-Complete!
11
u/abrahimladha Jun 19 '25
Google the Cook-Levin theorem. Essentially if a problem is in NP, it has a polytime verifier. you can convert this verifier to a circuit (or cnf, or...) such that the circuit outputs a 1 if the verifier does. The proof of the Cook-Levin is essentially just a lot of boolean programming. This may oversimplify it a bit.
19
u/esaule Jun 19 '25
NP complete problems are the hardest problems in NP. So if you can solve an NP compete problem, you've beat the final boss.
But look at Cook's theorem. It first proved that SAT is NP Complete and shows why any problem in NP reduces to SAT.
Then the rest os just transiticity of reduction. And therefore NP Complete being an equivalence class.
3
u/Classic-Try2484 Jun 19 '25
Circuit satisfiability is the grandfather. Essentially if we can generate an algorithm we can generate a circuit. So if circuit satisfiability is in P then all of NP is also in P and NP == P.
It was shown that 3Sat is just as hard as Sat by showing how any circuit can be written as a 3Sat problem. MaxClique et al were shown to be as hard as 3Sat by showing that you can turn any 3Sat program into a MaxClique (et al). Thus if MaxClique is in P then circuit satisfiability is in P.
To show a new problem is in np requires first you show the problem is in np (easy) and then you show that it’s np hard (not as easy). There are many np hard problems that are not in np but a solution to any of these is enough to solve all problems in np. Np hard problems are as hard as any problem in np. To show you are np hard you must show that a solution to the problem could be used to solve an existing np hard problem. Since that problem has already been proven to be np hard it’s turtles all the way down.
The traveling salesman problem is a nice example of np hard. With a small twist it can be converted to np complete.
Many np complete problems can be used to make a chain/loop but the traveling salesman problem is unique in that I know of no mapping to any other np complete/hard problems (other than the default circuit sat).
3
u/TSRelativity Jun 19 '25
Sipser talking about the Cook-Levin theorem on MIT OCW.
5
u/hiimgameboy Jun 19 '25
Ultimately, it comes down to the fact that computability is a well defined mathematical property, and that "does this Turing Machine accept this string" is the type of math question that can be encoded in a SAT formula, which isn't that surprising because boolean algebra is an extremely flexible way of representing all sorts of things. If you want more details, it's all written out in the proof that SAT is NP Complete, and it's well worth working through them.
-2
u/JoJoModding Jun 19 '25
It's not all problems. For example, graph isomorphism has not been shown to be NP-hard.
But besides, these problems are all "interesting." So maybe it's because we tend to find NP-complete programs interesting.