Describe an olog n algorithm to determine the value of n


You are given an array A of length n. Each value is 1. However, you do not know what the value of n is. You are allowed to access an element i of the array by calling A[i]. If i < n, this will return 1, and if i ≥ n, this will return a message saying that the location does not exist (you can think of this as an error message, but it will not crash your program). Describe an O(log n) algorithm to determine the value of n. (Hint: think binary search, but in reverse.)

Solution Preview :

Prepared by a verified Expert
Business Economics: Describe an olog n algorithm to determine the value of n
Reference No:- TGS02464571

Now Priced at $10 (50% Discount)

Recommended (99%)

Rated (4.3/5)