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
Get step-by-step solutions from verified subject matter experts
