Why is TSP NP-hard while the Hamiltonian path NP-complete? - algorithm

Why aren't these 2 problems, namely TSP and Hamiltonian path problem, both NP-complete?
They seem identical.

For a problem X to be NP-complete, it has to satisfy:
X is in NP, given a solution to X, the solution can be verified in polynomial time.
X is in NP-hard, that is, every NP problem is reduceable to it in polynomial time (you can do this through a reduction from a known NP-hard problem (e.g. Hamiltonian Path)).
There are two versions of the The Travelling Salesman Problem (TSP):
The optimization version (probably the one you are looking at), namely, find the optimum solution to the TSP. This is not a decision problem, and hence cannot be in NP, but it is however in NP-hard which can be proven via a Hamiltonian Path reduction. Therefore this isn't an NP complete problem.
The decision version - given an integer K is there a path through every vertex in the graph of length < K? This is a decision (yes/no) problem, and a solution can be verified in polynomial time (just traverse the path and see if it touches every vertex) and so it is in NP, but it is also in NP-hard (by an identical proof as above). Since it satisfies both requirements for NP-completeness, it is an NP-complete problem.

The definitions of NP-hardness and NP-completeness are related but different. Specifically, a problem is NP-hard if every problem in NP reduces to it in polynomial time, and a problem is NP-complete if it's both NP-hard and itself in NP.
The class NP consists of decision problems, problems that have a yes/no answer. As a result, TSP cannot be in NP because the expected answer is a number rather than yes or no. Therefore, TSP can be NP-hard, but it can't be NP-complete.
On the other hand, the Hamiltonian path problem asks for a yes/no answer, and it happens to be in NP. Therefore, since it's NP-hard as well, it's NP-complete.
Now, you can take TSP and convert it to a decision problem by changing the question from "what's the cheapest path?" to "is there a path that costs X or less?," and that latter formulation is in NP and also happens to be NP-complete.

Related

Is the NO-VERTEX-COVER in NP or not?

This is the reverse version of vertex cover problem. Consider a decision problem that asks whether, given a graph G = (V, E) and a nonnegative integer k, there does not exist a vertex cover of size no larger than k. Answer whether this problem is NP or not ? Please explain to me.
A short answer would be no (unless co-NP=NP).
Your decision problem, NO-VERTEX-COVER, is exactly the complement of the well-known VERTEX-COVER problem; the latter problem is NP-complete (and is, of course, in NP). Your problem NO-VERTEX-COVER is thus in co-NP. (Recall that a problem is in co-NP if and only if its complement is in NP.)
Because VERTEX-COVER, the complement of you problem, is NP-complete, it follows that unless co-NP=NP, the NO-VERTEX-COVER problem is not in NP. (This follows from a theorem that says that if co-NP is not equal to NP then no NP-complete problem is in co-NP.)

Complexity of Some problems in NP?

I want to summarize some problem on Complexity. Which of them can be solved in poly-time?
I) finding maximal sub complete graph of given graph = Clique Problem
II) select some elements among n objects in which value and weights
are given, such that sum of weights of selected elements is not bigger
than an specific bound and sum of value being maximum
III) finding all cycles of a graph
IV) Finding a path that visit each vertex exactly once = Determine a graph is Hamiltonian
I think IV is Hamiltonian path that is NP-Complete, III is NP-Hard and NP-Complete, II is NP-Complete, and I is NP-Complete. so 0 of these solved in poly-time.
Who can more clearer me about NP-Hard and NP-Complete of these problem in a nice way? Am I right?
As you've noted, parts (1), (2), and (4) are all famous NP-hard problems (max clique, knapsack, and Hamiltonian path). These problems are not in NP, though, because NP consists of decision problems (questions for which the answer is either "yes" or "no") and these are not decision problems.
Part (3) is more nuanced. This problem is a counting problem - the goal is to determine how many objects of some type exist - rather than a decision problem, so it can't be in NP. To the best of my knowledge, it's not really known how hard this problem is. It's known that if it can be solved in polynomial time, then P = NP (see this link for details), and the specific proof shows that it's NP-hard as well.
If P ≠ NP, then none of these can be solved in polynomial time. If any of these can be solved in polynomial time, then P = NP. They are all NP-hard.
Hope this helps!
Because I got asked about a reference, I am posting my comment as the answer:
II) select some elements among n objects in which value and weights
are given, such that sum of weights of selected elements is not bigger
than an specific bound and sum of value being maximum
This is a knapsack problem which is poly-time if weights are not a part of input size, i.e the solution is polynomial in terms of n only.
It runs in O(n * W) where W is the maximum allowed weight. Of course this can be not polynomial if W is related to n, for example if W = 2^n.
You can read about it here:
http://en.wikipedia.org/wiki/Knapsack_problem#Dynamic_programming_in_advance_algorithm
http://www.personal.kent.edu/~rmuhamma/Algorithms/MyAlgorithms/Dynamic/knapsackdyn.htm

