Instance: A graph G
Question: Does the graph contains a HC, i.e. an ordered of the vertices ?
This problem is intimately relates to the Traveling Salesman.
Question: Is there an ordering of the vertices of a weighted graph such that ?
Clearly, . Assign each edge in G weight 1, any edge not in G weight 2. This new graph has a Traveling Salesman tour of cost n iff the graph is Hamiltonian. Thus TSP is NP-complete if we can show HC is NP-complete.
Theorem: Hamiltonian Circuit is NP-complete
Proof: Clearly HC is in NP-guess a permutation and check it out. To show it is complete, we use vertex cover. A vertex cover instance consists of a graph and a constant k, the minimum size of an acceptable cover. We must construct another graph. Each edge in the initial graph will be represented by the following component:
We claim this graph has a HC iff G has a VC of size k.
Assume it starts at one of the k selector vertices. It must then go through one of the chains of gadgets until it reaches a different selector vertex.
Since the tour is a HC, all gadgets are traversed. The k chains correspond to the vertices in the cover.
Note that if both vertices associated with an edge are in the cover, the gadget will be traversal in two pieces - otherwise one chain suffices.
To avoid visiting a vertex more than once, each chain is associated with a selector vertex.
We can always add more vertices to the cover to bring it up to size k.
For each vertex in the cover, start traversing the chain. At each entry point to a gadget, check if the other vertex is in the cover and traverse the gadget accordingly.
Select the selector edges to complete the circuit.
Neat, sweet, and NP-complete.
To show that Longest Path or Hamiltonian Path is NP-complete, add start and stop vertices and distinguish the first and last selector vertices.
Listen To Part 26-2
Other NP-complete Problems
Open: Graph Isomorphism, Composite Number, Minimum Length Triangulation.
Listen To Part 26-3
Polynomial or Exponential?
Just changing a problem a little can make the difference between it being in P or NP-complete:
|Shortest Path||Longest Path|
|Eulerian Circuit||Hamiltonian Circuit|
|Edge Cover||Vertex Cover|
Listen To Part 26-4
Techniques for Proving NP-completeness
Listen To Part 26-5
The Art of Proving Hardness
Proving that problems are hard is an skill. Once you get the hang of it, it is surprisingly straightforward and pleasurable to do. Indeed, the dirty little secret of NP-completeness proofs is that they are usually easier to recreate than explain, in the same way that it is usually easier to rewrite old code than the try to understand it.
I offer the following advice to those needing to prove the hardness of a given problem:
Never use the general traveling salesman problem (TSP) as a target problem. Instead, use TSP on instances restricted to the triangle inequality. Better, use Hamiltonian cycle, i.e. where all the weights are 1 or . Even better, use Hamiltonian path instead of cycle. Best of all, use Hamiltonian path on directed, planar graphs where each vertex has total degree 3. All of these problems are equally hard, and the more you can restrict the problem you are reducing, the less work your reduction has to do.
Don't be afraid to add extra constraints or freedoms in order to make your problem more general (at least temporarily).
Selecting the right source problem makes a big difference is how difficult it is to prove a problem hard. This is the first and easiest place to go wrong.
I usually consider four and only four problems as candidates for my hard source problem. Limiting them to four means that I know a lot about these problems - which variants of these problems are hard and which are soft. My favorites are:
You are trying to translate one problem into another, while making them stay the same as much as possible. The easiest way to do this is to be bold with your penalties, to punish anyone trying to deviate from your proposed solution. ``If you pick this, then you have to pick up this huge set which dooms you to lose.'' The sharper the consequences for doing what is undesired, the easier it is to prove if and only if.
You should be asking these kinds of questions. ``How can I force that either A or B but not both are chosen?'' ``How can I force that A is taken before B?'' ``How can I clean up the things I did not select?''
Sometimes the reason you cannot prove hardness is that there is an efficient algorithm to solve your problem! When you can't prove hardness, it likely pays to change your thinking at least for a little while to keep you honest.
Listen To Part 26-8
Now watch me try it!
To demonstrate how one goes about proving a problem hard, I accept the challenge of showing how a proof can be built on the fly.
I need a volunteer to pick a random problem from the 400+ hard problems in the back of Garey and Johnson.
Listen To Part 27-2
Dealing with NP-complete Problems
Option 1: Algorithm fast in the Average case
Option 2: Heuristics
Note that the theory of NP-completeness does not stipulate that it is hard to get close to the answer, only that it is hard to get the optimal answer.
Often, we can prove performance bounds on heuristics, that the resulting answer is within C times that of the optimal one.