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 presorted array for some userdefined value, clientData. If clientData is stored in the array, it returns its array position, and if not found, it returns again just like in the modules Assume the array to be searched has data elements in itCheck all that apply
HINT: Each recursive call throws away half of the elements it gets. The method gets elements, but if clientData is not found in position first comparison the method throws of those elements away and calls itself. This inner call now has elements to search. It tests element against clientData second comparison and if it is not a match, throws about away half again, leaving The next callcomparison if needed, throws away about The next call, if needed, throws away The next call throws away The next call throws away 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 offbyone interpretations when counting such things, if your predicted answer is within one or 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 or fewer comparisons of data.
It may require as many as 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 or fewer comparisons of data.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