NP-Complete and some decision problems on graph?

We know about NP-Complete and NP-Hard, and NP Class. I want to conclude some tips on following problem, that take from 2008 Mid exam on MIT.
Decision Version of which of the following problem for a connected undirected weighted graph G is NP-Complete?
a) finding maximal matching.
b) finding maximum Hamiltonian cycle
c) finding maximum Eulelrian cycle
d) finding maximum cut
How can categorized these problem in a simple manner for me? i.e. NP or NP-Complete or NP-Hard.
There are poly-time algorithms for computing maximal matchings (e.g., greedy; Edmonds's Blossom algorithm computes a maximum matching in poly-time) and Eulerian cycles. The decision versions trivially belong to NP (P, in fact).
Hamilton cycle and max cut are well-known NP-hard problems. The decision versions are in NP so thus are NP-complete.

How can some NP-Complete problems be also NP-Hard?

I'm trying wrap my heard around P, NP, NP-Complete and NP-Hard in an intuitive way so that I don't have to remember their definitions.
In the following image (the left hand scenario, P != NP), there's an overlapping area between NP-Complete and NP-Hard. Does it mean that some problems are both NP-Complete and NP-Hard? I find that contradictory, according to this particular answer: What are the differences between NP, NP-Complete and NP-Hard?.
The table in the above link says an NP-Complete problem is verifiable in polynomial time and an NP-Hard problem is not. So how can there be an overlap?
Part of the definition of NP-completeness is being NP hard. Therefore, every NP-complete problem is NP-hard. This is also reflected by both of your graphs.
The table you linked to was wrong until I fixed it a few hours ago. NP-Complete problems are a subset of NP problems, and all NP problems are verifiable in polynomial time by definition. NP-hard problems are those problems which are at least as hard as any other NP problem (which is sort of unintuitive, because problems not in NP can be NP-hard).
To be NP-Complete a problem must be
in NP
NP-hard
to be complete in a specific complexity class, a problem must be
in that complexity class
at least as hard as any other problem in that complexity class
We have to define "at least as hard". Suppose we have a problem A in NP. To prove it is NP-hard (and therefore NP-Complete), we show that all problems in NP can be converted to A in polynomial time. Because A takes at least polynomial time to solve, and polynomials are closed under addition, the conversion is now negligible, and the runtime is the same as the runtime of A (in terms of it being polynomial or not).
Once you have one NP-Complete problem, you can prove a problem A in NP is NP-hard (and therefore NP-Complete) by taking another NP-Complete problem B and converting it to A in polynomial time.
I hope this makes it clear that NP-Complete is a subset of NP-hard (and that the table you linked to was wrong).

How is TSP NP-Hard?

I read the following in one of the answer on SO :
The Traveling Salesman Problem, as normally posed, is to find the cheapest route connecting all cities. That isn't a decision problem, and we can't verify any proposed solution directly. We can restate it as a decision problem: given a cost C, is there a route that's cheaper than C? This problem is NP-complete, and with a little work we can solve the original TSP about as easily as the modified, NP-complete, form. Therefore, the TSP is NP-hard, since it's at least as hard as an NP-complete problem.
I understand that a TSP is NP-Complete but how the problem is NP-Hard ? I read that problems that are in NP but not in P are NP-Hard. I cannot relate this thing to the TSP . Please explain this.
NP-Hard problems are those problems for which every problem in NP has a polynomial time (Cook or Karp, multiple definitions) reduction to. These could contain problems which are not in NP and in fact need not even contain decideable problems (like the Halting problem).
NP-Complete problems are those problems in NP which are also NP-Hard.
If P is not equal to NP, then there are infinitely many problems in NP which are neither in P, nor NP-Complete (Ladner's theorem).
The optimization version of TSP problem has been shown NP-hard, but yet known whether it's in NP or not since there is yet known verification algorithms.
The decision version of the TSP problem has been shown NP-complete (both in-NP and NP-hard).

Resources