Question: Imagine an infinitely large array A[0...]. In this array, A[0] = A[1] = and = A[n 1] = 0, == A[n] = A[n+ 1]

Imagine an infinitely large array A[0...]. In this array, A[0] = A[1] = and = A[n 1] = 0, == A[n] = A[n+ 1] =

Imagine an infinitely large array A[0...]. In this array, A[0] = A[1] = and = A[n 1] = 0, == A[n] = A[n+ 1] = A[n+ 2] = = ... = 1. That is, the first n elements of the array are 0 and all subsequent elements are 1. In constant time we can query the array to find the value of an array element A[i]. We do not know the value of n, the index of the first nonzero element. (A) Describe an algorithm to find the value of n. This algorithm should make at most O(logn) queries. (B) Describe an algorithm for finding any index m, where A[m] c> 1. Show that this algorithm requires O(log log n) array queries. (C) Describe an algorithm for finding any m, where A[m] algorithm? = = 1 and m

Step by Step Solution

3.49 Rating (162 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

A To find the value of n in Olog n queries you can use a binary search approach Heres how the algorithm works Start with an initial guess for n lets c... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!