I have a sorted list of sample numbers, e.g.:
0.1, 0.2, 0.4, 0.5, 0.8, 0.9, 1.0, 1.5, 2.0, 4.0, 4.5, 5.0, 10.0, 15.0, 20.0
I need to find the resolution of the samples and the ranges in which those resolutions hold. The restriction is that once you go to a lower resolution (higher delta between the numbers), you cannot go back.
The correct output for the example should then be:
- From 0.1 to 1.0, resolution is 0.1
- From 1.0 to 5.0, resolution is 0.5
- From 5.0 to 20.0, resolution is 5.0
I tried going over the numbers and taking their difference as the resolution, and extending the range as long as that resolution holds, but I'm having difficulty with cases such as between 0.2 and 0.4 where the resolution could be 0.2, which is then invalidated with the next sample of 0.5.
Can anyone help me find an algorithm that can accomplish this? I'm using c++, with the numbers having a precision of 3 decimal places, if that makes any difference.