Well I have to find the smallest difference between any two elements of a large array. By large i mean really large like 10 million or more elements array. Although this is not a practical scenario i like to know the fastest possible ones. Getting an element, comparing with the rest of the elements , sorting the difference and getting the least difference is really unimaginable. Is there some efficient way to do this task? I would be happy.
Asked
Active
Viewed 470 times
1 Answers
0
How fast this can be done depends entirely on your notion of 'difference' - for example, if you just have an array of numbers and want the smallest difference between two numbers (that is, you have a total ordering available for your elements) then you can just sort and get the smallest difference between neighbors. If there is no total ordering, you'll have to minimize your checks by clustering your elements somehow (e.g. creating a spatial tree for an array of 3D points).

Cubic
- 14,902
- 5
- 47
- 92