Problem Trying Implement Binary Search Function Java Using Eclipse Ide Program Carry 10 00 Q43894053
Problem:
I am trying to implement a binary search function in Java usingthe Eclipse IDE. In this program, I am to carry out the same10,000,000 unsuccessful searches for eight different-sized arrays,namely arrays of sizes, 128, 512, 2048, 8192, 32768, 131072,524288, and 2,097,152. I need to measure each of the three programsand the time it takes to do the 10,000,000 searches for each of theeight arrays.
Please make corrections to my programs below so that it maysuccessfully debug/run.
Code:
class BinarySearch{
int BinarySearch(int arr[], int 1, int r, int x)
{
if (r>=1)
{
iint mid = 1 +(r – 1)/2;
if(arr[mid] ==x)
return mid;
if(arr[mid] >x)
return binarySearch(arr, 1, mid-1, x);
returnbinarySearch(arr, mid+1, r, x);
}
return -1;
}
public class Problem5InJava {
public static void main(String[] args) {
BinarySearch obj = newBinarySearch();
int size = 2097152;
int arr[] = new int[size];
for(int i = 0; i < size;i++)
{
arr[i] =0;
}
int x = 1;
int result = 0;
longstart=System.currentTimeMillis();
for(int i = 0; i < 10000000;i++)
{
result =obj.BinarySearch(arr, 0, size-1, x);
}
long end =System.currentTimeMillis();
long elapsed_time =end-start;
System.out.println(elapsed_time);
}
}
Expert Answer
Answer to Problem: I am trying to implement a binary search function in Java using the Eclipse IDE. In this program, I am to carry…
OR