First the practical application that led me to the problem:
Given a set of angle measurements v[i] in the range of [0,360) degrees,
what is the smallest interval containing all v[i]?
Note: the interval may be on both sides, close around 0.
Abstract description of the problem:
For a given set of values v[i], what are the values c and d, such that
- for all
i:dist(v[i],c) <= dand dis as small as possible anddist(x,y) = abs(((x-y + N/2 + N) mod N) - N/2)?
This is trivial on an open (infinite) scale, where dist(x,y) = abs(x-y):
calculate max and min of all v[i]
c = (max + min)/2;
d = (max - min)/2;
But what's the best way to find c and d for a finite scale (modulo N) and a distance defintion as given above?
Is there maybe a way to do it O(n) (if n is the number of values)?