I have come into NP-complete problems and I can't tell when the problem is NP-complete.
Is there a shortcut to know whether a given problem is NP-complete or not so that I don't waste time thinking about a fast algorithm?
The only easy way to show that a problem is NP-Hard is to convert an already known NP-complete problem into this problem in polynomial time. Meaning the conversion should be calculated in polynomial time with respect to the size of the input. In this case, you know that the problem you have is NP-Hard, which means it is at least as hard as NP-Complete but may be more difficult.
At this point, you could stop trying to find a solution for it.
But if you also need to show that it is NP-complete, then you need to show that a solution could be check in polynomial time.
There is no easy way.
If you can transform a known NP-complete problem in an instance of your problem in polynomial time, than you know that your problem is also an NP-complete problem.
If you cannot find such a transformation, you simply don't know if it is NP-complete.
Related
Why is NP-hard unequal to NP-complete?
My informal understanding of definitions being used:
NP - all problems that can be verified in polynomial time
NP-complete - all problems that are NP and NP-hard
NP-hard - at least as hard as the hardest problem in NP
Decision Problem - A problem that asks a question with regards to an input and outputs a bool value
Confusion:
The problem with unknown solution of P vs NP arises from the fact that we cannot prove or disprove all problems in NP can be solved in polynomial time. It feels like a similar question arises from NP-complete vs NP-hard. How do we know all problems in NP-hard cannot be verified in polynomial time and thus result in NP-hard=NP-complete?
Here is my line of reasoning
From online research the distinction seems that this has something to do with decision problems (a concept I'm entirely new to but seem simple enough). I think this means that problems in NP have complementary decision problems that ask if an input is the solution to the problem. Let's say the problem is to find an optimal solution. I believe the complementary decision problem to be "is the given input the optimal solution?"and I believe that if this decision problem is verifiable in polynomial time then the problem is NP-complete (or in NP). So this means that NP-hard problems that aren't NP-complete problems are those that either have no decision problem (which I believe is never true since any brute force solution can answer this) or a problem is NP-hard and not NP-complete if it has a decision problem that's not verifiable in polynomial time. If it is the latter then it feels like we have the same problem from P vs NP. That is, how do we confirm all decision problems in NP-hard do not have polynomial time solutions?
Sorry if the above phrasing is weird. I will try and clarify any confusion in my question.
notes
I am interested in both an intuitive explanation and a formal explanation (a proof if it's a complicated answer). The formal explanation can certainly be a link to an academic paper. I don't want anyone to invest a significant amount of time into an overly complicated proof that may be beyond the scope of my understanding (I've found complexity theory to become very quickly... complex).
If it helps for the sake of explanation I have done work on the traveling salesman problem and I am currently working on a paper for the nurse scheduling problem (I believe these are NP-hard problems).
NP-Hard includes all problems whose solutions can be used to derive solutions to problems in NP with polynomial overhead.
This includes lots of problems that aren't in NP. For instance, the halting problem - an undecidable problem - is NP-Hard, because any problem in NP can be reduced to it in polynomial time:
Reduce any problem in NP to an instance of the NP-Complete problem 3-SAT
Construct in polynomial time a TM which checks all assignments and halts iff a satisfying assignment is found.
Use a solution to the halting problem to tell whether the TM halts.
If it halts, accept; otherwise, reject.
Can someone give me an example of an undecidable problem that is not NP-hard?
I'm unable to understand the difference between the two.
Thanks very much!
An NP-hard problem is one such that every problem in NP can be reduced to it. In fact, it is "at least as hard as" the problems in NP class. For example, TSP (Traveling Sales Person) is NP-hard. However, undecidable is a problem for which there is no algorithm that always decide correctly. For example, the question of whether a program halts at some point or not is undecidable. In fact, you may not have an algorithm that can answer this question correctly for all programs in the world. (This can be proved)
So, in brief, an undecidable problem is logically hard; no matter how strong your computers or algorithms are, they cannot be solved. But, NP-hard problems have algorithms to be solved with but those algorithms are not polynomial in time.
I get that if you can do a polynomial time reduction from "every" problem then it proves that the problem is at least as hard as every problem in NP. Except, how do we know that we've discovered every problem in NP? Can't there exist problems that we may not have discovered or proven exist in NP but CANNOT be reduced to any np-complete problem? Or is this still an open question?
As others have correctly stated, the existence of the problem that is NP, but is not NP-complete would imply that P != NP, so finding one would bring you a million dollar and eternal glory. One famous problem that is believed to belong in this class is integer factorization. However, your original question was
Can't there exist problems that we may not have discovered or proven
exist in NP but CANNOT be reduced to any np-complete problem?
The answer is no. By definition of NP-completeness, one of two
necessary conditions for a problem A to be NP-complete is that every NP problem needs to be reducible in polynomial time to A. If you want to find out how to prove that every single NP problem can be reducible in polynomial time to some NP-complete problem, have a look at the proof of Cook-Levin theorem that states that 3-SAT problem is NP-complete. It was the first proven NP-complete problem and many other NP-complete problems are later proven to be NP-complete by finding the appropriate reduction from 3-SAT to these problems.
NP consists of all problems that could (theoretically) be solved by being able to make lucky guesses, guessing the solution and checking in polynomial time that the solution is correct. For example, the travelling salesman problem "can I visit the capitols of all 50 states of the USA with a trip of less than 9,825 miles" can be solved by guessing a trip and checking that it is not too long.
And one problem in NP is basically simulating a programmable computer circuit with various inputs and checking whether a certain output can be achieved. And that programmable computer circuit is powerful enough to solve all problems in NP.
So yes, we know all about all problems in NP.
(Then of course an NP complete problem can by definition be used to solve any problem in NP. If there is a problem that it cannot solve, that problem is not in NP).
Except, how do we know that we've discovered every problem in NP?
We don't. The set of all problems in the universe is not only infinite, but uncountable.
Can't there exist problems that we may not have discovered or proven
exist in NP but CANNOT be reduced to any np-complete problem?
We don't know that. We suspect that this is the case, but this hasn't been proven yet. If we were to find a NP problem that is not in NP-Complete, it would be proof that P =/= NP.
It is one of the great unsolved problems in CS. Many brilliant minds have been taking a go at it, but this nut has been one tough one to crack.
I was trying to find a way to solve the problem in the famous game Flow. http://moh97.us/flow/
After googling I find out that this is a NP-complete problem. A good solution would make use of heuristics and cuts. How can I spot a NP-complete problem easily? Sometimes when I block, I can't see the obvious solution. When this happens with an NP-complete, it's better to recognise it quickly and move on to the next problem.
When you have an explosion of objects (say objects whose count grows
exponentially based on some parameter or parameters), this should point
you in the direction that it's an NP-complete problem. When you
have to inspect, check too many objects (combinatorial or others).
Usually these objects are subsets or sub-spaces of some initial
object space. You should build some intuition for this. But as usual,
the intuition lies sometimes (I've been lied like this by my intuition
on 2-3 occasions).
Then once you suspect some problem is NP-complete, just
Google for it and try finding more information about
the same or about a similar problem.
This is what I do at least and I've been
solving quite a few algorithmic problems
some time ago.
Here is a nice problem which I am pretty sure
is NP-complete but which can be solved through
a genetic algorithm for example.
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=973
And as Dukeling said, there's no generic way of doing this.
There's no easy generic way of doing this. It basically comes down to reducing some known NP-complete problem to solving this problem, or showing that they are equivalent.
So, learn more about well-known NP-complete problems and get more experience with reducing a problem to solving another problem and identifying equivalent problems.
Disclaimer: You just have to be careful of special cases of NP-complete problems - while the generic case of the problem may require exponential time to be solved, these special cases may actually be solvable in polynomial time.
Since any NP Hard problem be reduced to any other NP Hard problem by mapping, my question is 1 step forward;
for example every step of that algo : could that also be mapped to the other NP hard?
Thanks in advance
From http://en.wikipedia.org/wiki/Approximation_algorithm we see that
NP-hard problems vary greatly in their approximability; some, such as the bin packing problem, can be approximated within any factor greater than 1 (such a family of approximation algorithms is often called a polynomial time approximation scheme or PTAS). Others are impossible to approximate within any constant, or even polynomial factor unless P = NP, such as the maximum clique problem.
(end quote)
It follows from this that a good approximation in one NP-complete problem is not necessarily a good approximation in another NP-complete problem. In that fortunate world we could use easily-approximated NP-complete problems to find good approximate algorithms for all other NP-complete problems, which is not the case here, as there are hard-to-approximate NP-complete problems.
When proving a problem is NP-Hard, we usually consider the decision version of the problem, whose output is either yes or no. However, when considering approximation algorithms, we consider the optimization version of the problem.
If you use one problem's approximation algorithm to solve another problem by using the reduction in the proof of NP-Hard, the approximation ratio may change. For example, if you have a 2-approximation algorithm for problem A and you use it to solve problem B, then you may get a O(n)-approximation algorithm for problem B, since the reduction does not preserve approximation ratio. Hence, if you want to use an approximation algorithm for one problem to solve another problem, you need to ensure that the reduction will not change approximation ratio too much in order to get a useful algorithm. For example, you can use L-reduction or PTAS reduction.