Question: Write the method int iterativeBinarySearch ( int [ ] arr, int value ) . This method should accept a sorted array of integers and return
"Write the method int iterativeBinarySearchint arr, int value This method should accept a sorted array of integers and return the index at which value occurs in the array, using an iterative implementation of the binary search algorithm. If the value does not occur in the array, your method should return
Write the method int recursiveBinarySearchint arr, int value This method should accept a sorted array of integers and return the index at which value occurs in the array, using a recursive implementation of the binary search algorithm. If the value does not occur in the array, your method should return
Both using this main method that cannot be modified.
A class for implementing binary search
both iteratively and recursively
public class BinarySearch
public static void mainString args
int nums
;
long start end time ;
int result ;
test
start System.nanoTime;
result iterativeBinarySearchnums;
end System.nanoTime;
time end start;
System.out.printlnTest : Iterative found result in timenanosec;
test
start System.nanoTime;
result recursiveBinarySearchnums;
end System.nanoTime;
time end start;
System.out.printlnTest : Recursive found result in timenanosec;
test
start System.nanoTime;
result iterativeBinarySearchnums;
end System.nanoTime;
time end start;
System.out.printlnTest : Iterative found result in timenanosec;
test
start System.nanoTime;
result recursiveBinarySearchnums;
end System.nanoTime;
time end start;
System.out.printlnTest : Recursive found result in timenanosec;
test
start System.nanoTime;
result iterativeBinarySearchnums;
end System.nanoTime;
time end start;
System.out.println XFTest : Iterative found result in timenanosec;
test
start System.nanoTime;
result recursiveBinarySearchnums;
end System.nanoTime;
time end start;
System.out.printlnTest : Recursive found result in timenanosec;
public static int iterativeBinarySearchint arr, int value
return ;
public static int recursiveBinarySearchint arr, int value
return ;
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
