For arrays of finite size, we can use binary search to get the solution in O(log(n)) time.
If we have an infinite array with constant time lookup of indexes, how fast can we find the first occurrence of a 1 if we know the array is sorted?
For arrays of finite size, we can use binary search to get the solution in O(log(n)) time.
If we have an infinite array with constant time lookup of indexes, how fast can we find the first occurrence of a 1 if we know the array is sorted?
What is the above question? What are your operations on the infinite array? O(1) lookup? Perhaps the best thing would be to look iterate up to the first occurrence of a 1 of index 2^n for some n, and then do binary search. Then you are guaranteed to find it in O(log(n)) where n is the position of the first index.
Edit: Ps. This is not guaranteed to terminate if the array is indeed infinite and contains only zeros.