I want to find the index of 2 values A and B in a large array, from an input X, with the following conditions: - the array will have values in an increasing order, and the values are all ints. - the spacing of the values in the array is unknown - X will be an input in the range of coverage of the array. - A will be the closest number to X such that A < X - B will be the closest number to X such that B > X - if X is exactly equal to a number in the array, the index of that number will be returned.

I sort of know how to code this in arduino, but I was wondering what is the most efficient way and less clock cycles as possible way to do this...

If I understand you correctly (the array is in numeric size order) then...subdivide the array (take the midpoint of the array) and check if it value is higher or lower than your target.if the array value is lower subdivide the upper half again if the array value is higher subdivide the lower half again and so on until you get a match or the array will divide no more.There are variations on this