Quiz 4 Binary Search vs. Brute Force Search Algorithms for Finding a Local Minim
ID: 3723624 • Letter: Q
Question
Quiz 4 Binary Search vs. Brute Force Search Algorithms for Finding a Local Minimum in a Two- Dimensional Array In this project, you will implement the binary search-based (n) algorithm to determine the local minimum in an 'n'x 'n'two-dimensional array (as discussed in Module 2) and compare its run-time performance with that of a brute force O(n) algorithm that searches for the local minimum element by element until one is found Note that both the binary search and the brute force search algorithms should stop once a local mam is found. You should create random two-dimensional arrays (with numRows = numCols) with unique elements in the range.. numRows numCols] for the following values of numRows (numCols) and determi the average execution time of the binary search and the brute force search algorithms by running 200 for each of the numRows (numCols) values. Determine the running times in nano seconds or milli seconds, as appropriate. numRows (numCols) values: 4, 6, 8, 10, 15, 20, 25, 30, 35. 40, 50, 75, 100, 150, 200, 250, 300 Plot the results with numRows in X-axis and the average execution times (in nanoseconds or milliseconds) of the binary search and the brute force search algorithms in the Y-axis (1 -65 pts) Code for the binary search and the brute force search algorithms (2 - 15 pts) Excel plots of the numRows vs. average execution times of the two algorithms (3 - 20 pts) Your interpretation of the results. *use javáaExplanation / Answer
CODE:
public class Binarysearchapp {
public int binarySearch(int[] value, int input) {
int b = 0;//for intial value
int l = value.length - 1;//final value defination
while (b <= l) {
int n = (b + l) / 2;
if (input == value[n]) {//n is count between
return n;
}
if (input < value[n]) {
l = n - 1;
} else {
b = n + 1;
}
}
return -1;
}
public static void main(String[] args) {
Binarysearchapp mbs = new Binarysearchapp();
int arr[] = { 4, 6, 8, 10, 15, 20, 25, 30, 35, 40, 50, 75, 100, 150, 200, 250, 300, 350};
System.out.println("input 14's position:"+mbs.binarySearch(arr, 10));
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.