<p>This is called an insertion heuristic. The general TSP cannot be approximated unless $P=NP$. The question is more interesting for the metric TSP. In that case, Rosenkrantz et al. (1974) show that your heuristic gives an $O(\log n)$ approximation.</p>

<p>You can also try to choose a good vertex $v$ to be inserted in each step, instead of just taking an arbitrary one. One variant is farthest insertion in which $v$ is chosen such that is has maximum distance from the current $H$. Another variant is nearest insertion in which $v$ is chosen such that it has minimum distance from the current $H$. Yet another possibility is cheapest insertion in which $v$ is chosen such that the new $H$ has minimum length. Rosenkrantz et al. show that both nearest and cheapest insertion give a $2-2/n$ approximation and this is tight.</p>

<p>The full reference is:
D. Rosenkrantz, R. Stearns, and P. Lewis II. An analysis of several heuristics for the traveling salesman problem. SIAM Journal on Computing, 6(3):563-581, 1977.</p>

CC BY-SA 2.5
2010-12-11T09:00:21.500Z
2010-12-11T09:00:21.500Z
Matthias
<p>As proven <a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.64.7246" rel="nofollow">here</a>, general TSP is NPO-complete. This means you can either solve it exactly in exponential time or approximate it in polynomial time with an approximation factor growing exponentially with the length of the input. This means that your algorithm, when applied to general TSP instances, cannot give a better guarantee than a factor $O(2^{n^\epsilon})$ for some $\epsilon &gt; 0$.</p>

<p>Different versions of TSP admit different bounds on approximation algorithms. For an overview, the site "A compendium of NP optimization problems" lists a number of TSP variants <a href="http://www.nada.kth.se/~viggo/wwwcompendium/node103.html" rel="nofollow">here</a>. Wikipedia also gives a lot of bounds on its page about TSP, <a href="http://en.wikipedia.org/wiki/Travelling_salesman_problem#Complexity_of_approximation" rel="nofollow">in this section</a> and <a href="http://en.wikipedia.org/wiki/Travelling_salesman_problem#Special_cases" rel="nofollow">in this section</a>.</p>

