Let's say that I have an array of doubles, for example double[] foo = double[] {1.3, 4.5, 8.12, 10.1};
Just assume the doubles are in increasing order.
Can you guys make me a fast algorithm (function) that takes two parameters, a double array and a double, and returns the lowest element in the array that is greater than or equal to that given double? By lowest element, I actually mean the "index of the lowest element".
Phrased more clearly: Let a_0, a_1, ..., a_n be positive real numbers. Let a be a positive real number. Find the least i such that a_i >= a.
Is there any faster way to do this than just for-looping through the array?
Notice that the beast should be fast in the sense that the array is constant throughout, but the double (that I call a above) is changing alot and I will always need to find such a "least index" for different a's loads of times over and over again.
or if you dont like to use that try to copy the content of your array to a List variable then use Find() or FindAll() but these functions would iterate on your items internally..