Question: 4. (20 points) We are given an array A with n elements and a number D. Assume that the sum of the elements in A
4. (20 points) We are given an array A with n elements and a number D. Assume that the sum of the elements in A is larger than D. We would like to compute the size of the smallest subset of A whose elements sum to at least D. (For example, if A = 18,3, 9.2.7,1,5) and D = 18 then the answer is 3; the set is {7.8.9.) Give a linear-time algorithm for this problem. (Any superlinear-time algorithm will receive no credit. HINT: use the linear-time SELECT algo- rithm.)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
