Question: Consider the following problem tSum(A, T) Input: An array A with n numbers. All the numbers in the array are positive and distinct (no duplicates).

Consider the following problem tSum(A, T)

Input: An array A with n numbers. All the numbers in the array are positive and distinct (no duplicates). The input array is also not sorted. Positive number T.

Output: the smallest positive integer k such that the largest k elements of A sum to at least T.

For example, if A = 6, 20, 10, 1, 7, 13, 5 then tSum(A,45) = 4 since the four largest numbers in A are 7, 10, 13, 20 and 7 + 10 + 13 + 20 = 50 > 45. But if you had just taken the three largest numbers you would have 10 + 13 + 20 = 43 < 45. So you need the four largest numbers, which is why tSum(A,45) = 4.

Write pseudocode for a recursive algorithm that solves the above problem. You can only use heaps, priority queues, and dictionaries (Don't have to use all of them).

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!