D1 Algorithms - Bin Packing
D1 Algorithms - Bin Packing
com
1. 41 28 42 31 36 32 29
The numbers in the list represent the weights, in kilograms, of seven statues. They are to be
transported in crates that will each hold a maximum weight of 60 kilograms.
(a) Calculate a lower bound for the number of crates that will be needed to transport the
statues.
(2)
(b) Use the first-fit bin packing algorithm to allocate the statues to the crates.
(3)
(c) Use the full bin algorithm to allocate the statues to the crates.
(2)
(d) Explain why it is not possible to transport the statues using fewer crates than the number
needed for part (c).
(2)
(Total 9 marks)
2. 32 45 17 23 38 28 16 9 12 10
The numbers in the list above represent the lengths, in metres, of ten lengths of fabric. They are
to be cut from rolls of fabric of length 60m.
(b) Use the first-fit bin packing algorithm to determine how these ten lengths can be cut from
rolls of length 60m.
(4)
(c) Use full bins to find an optimal solution that uses the minimum number of rolls.
(3)
(Total 9 marks)
3. 29 52 73 87 74 47 38 61 41
The numbers in the list represent the lengths in minutes of nine radio programmes. They are to
be recorded onto tapes which each store up to 100 minutes of programmes.
(a) Obtain a lower bound for the number of tapes needed to store the nine programmes.
(2)
(b) Use the first-fit bin packing algorithm to fit the programmes onto the tapes.
(3)
(c) Use the first-fit decreasing bin packing algorithm to fit the programmes onto the tapes.
(3)
(Total 8 marks)
4. 650 431 245 643 455 134 710 234 162 452
(a) The list of numbers above is to be sorted into descending order. Perform a Quick Sort to
obtain the sorted list, giving the state of the list after each pass, indicating the pivot
elements.
(5)
The numbers in the list represent the lengths, in mm, of some pieces of wood. The wood is sold
in one metre lengths.
(b) Use the first-fit decreasing bin packing algorithm to determine how these pieces could be
cut from the minimum number of one metre lengths. (You should ignore wastage due to
cutting.)
(4)
(c) Determine whether your solution to part (b) is optimal. Give a reason for your answer.
(2)
(Total 11 marks)
5. Nine pieces of wood are required to build a small cabinet. The lengths, in cm, of the pieces of
wood are listed below.
(a) The first fit decreasing algorithm is used to determine how many of these planks are to be
purchased to make this cabinet. Find the total cost and the amount of wood wasted.
(5)
Planks of wood can also be bought in 1.5 m lengths, at a cost of £4 each. The cabinet can be
built using a mixture of 1 m and 1.5 m planks.
(b) Find the minimum cost of making this cabinet. Justify your answer.
(4)
(Total 9 marks)
6. 25 22 30 18 29 21 27 21
(a) (i) Perform the first pass of a bubble sort, giving the state of the list after each
exchange.
(ii) Perform further passes, giving the state of the list after each pass, until the
algorithm terminates.
(5)
The numbers represent the lengths, in cm, of pieces to be cut from rods of length 50 cm.
(b) (i) Show the result of applying the first fit decreasing bin packing algorithm to this
situation.
(ii) Determine whether your solution to (b) (i) has used the minimum number of 50 cm
rods.
(4)
(Total 9 marks)
239
1. (a) e.g. total weight is 239, lower bound is = 3.98 so 4 bins. M1 A1 2
60
Note
1M1: Any correct statement, must involve calculation
1A1: cao (accept 4 for both marks)
(d) There are 5 items over 30. No two of these 5 can be paired B2, 1, 0 2
in a bin, so at least 5 bins will be required.
Note
1B1: Correct argument may be imprecise or muddled (bod gets B1)
2B1: A good, clear, correct argument. (They have answered
the question ‘why?’)
[9]
230
2. (a) = 3.83 so 4 needed M1 A1 2
60
Note
1M1: Their 230 divided by 60, some evidence
of correct method 3.8 enough.
1A1: cso 4.
(b) Bin 1: 32 17 9 M1 A1
Bin 2: 45 12 A1
Bin 3: 23 28 A1 4
Bin 4: 38 16
Bin 5: 10
Note
1M1: Use of first fit. Probably 32, 45 and
17 correctly placed.
1A1: 32, 45, 17, 23, 38 and 28 placed correctly
2A1: 32, 45, 17, 23, 38, 28, 16, 9 placed correctly.
3A1: cao
Special case for (b) misread using first fit decreasing.
Give M1A1 (max)
Bin 1: 45 12
Bin 2: 38 17
Bin 3: 32 28
Bin 4: 23 16 10 9
M1 for placing 45, 38, 32, 28 and 23 correctly
A1 for cao.
502
3. (a) = 5.02 so 6 tapes. Ml
100
Al 2
1M1 (502 ±40) ÷ 100 (maybe implicit)
1A1: cao 6 tapes
(b) Bin 1 710 + 245 Bin 3 643 + 162 + 134 Bin 5 431 M1 A1
Bin 2 650 + 234 Bin 4 455 + 452 A1ft A1 4
(c) eg.
4116
= 4.116 ∴ 5 bins needed ∴ optimal M1 A1ft 2
1000
[11]
1. This was a good source of marks for well-prepared candidates with over 75% gaining at least 7
marks, though the final part challenged all but the most able.
Part (a) was almost always completed correctly.
Part (b) was often well done, although some used first fit decreasing and 29 was sometimes
either omitted from the list or changed to 39.
Most candidates were able to complete part (c) correctly but a few only listed one full bin.
In part (d) many incorrectly stated that the full bin solution was optimal, others made some
vague reference to the statues being too heavy, relatively few attempted a valid numerically
based answer and managed to express it clearly.
2. This was often a good source of marks for candidates. Most were able to calculate the lower
bound getting 3.8 and therefore 4 bins. Most candidates applied first fit correctly, although some
candidates did not offer each item to each bin in turn, starting with bin 1 each time, so often the
9 was the first item to be misplaced. Some candidates wasted time by replacing each letter by a
number, or explaining in lengthy detail the steps they took to place each item. Not all candidates
realised that they should fill as many bins as possible when using full bin, most found one full
bin, but only the best found two.
3. This proved an accessible first question and was well answered by many candidates. Some
candidates probably spent too long on this question, drawing out very neat and accurate bar
graphs in (b) and (c), where numbers in bins were perfectly acceptable. Most candidates
calculated the lower bound correctly in part (a) although some attempted a full bin solution and
others divided by 9, some having calculated 5.02 rounded down to 5. Apart from the usual
omissions of data, part (b) was usually well answered, the most common slips being to swap the
38 and the 41, or to use the 52 to start off the second bin. First–Fit increasing was
disappointingly often seen in part (c), but those who used the correct algorithm were usually
successful with the only common error being misplacing the 38.
4. Some very good answers were seen to part (a), but many candidates produced disappointing
attempts. Poor presentation and lack of concentration accounted for most errors in part (a); there
was inconsistent choice of pivots, numbers that disappeared from the list, numbers that mutated
into other numbers and, of course, numbers being reordered in the list. A large minority sorted
the list into ascending order. A number of candidates are only selecting one pivot per pass,
which rather defeats the object of a quick sort. Only a very few Bubble sorts were seen.
Candidate would help themselves hugely by not fixing the position of the pivots until the line
after they are selected, this would avoid the need to try to cram numbers into the ever-
decreasing space formed by their previously chosen pivots. Candidates could then use the whole
width of the line each time. Part (b) was usually well done. Some used the first fit algorithm and
many put 134 into bin 5 rather than bin 3. Part (c) was often well attempted with the majority of
candidates giving a clear, arithmetical argument.
5. Many candidates scored full marks in part (a); however some candidates used the values in
ascending order scoring zero. There was no need to use a formal sort to put the list in order.
Many candidates gave the cost of the wasted wood rather than the cost of the five planks. In part
(b) many candidates found an optimal solution, but many then went on to consider just the
amount of wood wasted, rather than showing that the cost depended upon the value for money
of each plank and therefore maximising the number of 1.5m lengths used.
6. Most candidates were able to complete the bubble sort correctly, although a number of shuttle
sorts were seen from a few candidates. A number of candidates did not complete a final pass,
(or stated that they had performed a final pass and found no further exchanges). The majority
were able to complete the bin packing but a number were unable to show that they had used a
minimum number of bins, once again the lower bound would have helped here.