CC BY-SA 2.5
2010-12-12T11:47:25.763Z
2010-12-12T11:47:25.763Z
Alex ten Brink
<p>General TSP is not approximable within any factor, so your algorithm doesn't really have a chance of working well. A worst-case example:
We select one Hamiltonian cycle in the clique and give all its edges weight 1 (assume this cycle is $(v_1, v_2, ..., v_n, v_1)$. All the other edges have some big weight $\alpha(n)$. Now let's have your algorithm start with odd vertices. Between any odd vertices there are only edges with weight $\alpha(n)$ and we don't have any tie breaking rule, so the cycle on odd vertices your algorithm constructs can be totally arbitrary (we can for egample forbid it to contain any edges of the form $(v_i, v_{i+2})$. When the algorithm starts working on the even vertices, it will have just two possible places to put $v_i$: after $v_{i-1}$ or before $v_{i+1}$. Again we have no tie-breaking rule, so we can assume that it always choses to put $v_i$ after $v_{i-1}$ (of course we do all this modulo $n$). When we look at the constructed cycle, we see that it is built of alternating weight 1 and weight $\alpha(n)$ edges. So we have $OPT = n$, and our solution has weight ${n \over 2} + {\alpha(n) \over 2}$. We can chose $\alpha$ arbitrarily to disprove any claimed approximation factor. There are some technicalities involved with encoding weight $\alpha$; when we increase $\alpha$ the input size also grows (but more slowly), but still I think we can get any factor. </p>

CC BY-SA 2.5
2010-12-12T01:52:30.430Z
General TSP with the triangle inequality (which encompasses a large number of practical cases) is indeed approximable within a constant factor.
Peter Shor 
CC BY-SA 2.5
2010-12-11T08:48:02.070Z
2010-12-11T08:48:02.070Z
Karolina Sołtys
<p>Consider the following extremely simple approximation algorithm for the TSP.</p>

<p>Input: A complete weighted graph $G=(V,E).$
</p>

<ol>
<li>Take any three vertices $a,b,c\in V$ and let $H:=(a,b,c,a).$
</li>
<li><p>While there are vertices in V that are not in H:</p>

<ol>
<li>Take one of them, say $v.$ Let $H=(v_1,v_2,...,v_k,v_1),$ where $k$ is the number of distinct vertices currently contained in $H.$
</li>
<li>Take as new $H$ the shortest of all the Hamiltonian cycles $(v,v_1,v_2,\ldots,v_k,v),$ $(v_1,v,v_2,\ldots,v_k,v_1),$ $(v_1,v_2,v,\ldots,v_k,v_1),$ $\dots,$ $(v_1,v_2,\ldots,v,v_k,v_1),$ i.e., insert $v$ before every vertex in $H$ and find the shortest Hamiltonian cycle among all those.</li>
</ol></li>
</ol>

<p>Output: $H.$
</p>

<p>Obviously, this algorithm has runtime $O(n^2).$
</p>

<p>Can anyone give me a lower (or upper) bound on the approximation ratio of this algorithm? Or a worst-case example, for that matter?</p>

CC BY-SA 2.5
2010-12-11T07:50:46.497Z
The question is definitely within scope. Try to state your algorithm more clearly (for example, what is *k*?), and use LaTeX code to help you with the math formulas.
Hsien-Chih Chang 張顯之
CC BY-SA 2.5
2010-12-11T08:14:37.637Z
Thank you for the tips! I wasn’t sure about the LaTeX because the preview only “switches” after a few seconds.
Sacha
CC BY-SA 2.5
2010-12-11T08:19:44.077Z
@Sacha: You are welcome! The revision is nice, and it will make the question more readable, which increase the possibility that the question will be answered. A small typo: in the inner-loop, the cycles should be $(v,v_1,\ldots,v_k)$, $(v_1,v,\ldots,v_k)$ and so on, right?
Hsien-Chih Chang 張顯之
CC BY-SA 2.5
2010-12-11T08:24:37.457Z
I’m not sure what you mean. There was indeed a tiny typo in the definition of the first Hamiltonian cycle (it is of course $(v,v_1,v_2,\ldots,v_k,v)$ instead of $(v,v_1,v_2,\ldots,v_k,v_1)$). But I think our notation differs a little bit. What you write are paths to me—I think it’s just a matter of definition whether you include the last (first) vertex twice.
Sacha
CC BY-SA 2.5
2010-12-11T08:30:21.960Z
I got you point, and you are right :) By writing $(v,v_1,\ldots,v_k)$, I do mean a cycle through all the nodes in it, which is the same as your notation $(v,v_1,\ldots,v_k,v)$.
Hsien-Chih Chang 張顯之
CC BY-SA 2.5
2010-12-11T09:38:44.180Z
Is it allowed to renumber vertices in $H$ between iterations?
Raphael
<ds.algorithms><graph-theory><approximation-algorithms><tsp><optimization>
A simple approximation algorithm for the TSP
Sacha
# A simple approximation algorithm for the TSP

(Asked by: username_0 on 2010-12-11)

Consider the following extremely simple approximation algorithm for the TSP.

Input: A complete weighted graph $G=(V,E).$

1. Take any three vertices $a,b,c\in V$ and let $H:=(a,b,c,a).$
2. While there are vertices in V that are not in H:

   1. Take one of them, say $v.$ Let $H=(v\_1,v\_2,...,v\_k,v\_1),$ where $k$ is the number of distinct vertices currently contained in $H.$
   2. Take as new $H$ the shortest of all the Hamiltonian cycles $(v,v\_1,v\_2,\ldots,v\_k,v),$ $(v\_1,v,v\_2,\ldots,v\_k,v\_1),$ $(v\_1,v\_2,v,\ldots,v\_k,v\_1),$ $\dots,$ $(v\_1,v\_2,\ldots,v,v\_k,v\_1),$ i.e., insert $v$ before every vertex in $H$ and find the shortest Hamiltonian cycle among all those.

Output: $H.$

Obviously, this algorithm has runtime $O(n^2).$

Can anyone give me a lower (or upper) bound on the approximation ratio of this algorithm? Or a worst-case example, for that matter?

**Tags:** ds.algorithms, graph-theory, approximation-algorithms, tsp, optimization

> **Comments:**
> **username_1**: The question is definitely within scope. Try to state your algorithm more clearly (for example, what is *k*?), and use LaTeX code to help you with the math formulas.  
> **username_0**: Thank you for the tips! I wasn’t sure about the LaTeX because the preview only “switches” after a few seconds.  
> **username_1**: @username_0: You are welcome! The revision is nice, and it will make the question more readable, which increase the possibility that the question will be answered. A small typo: in the inner-loop, the cycles should be $(v,v_1,\ldots,v_k)$, $(v_1,v,\ldots,v_k)$ and so on, right?  
> **username_0**: I’m not sure what you mean. There was indeed a tiny typo in the definition of the first Hamiltonian cycle (it is of course $(v,v_1,v_2,\ldots,v_k,v)$ instead of $(v,v_1,v_2,\ldots,v_k,v_1)$). But I think our notation differs a little bit. What you write are paths to me—I think it’s just a matter of definition whether you include the last (first) vertex twice.  
> **username_1**: I got you point, and you are right :) By writing $(v,v_1,\ldots,v_k)$, I do mean a cycle through all the nodes in it, which is the same as your notation $(v,v_1,\ldots,v_k,v)$.  
> **username_2**: Is it allowed to renumber vertices in $H$ between iterations?  

