Question: 4.(20 points)LetA[1n] be an (unsorted) array of n elements. We assume that no two elements of A are equal. We are also given another numberM.

4.(20 points)LetA[1n] be an (unsorted) array of n elements. We assume that no two elements of A are equal. We are also given another numberM. The problem is to find the largest element x in A such that the sum of the elements of A less than x is at mostM(i.e.,aA,a

Design anO(n) time algorithm for the problem.Hint:Use the prune-and-search technique.Note:You must describe the main idea of your algorithm (you may also give the pseudocode instead if it clearly explains the main idea) and analyze the time complexity

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!