Suppose you have a number of boxes, each of which can hold total weight C anditems i1 | StudySoup

Textbook Solutions for Data Structures and Algorithm Analysis in Java

Chapter 6 Problem 6.37

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

Step 1 of 4)

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.

Step 2 of 7)

Visible to paid subscribers only

Step 3 of 7)

Visible to paid subscribers only

Subscribe to view the
full solution

Title Data Structures and Algorithm Analysis in Java 3 
Author Mark A. Weiss
ISBN 9780132576277

Suppose you have a number of boxes, each of which can hold total weight C anditems i1

Chapter 6 textbook questions

×

Login

Organize all study tools for free

Or continue with
×

Register

Sign up for access to all content on our site!

Or continue with

Or login if you already have an account

×

Reset password

If you have an active account we’ll send you an e-mail for password recovery

Or login if you have your password back