I have an array of points with their coordinates X and Y. Each point represents a bus stop.
I need to sort the points in a sequence by giving them sequence numbers, so that the path from the first to the last is the shortest.


For a convention, let's call the array "points", so we access and write by calling



```
point(i) for the point
point(i)(x) and point(i)(y) for the coordinates
point(n) is the sequence number.

```

It's also possible to use the "for each" loop:



```
for each point in points
point(x)
point(y)
point(n) 

```

The sequence needs to go through all the points of the array.
I searched a lot on the internet, and the only thing I could find is Dijkstra's algorithm, which is not exactly what I am looking for, since I need to go through all the points.


It would be great if one of you guys knew something about that...


Thanks a lot.


Julien



Algorithm for the shortest path through all the points of a 2D cloud
If you only care about the length of the path between the first and last bus stops, then it looks like you are trying to solve the shortest Hamiltonian path problem (HPP). This is related to the more widely studied traveling salesman problem, see [TSP](http://en.wikipedia.org/wiki/Travelling_salesman_problem). Since your points actually lie in the plane, you are considering the special case of the Euclidean Hamiltonian path problem. For Euclidean TSP, there is a [polynomial-time approximation scheme](http://en.wikipedia.org/wiki/Polynomial-time_approximation_scheme), so I am guessing that the same is true for Euclidean HPP. Also, there are some heuristics based on neural networks, that appear to work well. See this [paper](http://www.sciencedirect.com/science?_ob=ArticleURL&_udi=B6VC5-3YJYG1B-5&_user=10&_coverDate=04%2F30%2F2000&_rdoc=1&_fmt=high&_orig=search&_sort=d&_docanchor=&view=c&_searchStrId=1345451288&_rerunOrigin=google&_acct=C000050221&_version=1&_urlVersion=0&_userid=10&md5=fc6dbe054dae78d3e1c8dcacd48c03df).


