Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started