Circular array with minimum absolute difference among adjacent elements

1.3k Views Asked by At

Given a circular array, rearrange the array so that the maximum absolute difference between adjacent elements among all elements is minimum. Can anyone help me with this?

1

There are 1 best solutions below

3
On BEST ANSWER

Sounds like that's equivalent to the travelling salesman problem.

https://en.wikipedia.org/wiki/Travelling_salesman_problem

In your case, each element in the array is a city, and the distance between two cities is the difference between each element.

Here's a paper on a fast solution to TSP that I pulled off arxiv:

http://arxiv.org/ftp/cs/papers/0702/0702133.pdf

Here's a fast TSP solving library:

http://cran.r-project.org/web/packages/TSP/index.html


Your edit makes it no longer related to TSP.