binary search - Programmers Heaven

Howdy, Stranger!

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

Categories

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.