Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started