Question: Let A be an array of n distinct integers. Consider an algorithm to find the minimum value, where we pair up the elements, and retain

 Let A be an array of n distinct integers. Consider an

Let A be an array of n distinct integers. Consider an algorithm to find the minimum value, where we pair up the elements, and retain the smaller of the values from each pair. This will result in an array of half the size (actually the resulting size will be n/2. We can then recursively apply the same approach, until we get a final array with just two elements. We compare these two values and return the minimum of those values as the answer. Answer the following questions: a. How many comparisons are done in the above algorithm in the worst case. b. Show how to modifylextend this method to find the second smallest element. c. Prove that we can find the second smallest element in n+log(n)2 comparisons in the worst case Note that the above questions are not asking for the big-Oh complexity, but rather the (exact) number of comparisons in the worst case. For example, it is easy to find the 2 nd smallest element in at most 2n comparisons, but that is n+n which is larger than n+log(n)2 comparisons

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!