6

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

They seem identical.

nbro
  • 15,395
  • 32
  • 113
  • 196
User
  • 23,729
  • 38
  • 124
  • 207

2 Answers2

9

For a problem X to be NP-complete, it has to satisfy:

  1. X is in NP, given a solution to X, the solution can be verified in polynomial time.
  2. 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):

  1. 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.
  2. 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.
Community
  • 1
  • 1
ifma
  • 3,673
  • 4
  • 26
  • 38
  • So the optimization problem is NP-hard? – User Jul 28 '16 at 21:02
  • 1
    I think there's a couple of errors in your definitions. A decision problem may not have a solution that's verifiable in poly time (it's just any problem with a yes/no answer). NP-hard isn't defined in terms of other NP-hard problems (although your definition is sufficient, it's not necessary) -- the definition is that every NP problem is reduceable to it in poly time. – Paul Hankin Jul 29 '16 at 03:08
  • @PaulHankin Yes of course you are correct, thanks very much for your comment. For the NP-hard definition I just wanted to give an intuitive definition, and the step required to prove a problem X is in NP-hard. I updated my answer. – ifma Jul 29 '16 at 03:20
  • Question: For a TSP decision problem, assume that the answer is no. How would you check that in polytime? – wjmccann Jan 13 '18 at 23:50
  • @wjmccann by traversing the given solution and verifying that it is indeed "no". You can't just simply say "no" -- you need to provide a proof for why the answer is "no" -- from there you can simply check it, and it is in poly time because you just need to traverse n nodes from the solution. – ifma Jan 27 '18 at 09:10
5

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.

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065