Question: An array A with n numbers and a number p. Assume that the sum of the elements in A is larger than p. We would

An array A with n numbers and a number p. Assume that the sum of the elements in A is larger than p. We would like to compute a subset A' of A such that (i) the sum of the elements in A' is at least p and (ii) satisfying (i), the number of elements in A' is as small as possible. Give an O(n) time algorithm for this problem. (HINT: use the linear-time SELECT algorithm) (For example, if A = {8, 3, 9, 2, 7, 1, 5} and p = 18, then the answer is A' = {8, 9, 1}.)

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!