Question: We will now measure the performance of binary and linear search. In Java you can measure the current system time using System.nanoTime(). long start=System.nanoTime(); /*put

We will now measure the performance of binary and linear search. In Java you can measure the current system time using System.nanoTime().

long start=System.nanoTime(); /*put code to measure here (i.e., single method call)*/ long stop=System.nanoTime(); long time = stop-start; 

Generate five random integer arrays of sizes 10 too much larger values of N.

 - Sample code to do this for an array size of 10 is: 
 int[] randNumbers1 = new int[10]; for(int i = 0; i < randNumbers1.length; i++) { 

1

randNumbers1[i] = (int)(Math.random()*0+9); } 

Create methods that do both linear and binary search on these arrays and record the time it takes to perform the search for the last number in these arrays (hint. this implies you will have to pass the element array[array.lenghth-1] as the key to the search). Make a table as shown below:

n=4

s=1

t=5

Array Size (N) 
Binary Search Time 
Linear Search Time 

Does this follow your expectations based on the Big-O notation? If not, explain why. What is the value of x (s.t. x>=N) where the performance improvements can clearly be seen between the two search methods. If this value cannot be determined, mention it.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!