Can both insert and findMin be implemented in constant time?
Read moreTextbook Solutions for Data Structures and Algorithm Analysis in Java
Question
Suppose you have a number of boxes, each of which can hold total weight C anditems i1, i2, i3, ... , iN, which weigh w1, w2, w3, ... , wN, respectively. The object isto pack all the items without placing more weight in any box than its capacity andusing as few boxes as possible. For instance, if C = 5, and the items have weights2, 2, 3, 3, then we can solve the problem with two boxes.In general, this problem is very hard, and no efficient solution is known. Writeprograms to implement efficiently the following approximation strategies:a. Place the weight in the first box for which it fits (creating a new box if there isno box with enough room). (This strategy and all that follow would give threeboxes, which is suboptimal.)b. Place the weight in the box with the most room for it.c. Place the weight in the most filled box that can accept it without overflowing.d. Are any of these strategies enhanced by presorting the items by weight?
Solution
The first step in solving 6 problem number 37 trying to solve the problem we have to refer to the textbook question: Suppose you have a number of boxes, each of which can hold total weight C anditems i1, i2, i3, ... , iN, which weigh w1, w2, w3, ... , wN, respectively. The object isto pack all the items without placing more weight in any box than its capacity andusing as few boxes as possible. For instance, if C = 5, and the items have weights2, 2, 3, 3, then we can solve the problem with two boxes.In general, this problem is very hard, and no efficient solution is known. Writeprograms to implement efficiently the following approximation strategies:a. Place the weight in the first box for which it fits (creating a new box if there isno box with enough room). (This strategy and all that follow would give threeboxes, which is suboptimal.)b. Place the weight in the box with the most room for it.c. Place the weight in the most filled box that can accept it without overflowing.d. Are any of these strategies enhanced by presorting the items by weight?
From the textbook chapter Priority Queues (Heaps) you will find a few key concepts needed to solve this.
Visible to paid subscribers only
Step 3 of 7)Visible to paid subscribers only
full solution