Question: How many times does a binary search need to execute to find its value? Recall from our lesson that the number of iterations is roughly

How many times does a binary search need to execute to find its value? Recall from our lesson that the number of iterations is roughly a log base 2 relationship.
In this exercise, you are going to calculate the maximum iterations and the actual iterations needed to find a random value in arrays of size 100,1000,10k, and 100k.
You are given helper methods to calculate the maximum iterations, generate the random array, and do the binary search. You are also given a counter variable that increments each time your recursive binary method is called.
You will need to come up with the remainder of the code.
Sample Output
Array Size: 100
Max iterations: 7
Actual iterations: 5
Array Size: 1000
Max iterations: 10
Actual iterations: 5
 How many times does a binary search need to execute to

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!