Question
Hallo There! I have this one task, I don't konw how I code, so I need help please. Task! Binary and Linear Search. There are
Hallo There!
I have this one task, I don't konw how I code, so I need help please.
Task!
Binary and Linear Search. There are advantages and disadvantages of both algorithms. One is simple and is suitable for a small amount of data, the other is suitable for large amounts of data but requires data to be sorted. 1. In this task, implement the method public static int linearSearch (int [] a, int x), which searches linearly after the value x in the array a. Returns the position where x is found or returned -1. 2. Implement a method public static int binarySearch (int [] a, int x) that searches binary for the value x in the array a. The method returns the position if x is found otherwise returns -1. 3. Implement the method static int [] createArray (int size, int min, int max) that generates one array of integer values in the range min-max and with size size. 4. Write a program that generates an array of integer data in the 1-1000 range. The size of the array is first 100000 elements. The program should search for a slurry random value. The search must be done first with linearSearch () and then with binarySearch (). NOTE! Do not forget to sort the array before binary search (see java.util.Arrays.sort ()). The program should count the time taken for each search. You are reading the time: long time1 = System.currentTimeMillis (); Read the exact time before the search begins and then after the search ends. Count the difference and see how long it takes to search. Print the search time of a file along with the size of the array. You must have a file where you save the time for linear search and a file where you save the time for binary search. Make 10 searches for the same array. Is it different in the time you get? Why?
Thanks!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started