You have N dollars and you have a list of k items L1, ..., Lk that you wish to purchase from an online store. If you purchase an item, then the online store gives you some reward points. For an item Li , 1<= i <= k,  the price and reward values are Pi and Ri, respectively. Both Pi and Ri are integers. Unfortunately, there is a threshold T on the total reward you can earn. In other words, if the sum of reward values for the items you purchase is more than T, then any reward point beyond T will be wasted. Write an efficient algorithm (to the best of your knowledge) to find a list of items within N dollars such that purchasing them will maximize the sum of reward values but will keep the sum within the threshold T (Note: the sum can be equal to T).  Briefly describe why it is a correct algorithm, provide pseudocode, and analyze the time complexity. Example: Input: N = 10,  k = 3, T = 100, P = [4,6,5], R = [40,70,50] Output: L1, L3.  Here is an explanation. Note that you have the following choices: {L1} where price 4 and reward 40. {L2} where price 6 and reward 70. {L3} where price 5 and reward 50. {L1,L2} where price 10 and reward sum 110 (exceeding T). {L1,L3} where price 9 and reward 90. {L2,L3} where price 11 (exceeding N) and reward 120 (exceeding T).  Thus the best option that maximizes the reward sum is L1, L3.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

You have N dollars and you have a list of k items L1, ..., Lk that you wish to purchase from an online store. If you purchase an item, then the online store gives you some reward points. For an item Li , 1<= i <= k,  the price and reward values are Pand Ri, respectively. Both Pand Ri are integers. Unfortunately, there is a threshold T on the total reward you can earn. In other words, if the sum of reward values for the items you purchase is more than T, then any reward point beyond T will be wasted. Write an efficient algorithm (to the best of your knowledge) to find a list of items within N dollars such that purchasing them will maximize the sum of reward values but will keep the sum within the threshold T (Note: the sum can be equal to T).  Briefly describe why it is a correct algorithm, provide pseudocode, and analyze the time complexity.

Example: Input: N = 10,  k = 3, T = 100, P = [4,6,5], R = [40,70,50]

Output: L1, L3. 

Here is an explanation. Note that you have the following choices:

{L1} where price 4 and reward 40. {L2} where price 6 and reward 70. {L3} where price 5 and reward 50. {L1,L2} where price 10 and reward sum 110 (exceeding T). {L1,L3} where price 9 and reward 90. {L2,L3} where price 11 (exceeding N) and reward 120 (exceeding T). 

Thus the best option that maximizes the reward sum is L1, L3.

 

Expert Solution
steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education