Question: Question 3. [12 marks in total a. (4 marks) Provide sample inputs for both best and worst case time com- plexities for the following search

 Question 3. [12 marks in total a. (4 marks) Provide sample

Question 3. [12 marks in total a. (4 marks) Provide sample inputs for both best and worst case time com- plexities for the following search method public static int mySearch (int [] arr, int target) int result -1 for(int i-arr.length-1; i>-0; i--) t if (arr [i]target) 1 resulti return result; You answer must be of the form: Best case time complexity: O) when arr-, target - . Worst case time complexity: O when arr -[), target - b. (4 marks) Re-write the method from task a. so that its best case time complexity improves (it takes less time in the best case scenario) c. (4 marks) (Advanced) Determine the minimum number of searches (k) that must be performed on an array to justify sorting it once (using merge sort) before performing k binary searches rather than performing k linear searches over an unsorted arrav. Worst case time complexities of relevant algorithms . Linear Search: O(n) Binary Search: O(log-n) . Merge Sort: O(nlogzn)

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!