Question: Please help. I need to alter the code to output the best case, worse case and the average. The value of key should be okay

Please help. I need to alter the code to output the best case, worse case and the average. The value of key should be okay to generate randomly and the range should be able to be chosen. thank you  Please help. I need to alter the code to output the
best case, worse case and the average. The value of key should

public class LinearSearch B /** The method for finding a key in the list */ public static int linearsearch(int [] list, int key) \{ for ( int 1=0;10.5?1;1)); System.out.print(list [1] + ","); long begin, end, time; Il we will measure time it took to search begin = Systen, nanotime(); // / we measure in nanoseconds. 1/starting the watch System, out.println (linearSearch(list, KEY)); end = Systein. nanotime(); time = end-begin; System,out, println("1t took " + time + " nanoseconds to run linear search with the key " + KEY + " on the array of " +N+ " elements. "); J We will add a small trick to get the best case: as the Key is known in advance, we will assign the first element to it. Technically we do not need to populate our array, just creating it (and population with zeros) is enough Modify the code as stated above. Keep running your simulations in analogous manner as in 1.3. for best case. Take a screenshot of your code and single output and insert your results in the same table. 1.5. Proving with practice: Average case It should be fine to generate the value of KEY randomly. You can choose its range yourself. Modify the code as stated above. Keep running your simulations in analogous manner as in 1.3. for the Average case. Take a screenshot of your code and single output and insert your results in the same table

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!