binary search - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

binary search

fonsdefonsde Posts: 1Member
You are given an infnite array A[] in which the first n cells contain integers in sorted order and
the rest of the cells are filled with1. You are not given the value of n. Describe an algorithm that
takes an integer x as input and finds a position in the array containing x, if such a position exists,
in O(log n) time. (If you are disturbed by the fact that the array A has infnite length, assume
instead that it is of length n, but that you don't know this length, and that the implementation
of the array data type in your programming language returns the error message 1 whenever
elements A[i] with i > n are accessed.)
Sign In or Register to comment.