Question: The language is java, make sure to complete everything and that the output is correct: Write a program to 1) Declare an int array of

The language is java, make sure to complete everything and that the output is correct:

Write a program to

1) Declare an int array of 5000 elements

2) Randomly assign distinct numbers between 1 and 5000 into the array

3) Randomly pick a target number between 1 and 5000

4) Write a method to use sequential (linear) search to find the target number and return the actual number of comparisons it takes to find the target number

5) In your main method, call the random target number picking and linear search methods 500 times.

Print out:

1) The smallest number of comparisons

2) The largest number of comparisons

3) The average number of comparisons.

Be sure to follow all the directions, complete everything and send the correct code with correct output as asked

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!