Need the code adjusted to search for 50. With the end results matching the attached data. import java.util.Random; import java.util.Arrays; public class Lab6 { public static void main(String args[]) { int[] n= {2500, 5000, 10000, 20000, 40000}; for(int i=0; i= max) { throw new IllegalArgumentException("max must be greater than min"); } Random r = new Random(); return r.nextInt((max - min) + 1) + min; } }
Need the code adjusted to search for 50. With the end results matching the attached data.
import java.util.Random;
import java.util.Arrays;
public class Lab6 {
public static void main(String args[]) {
int[] n= {2500, 5000, 10000, 20000, 40000};
for(int i=0; i<n.length; i++) {
int[] arr1 = getRandIntArray(n[i]);
Arrays.sort(arr1);
long startTime = System.nanoTime();
// linear
linearSearch(arr1, 50);
// search 50 (this number is not in array)
// search a number outside the range (-10, 200)
// search a number that is inside the array (100)
long stopTime = System.nanoTime();
System.out.println("for array size: "+n[i]+" Execution time linear: "+(stopTime - startTime)/1000.0 + " microSec");
startTime = System.nanoTime();
// binary
binarySearch(arr1, 50);
stopTime = System.nanoTime();
System.out.println("for array size: "+n[i]+" Execution time binary: "+(stopTime - startTime)/1000.0 + " microSec");
}
}
public static void linearSearch(int[] arr, int search_item) {
for(int i=0; i<arr.length; i++) {
//System.out.println(arr[i]);
}
}
public static void binarySearch(int[] arr, int search_item) {
}
public static void printArray(int[] arr) {
for(int i=0; i<arr.length; i++) {
//System.out.println(arr[i]);
}
}
public static int[] getRandIntArray(int n) {
int[] arr = new int[n];
// Random array that doesn't contain 50
for(int i=0; i<n; i++) {
int num = getRandomNumberInRange(1,100);
if(num == 50) {
num+=1;
}
arr[i]=num;
}
return arr;
}
public static int getRandomNumberInRange(int min, int max) {
if (min >= max) {
throw new IllegalArgumentException("max must be greater than min");
}
Random r = new Random();
return r.nextInt((max - min) + 1) + min;
}
}
![Based on the given code, the time taken for
program to run the search is:
Searching 50 (not in array)
for array size: 2500 Execution time linear: 21.67 microSec
for array size: 2500Execution time binary: 1.971 microSec
for array size: 5000 Execution time linear: 34.281 microSec
for array size: 5000Execution time binary: 0.18 microSec
for array size: 10000 Execution time linear: 83.222 microSec
for array size: 10000Execution time binary: 0.21 microSec
for array size: 20000 Execution time linear: 130.494 microSec
for array size: 20000Execution time binary: 0.22 microSec
for array size: 40000 Execution time linear: 289.348 microSec
for array size: 40000Execution time binary: 0.231 microSec](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F8295a52d-4a2c-4cdc-ad96-938dc7903dc9%2F522c5501-28e3-49d9-9997-29b6bfacf82e%2Fcld553_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)