0% found this document useful (0 votes)
19 views2 pages

As Binpacking

The document outlines a bin packing problem where items of varying weights must be placed into bins with a capacity of 10 pounds. It describes five algorithms for packing the items: First Fit, First Fit Increasing, First Fit Decreasing, Best Fit, and Worst Fit, and provides sample input and output for testing these algorithms. The goal is to minimize wasted capacity in the bins while adhering to the specified packing methods.

Uploaded by

CK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views2 pages

As Binpacking

The document outlines a bin packing problem where items of varying weights must be placed into bins with a capacity of 10 pounds. It describes five algorithms for packing the items: First Fit, First Fit Increasing, First Fit Decreasing, Best Fit, and Worst Fit, and provides sample input and output for testing these algorithms. The goal is to minimize wasted capacity in the bins while adhering to the specified packing methods.

Uploaded by

CK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

ACSL

ALL-STAR American Computer Science League Program #5


Bin Packing

PROBLEM: You have a set of "bins". Each bin has a capacity of 10 pounds. You are
given items weighing from 1 to 10 pounds each. The goal is to place the items in the bins
such that each bin is packed as close to capacity as possible. For example, if you have
items weighing 4, 3, 7, and 6, you could fit them into 2 bins: 4 + 6 in bin #1, and 3 + 7 in
bin #2. There would be no wasted capacity, as both bins are filled to capacity. However,
if you place 4 +3 in bin #1, you'd need to place 7 and 6 in separate bins, thereby, using 3
bins. There would be 3+3+4=10 pounds of extra capacity. Given 5 algorithms for placing
items in bins, determine the weight of each bin that needs to be used.

1. First Fit – Starting with bin #1, place the items, in the order given, in the first bin in
which they fit.

2. First Fit Increasing – Sort the items from lightest to heaviest. Then place the items,
starting with the lightest and bin #1, in the first bin in which they fit.

3. First Fit Decreasing – Sort the items from heaviest to lightest. Then place the items,
starting with the heaviest and bin #1, in the first bin in which they fit.

4. Best Fit – Starting with bin #1 and using the items in the order given put the items in
the first bin that will come closest to maximizing the load of that bin.

5. Worst Fit – Starting with bin #1 and using the items in the order given put the items
in the lightest non-empty bin in which they fit. Empty bins are used only when no other
bins are available.

INPUT: There will be two input lines. Each line will have a list of item weights. The
list will end with a weight of zero.

OUTPUT: There are 10 outputs. For each line of input print in order, starting with bin
#1, the weight of each non-zero bin used for each of the algorithms. The output lines will
be in the order of the algorithms above unless labeled otherwise.

SAMPLE INPUT SAMPLE OUTPUT

1. 1, 3, 5, 3, 6, 2, 1, 2, 4, 6, 3, 7, 0 1. 10, 9, 8, 9, 7
2. 9, 10, 5, 6, 6, 7
3. 10, 10, 10, 10, 3
4. 10, 9, 8, 9, 7
5. 9, 9, 9, 9, 7
ACSL
ALL-STAR American Computer Science League Program #5
Bin Packing

TEST DATA

TEST INPUT

1. 2, 9, 4, 7, 1, 3, 2, 6, 8, 1, 4, 2, 5, 3, 4, 0
2. 1, 4, 2, 8, 2, 1, 6, 3, 4, 5, 2, 2, 7, 3, 1, 5, 2, 0

TEST OUTPUT

1. 10, 10, 9, 10, 10, 8, 4


2. 8, 10, 8, 5, 6, 7, 8, 9
3. 10, 10, 10, 10, 10, 9, 2
4. 9, 10, 10, 10, 10, 8, 4
5. 10, 9, 9, 7, 8, 10, 8
6. 10, 10, 10, 9, 9, 10
7. 9, 10, 8, 10, 6, 7, 8
8. 10, 10, 10, 10, 10, 8
9. 10, 10, 10, 9, 9, 10
10. 9, 9, 9, 9, 8, 7, 7

You might also like