Question: You are given as input an array A [ 1 . . . n ] , with n entries. The array consists of a series

You are given as input an array A[1...n], with n entries. The array consists of a series of 0s followed by a series of 1s, but you dont know how many of each there are. Your goal is to find the first 1 in the array. There is a cost associated with checking the value of an array. Each time you check a value and it turns out to be 0, you must pay 1 dollar. If value turns out to be 1, you have to pay 1 euro. In each of the parts of this question, you will have some number of dollars and some number of euros. You must give an algorithm which will return the index of the first (lowest index) occurrence of 1 which works given your resources. Justify that your algorithm does not use more than the given amount of dollars and euros. Now consider the case where you are given an array A, but you dont know its size n. Again, you want to find the first 1 in the array. Suppose this first 1 is at some location t (and of course you dont know the value of t). Give an algorithm that solves the problem using O(\sqrt(t)) dollars and 2 euros.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!