---

## 3 answers

### Answer by username_5 on 2010-12-11. Score: 9 | Accepted answer

General TSP is not approximable within any factor, so your algorithm doesn't really have a chance of working well. A worst-case example:
We select one Hamiltonian cycle in the clique and give all its edges weight 1 (assume this cycle is $(v\_1, v\_2, ..., v\_n, v\_1)$. All the other edges have some big weight $\alpha(n)$. Now let's have your algorithm start with odd vertices. Between any odd vertices there are only edges with weight $\alpha(n)$ and we don't have any tie breaking rule, so the cycle on odd vertices your algorithm constructs can be totally arbitrary (we can for egample forbid it to contain any edges of the form $(v\_i, v\_{i+2})$. When the algorithm starts working on the even vertices, it will have just two possible places to put $v\_i$: after $v\_{i-1}$ or before $v\_{i+1}$. Again we have no tie-breaking rule, so we can assume that it always choses to put $v\_i$ after $v\_{i-1}$ (of course we do all this modulo $n$). When we look at the constructed cycle, we see that it is built of alternating weight 1 and weight $\alpha(n)$ edges. So we have $OPT = n$, and our solution has weight ${n \over 2} + {\alpha(n) \over 2}$. We can chose $\alpha$ arbitrarily to disprove any claimed approximation factor. There are some technicalities involved with encoding weight $\alpha$; when we increase $\alpha$ the input size also grows (but more slowly), but still I think we can get any factor.

> **Comments:**
> **username_6**: General TSP with the triangle inequality (which encompasses a large number of practical cases) is indeed approximable within a constant factor.  

---

### Answer by username_3 on 2010-12-11. Score: 25

This is called an insertion heuristic. The general TSP cannot be approximated unless $P=NP$. The question is more interesting for the metric TSP. In that case, Rosenkrantz et al. (1974) show that your heuristic gives an $O(\log n)$ approximation.

You can also try to choose a good vertex $v$ to be inserted in each step, instead of just taking an arbitrary one. One variant is farthest insertion in which $v$ is chosen such that is has maximum distance from the current $H$. Another variant is nearest insertion in which $v$ is chosen such that it has minimum distance from the current $H$. Yet another possibility is cheapest insertion in which $v$ is chosen such that the new $H$ has minimum length. Rosenkrantz et al. show that both nearest and cheapest insertion give a $2-2/n$ approximation and this is tight.

The full reference is:
D. Rosenkrantz, R. Stearns, and P. Lewis II. An analysis of several heuristics for the traveling salesman problem. SIAM Journal on Computing, 6(3):563-581, 1977.


---

### Answer by username_4 on 2010-12-12. Score: 3

As proven [here](http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.64.7246), general TSP is NPO-complete. This means you can either solve it exactly in exponential time or approximate it in polynomial time with an approximation factor growing exponentially with the length of the input. This means that your algorithm, when applied to general TSP instances, cannot give a better guarantee than a factor $O(2^{n^\epsilon})$ for some $\epsilon > 0$.

Different versions of TSP admit different bounds on approximation algorithms. For an overview, the site "A compendium of NP optimization problems" lists a number of TSP variants [here](http://www.nada.kth.se/~viggo/wwwcompendium/node103.html). Wikipedia also gives a lot of bounds on its page about TSP, [in this section](http://en.wikipedia.org/wiki/Travelling_salesman_problem#Complexity_of_approximation) and [in this section](http://en.wikipedia.org/wiki/Travelling_salesman_problem#Special_cases).


---

