create alinearsearch andbinarysearch and record the time it takes for searching for various numbers. There is starter code at the end of this document.ArrayCreate an array of integers with size...







create a
linear
search and
binary
search and record the time it takes for searching for various numbers. There is starter code at the end of this document.




Array




Create an array of integers with size 1,000,000 and fill it with numbers 1 - 1,000,000 in order.



Linear Search


Create a
linear
search method called linearSearch with the method signature below. This method takes the array of integers and the number we are searching for and should return the
index
of the number in the array or -1 if not found.



public static int
linearSearch
(int a[], int search)



Binary Search


Create a
binary
search method called
binarySearch
with the method signature below. This method takes the array of integers and the number we are searching for and should return the
index
of the number in the array or -1 if not found.



public static int
binarySearch
(int a[], int search)



Report



In the comments at the top of your code (see Main.java below), record the time for searching for the following numbers for both linear and binary search: 1, 100, 1000, 10000, 100000, 1000000, 1000001. Is this what was expected? Write a couple sentences about what happened. Be sure to start the clock after you’re done initializing the array. We just want the search times. You can use System.nanoTime() to get the time in nanoseconds. For instance:



long startTime = System.nanoTime();


Your code must be your own code. Do not use Chegg, CourseHero or any other websites like these. If you watch a YouTube video or other online resource and put in their code, that’s not your code.
That is someone else’s code
.




page1image30102816







/*






Record the time for the following search:




Linear Search:

1:





100:

1,000:

10,000:

100,000:

1,000,000:

1,000,001:




Binary Search:

1:





100:

1,000:

10,000:

100,000:

1,000,000:

1,000,001:




Write a couple sentences about what you observed:




*/



class Main {

public static void main(String[] args) {




} }





Feb 15, 2023
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here