Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions