# Nearest Insertion Traveling Salesman Heuristic: is it faster to insert nearest nodes first?

I am trying to implement the nearest insertion TSP heuristic. However, I am wondering if it matters which node I insert into the subgraph first.

For example, should I start with one node; calculate the distance between this node and the other nodes; and sort the other nodes by this distance? Then, I will insert the closest node (to the first node) first. Will this be faster than randomly choosing nodes to insert?

• I'm a little confused: sure, it can be faster if you insert a random node as the next node, but then you are not following the nearest insertion heuristic anymore. – Juho Dec 1 '18 at 19:57
• @Juho Well, I didn't know a name for this "new technique" but it doesn't matter that I'm not following the insertion heuristic if this variation is faster, so do u know if it is? – Goldname Dec 1 '18 at 20:07

Inserting a random point instead of a nearest point can be faster, but then you are not following the nearest insertion heuristic anymore. The key is to realize that the point is not the runtime efficiency of the algorithm, but rather the quality of the solution obtained. Indeed, remember that we are dealing with an NP-hard problem.

The nearest neighbor heuristic should return considerably shorter tours than random insertion. In fact, we can prove that the ratio of the nearest insertion heuristic's solution to the minimum tour length is bounded by $$O(\log n)$$, where $$n$$ is the number of cities. No such guarantee exists for the random insertion that you propose, i.e., such a heuristic can return very long tours.

• How about this instead: I insert the node closest to one particular node. I build the graph around one node? Is that a good solution? – Goldname Dec 1 '18 at 21:13
• @Goldname What are you actually trying to achieve? Do you care about the length of the tour at all? How fast should the algorithm be? – Juho Dec 1 '18 at 21:30
• I'm looking for an accurate and fast running estimation of the tour, but I want it to be easy to code as well. – Goldname Dec 1 '18 at 23:22
• @Goldname OK. Google for 2-opt as well. – Juho Dec 1 '18 at 23:24