Question: A binary search algorithm is written which searches a pre - sorted array for some user - defined value, clientData. If clientData is stored in

A binary search algorithm is written which searches a pre-sorted array for some user-defined value, clientData. If clientData is stored in the array, it returns its array position, and if not found, it returns -1(again, just like in the modules). Assume the array to be searched has 100 data elements in it.(Check all that apply).
HINT: Each recursive call throws away half of the elements it gets. The method gets 100 elements, but if clientData is not found in position 49(first comparison) the method throws 51 of those elements away and calls itself. This inner call now has 49 elements to search. It tests element 24 against clientData (second comparison), and if it is not a match, throws about away half again, leaving 24. The next call/comparison, if needed, throws away about 12. The next call, if needed, throws away 6. The next call throws away 3. The next call throws away 2. Finally we only have one element to test. Each recursive call does one comparison. How many comparisons have we done, give or take one, (count above) in the worst case, assuming we have to go all the way down until we only have one element before we find the data we are searching for?
[NOTE: due to common off-by-one interpretations when counting such things, if your predicted answer is within one (+1 or -1) of a posted option below, you can assume your prediction and the choice you are looking at are equivalent and check that option.]
Group of answer choices
It will always return with an answer in 3 or fewer comparisons of data.
It may require as many as 99 comparisons of data before it returns.
It might return to the client with an answer after only one comparison of data.
It will always return with an answer in 7 or fewer comparisons of data.

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!