Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Robb,Carlos Coronel

5th Edition

061906269X, 9780619062699

More Books

Students also viewed these Databases questions

Question

2. How will the team select a leader?

Answered: 1 week ago