How is TSP NP-Hard? - algorithm

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).

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.)

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

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.

Prove that the Weighted Feedback Vertex Set is NP-Complete

I need to show that the Weighted Feedback Vertex Set (WFVS) is NP-Complete. How do I do this, I got confused. I'm not sure how to do this.
Thanks! :)
There are 3 basic steps to showing that a problem is in NP
Decision Problem: Can you turn your problem into a decision problem? In the case of the WFVS problem, the decision problem might be "Given a graph G and real number K, is there a set of vertices V such that V satisfies the conditions of WFVS?
Certificate: Can you identify an answer to your decision question? Again, in the case of the WFVS problem, an answer might be the set of vertices in the Graph
Verification: Can you verify a certificate in polynomial time. By verifying in polynomial time, you know that the problem is not NP-Hard. Some verification steps might be: are all of the vertices/edges in the graph? is the sum of the weighted edges <= K? etc.
That is how you know that your problem is in NP.
NP Complete
To show that a problem is NP-Complete, you must find a commonly known NP-Complete problem, such as vertex cover or the travelling salesman problem, and show that your problem is just as hard as that problem by transforming the known problem into your problem, then proving that a 'yes' certificate to your problem implies a 'yes' certificate to the other problem, and vice versa.
This is how you show that your problem is 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 to find Hamiltonian Cycle in a Graph

I am trying to solve the Hamiltonian Cycle problem. I am able to find a path with all the vertices, but unable to complete the cycle.
Can someone provide me with an algorithm to find the cycle?
Determining if a graph has a Hamiltonian Cycle is a NP-complete problem. This means that we can check if a given path is a Hamiltonian cycle in polynomial time, but we don't know any polynomial time algorithms capable of finding it.
The only algorithms that can be used to find a Hamiltonian cycle are exponential time algorithms. Some of them are
Brute force search
Dynamic programming
Other exponential but nevertheless faster algorithms that you can find here
This is one of the most basic problems in computer science, there are plenty solutions depending on what you want: start here http://en.wikipedia.org/wiki/Hamiltonian_path_problem#Algorithms
There are also SO answers related:
here and here
I hope this below link which i found will help you lot with clear explanation...... http://www.geeksforgeeks.org/archives/19092
Use a SAT solver if possible. They don't have the good theoretical time limits of the algorithms in the Wikipedia article, but in practice they can often solve them surprisingly quickly.

Resources