129
Bin packing First-fit algorithm

Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Embed Size (px)

Citation preview

Page 1: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Bin packingFirst-fit algorithm

Page 2: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

1 23

6

2 35

3

A B C D E F

4

Each block will be fitted into the first bin that has room for it.Each block will be fitted into the first bin that has room for it.

Bin packingFirst-fit algorithm

Page 3: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

A B C D E F

4

The first block fits into the first bin.The first block fits into the first bin.

1 23

6

2 35

3

Bin packingFirst-fit algorithm

Page 4: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

A B C D E F

4

The second block fits into the first bin.The second block fits into the first bin.

1

23

6

2 35

3

Bin packingFirst-fit algorithm

Page 5: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

A B C D E F

4

The third block will not fit in the first binThe third block will not fit in the first bin

1

23

6

2

35

3

2

But there is room in the second bin.But there is room in the second bin.

Bin packingFirst-fit algorithm

Page 6: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

The third bin is the first one the 5 will fit into.The third bin is the first one the 5 will fit into.

A B C D E F

4

1

2

6

3

5

3

2

3

5

5

Bin packingFirst-fit algorithm

Page 7: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

The second bin has room for the 3.The second bin has room for the 3.

Bin packingFirst-fit algorithm

A B C D E F

4

1

2

6

33

2

35

3

Page 8: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

The fourth bin is the first one with room for the 2.

The fourth bin is the first one with room for the 2.

Bin packingFirst-fit algorithm

A B C D E F

4

1

2

6

33

2

35

2 2

2

Page 9: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

The 3 also fits into the fourth bin.The 3 also fits into the fourth bin.

Bin packingFirst-fit algorithm

A B C D E F

4

1

6

3

2

35

2

3 3 3

3

Page 10: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

No room until the fifth bin for the 6.No room until the fifth bin for the 6.

Bin packingFirst-fit algorithm

A B C D E F

4

1

6

3

2

35

2

3

6 6 6

6

Page 11: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

The 3 has to start a new binThe 3 has to start a new bin

Bin packingFirst-fit algorithm

A B C D E F

4

1

2

35

2

3 6

3 3 3 33

3

Total usage is 6 bins.Total usage is 6 bins.

Page 12: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Bin Packing

Examples

of first-fit algorithm

Page 13: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Example 1Pack the following items

into bins of size 20:11, 7, 3, 4, 3, 5, 1, 8, 9

How many bins are required?

Page 14: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

11, 7, 3, 4, 3, 5, 1, 8, 9 Bin size 20

7 538

39

4 1

Bins

11

Page 15: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

11, 7, 3, 4, 3, 5, 1, 8, 9 Bin size 20

7 538

39

4 1

Bins

11

Page 16: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

11, 7, 3, 4, 3, 5, 1, 8, 9 Bin size 20

7

538

39

4 1

Bins

11

Page 17: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

11, 7, 3, 4, 3, 5, 1, 8, 9 Bin size 20

7

538

3

94 1

Bins

11

Page 18: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

11, 7, 3, 4, 3, 5, 1, 8, 9 Bin size 20

7

538

3

94 1

Bins

11

Page 19: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

11, 7, 3, 4, 3, 5, 1, 8, 9 Bin size 20

7

538

3

9

4

1

Bins

11

Page 20: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

11, 7, 3, 4, 3, 5, 1, 8, 9 Bin size 20

7

5

3

8

3

9

4

1

Bins

11

Page 21: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

11, 7, 3, 4, 3, 5, 1, 8, 9 Bin size 20

7 5

3

8

3

9

4

1

Bins

11

Page 22: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

11, 7, 3, 4, 3, 5, 1, 8, 9 Bin size 20

7 5

3

8

3

9

4

1

Bins

11

Page 23: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

11, 7, 3, 4, 3, 5, 1, 8, 9 Bin size 20

7 5

3

8

3

9

4

1

Bins

11

Page 24: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

11, 7, 3, 4, 3, 5, 1, 8, 9 Bin size 20

7 5

3

83

9

4

1

Bins

11

Page 25: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

11, 7, 3, 4, 3, 5, 1, 8, 9 Bin size 20

7 5

3

83

9

4

1

Bins

11

We need 3 bins.

Page 26: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Example 2Pack the following items into

bins of size 20:5, 8, 12, 4, 11, 17, 7, 9, 7

How many bins are required?

Page 27: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

5, 8, 12, 4, 11, 17, 7, 9, 7Bin size 20

8

1711 912

74 7

Bins

5

Page 28: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

5, 8, 12, 4, 11, 17, 7, 9, 7Bin size 20

8

1711 912

74 7

Bins

5

Page 29: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

5, 8, 12, 4, 11, 17, 7, 9, 7Bin size 20

8

1711 912

74 7

Bins

5

Page 30: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

5, 8, 12, 4, 11, 17, 7, 9, 7Bin size 20

8

1711 9

12

74 7

Bins

5

Page 31: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

5, 8, 12, 4, 11, 17, 7, 9, 7Bin size 20

8

1711 9

12

74 7

Bins

5

Page 32: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

5, 8, 12, 4, 11, 17, 7, 9, 7Bin size 20

8

1711 9

12

7

4

7

Bins

5

Page 33: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

5, 8, 12, 4, 11, 17, 7, 9, 7Bin size 20

8

17

11

9

12

7

4

7

Bins

5

Page 34: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

5, 8, 12, 4, 11, 17, 7, 9, 7Bin size 20

8

17

11

9

12

7

4

7

Bins

5

Page 35: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

5, 8, 12, 4, 11, 17, 7, 9, 7Bin size 20

8

17

11

9

12

7

4

7

Bins

5

Page 36: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

5, 8, 12, 4, 11, 17, 7, 9, 7Bin size 20

8 1711

9

12

7

4

7

Bins

5

Page 37: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

5, 8, 12, 4, 11, 17, 7, 9, 7Bin size 20

8 1711

9

12

7

4 7

Bins

5

Page 38: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

5, 8, 12, 4, 11, 17, 7, 9, 7Bin size 20

8 1711

9

12

7

4 7

Bins

5

Page 39: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

5, 8, 12, 4, 11, 17, 7, 9, 7Bin size 20

8 1711

9

127

4 7

Bins

5

We need 5 bins.

Page 40: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Example 3A wholesale greengrocer is packing the following items into crates

that will carry 24 kg:Item Weight of item (kg) Number of items

required

Carrots 9 1

Apples 6 2

Pears 7 1

Courgettes 3 1

Cauliflowers 14 1

Potatoes 20 1

Oranges 10 1

Leeks 6 1

Bananas 8 1

Tomatoes 5 3

Grapes 2 1

Onions 18 1

How many crates will the greengrocer need?

Page 41: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Crates (24 kg)

Item Weight of item (kg) Number of items required

Carrots 9 1

Apples 6 2

Pears 7 1

Courgettes 3 1

Cauliflowers 14 1

Potatoes 20 1

Oranges 10 1

Leeks 6 1

Bananas 8 1

Tomatoes 5 3

Grapes 2 1

Onions 18 1

Page 42: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Crates (24 kg)9 kg

Item Weight of item (kg) Number of items required

Carrots 9 1

Apples 6 2

Pears 7 1

Courgettes 3 1

Cauliflowers 14 1

Potatoes 20 1

Oranges 10 1

Leeks 6 1

Bananas 8 1

Tomatoes 5 3

Grapes 2 1

Onions 18 1

Page 43: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Crates (24 kg)9 kg, 6 kg

Item Weight of item (kg) Number of items required

Carrots 9 1

Apples 6 2

Pears 7 1

Courgettes 3 1

Cauliflowers 14 1

Potatoes 20 1

Oranges 10 1

Leeks 6 1

Bananas 8 1

Tomatoes 5 3

Grapes 2 1

Onions 18 1

Page 44: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Crates (24 kg)9 kg, 6 kg, 6 kg

Item Weight of item (kg) Number of items required

Carrots 9 1

Apples 6 2

Pears 7 1

Courgettes 3 1

Cauliflowers 14 1

Potatoes 20 1

Oranges 10 1

Leeks 6 1

Bananas 8 1

Tomatoes 5 3

Grapes 2 1

Onions 18 1

Page 45: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Crates (24 kg)9 kg, 6 kg, 6 kg, 7 kg

Item Weight of item (kg) Number of items required

Carrots 9 1

Apples 6 2

Pears 7 1

Courgettes 3 1

Cauliflowers 14 1

Potatoes 20 1

Oranges 10 1

Leeks 6 1

Bananas 8 1

Tomatoes 5 3

Grapes 2 1

Onions 18 1

Page 46: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Crates (24 kg)9 kg, 6 kg, 6 kg

7 kg

Item Weight of item (kg) Number of items required

Carrots 9 1

Apples 6 2

Pears 7 1

Courgettes 3 1

Cauliflowers 14 1

Potatoes 20 1

Oranges 10 1

Leeks 6 1

Bananas 8 1

Tomatoes 5 3

Grapes 2 1

Onions 18 1

Page 47: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Crates (24 kg)9 kg, 6 kg, 6 kg, 3 kg

7 kg

Item Weight of item (kg) Number of items required

Carrots 9 1

Apples 6 2

Pears 7 1

Courgettes 3 1

Cauliflowers 14 1

Potatoes 20 1

Oranges 10 1

Leeks 6 1

Bananas 8 1

Tomatoes 5 3

Grapes 2 1

Onions 18 1

Page 48: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Crates (24 kg)9 kg, 6 kg, 6 kg, 3 kg

7 kg

Item Weight of item (kg) Number of items required

Carrots 9 1

Apples 6 2

Pears 7 1

Courgettes 3 1

Cauliflowers 14 1

Potatoes 20 1

Oranges 10 1

Leeks 6 1

Bananas 8 1

Tomatoes 5 3

Grapes 2 1

Onions 18 1

Page 49: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Crates (24 kg)9 kg, 6 kg, 6 kg, 3 kg

7 kg, 14 kg

Item Weight of item (kg) Number of items required

Carrots 9 1

Apples 6 2

Pears 7 1

Courgettes 3 1

Cauliflowers 14 1

Potatoes 20 1

Oranges 10 1

Leeks 6 1

Bananas 8 1

Tomatoes 5 3

Grapes 2 1

Onions 18 1

Page 50: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Crates (24 kg)9 kg, 6 kg, 6 kg, 3 kg

7 kg, 14 kg, 20 kg

Item Weight of item (kg) Number of items required

Carrots 9 1

Apples 6 2

Pears 7 1

Courgettes 3 1

Cauliflowers 14 1

Potatoes 20 1

Oranges 10 1

Leeks 6 1

Bananas 8 1

Tomatoes 5 3

Grapes 2 1

Onions 18 1

Page 51: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Crates (24 kg)9 kg, 6 kg, 6 kg, 3 kg

7 kg, 14 kg

20 kg

Item Weight of item (kg) Number of items required

Carrots 9 1

Apples 6 2

Pears 7 1

Courgettes 3 1

Cauliflowers 14 1

Potatoes 20 1

Oranges 10 1

Leeks 6 1

Bananas 8 1

Tomatoes 5 3

Grapes 2 1

Onions 18 1

Page 52: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Crates (24 kg)9 kg, 6 kg, 6 kg, 3 kg

7 kg, 14 kg, 10 kg

20 kg

Item Weight of item (kg) Number of items required

Carrots 9 1

Apples 6 2

Pears 7 1

Courgettes 3 1

Cauliflowers 14 1

Potatoes 20 1

Oranges 10 1

Leeks 6 1

Bananas 8 1

Tomatoes 5 3

Grapes 2 1

Onions 18 1

Page 53: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Crates (24 kg)9 kg, 6 kg, 6 kg, 3 kg

7 kg, 14 kg

20 kg, 10 kg

Item Weight of item (kg) Number of items required

Carrots 9 1

Apples 6 2

Pears 7 1

Courgettes 3 1

Cauliflowers 14 1

Potatoes 20 1

Oranges 10 1

Leeks 6 1

Bananas 8 1

Tomatoes 5 3

Grapes 2 1

Onions 18 1

Page 54: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Crates (24 kg)9 kg, 6 kg, 6 kg, 3 kg

7 kg, 14 kg

20 kg

10 kg

Item Weight of item (kg) Number of items required

Carrots 9 1

Apples 6 2

Pears 7 1

Courgettes 3 1

Cauliflowers 14 1

Potatoes 20 1

Oranges 10 1

Leeks 6 1

Bananas 8 1

Tomatoes 5 3

Grapes 2 1

Onions 18 1

Page 55: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Crates (24 kg)9 kg, 6 kg, 6 kg, 3 kg

7 kg, 14 kg, 6 kg

20 kg

10 kg

Item Weight of item (kg) Number of items required

Carrots 9 1

Apples 6 2

Pears 7 1

Courgettes 3 1

Cauliflowers 14 1

Potatoes 20 1

Oranges 10 1

Leeks 6 1

Bananas 8 1

Tomatoes 5 3

Grapes 2 1

Onions 18 1

Page 56: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Crates (24 kg)9 kg, 6 kg, 6 kg, 3 kg

7 kg, 14 kg

20 kg, 6 kg

10 kg

Item Weight of item (kg) Number of items required

Carrots 9 1

Apples 6 2

Pears 7 1

Courgettes 3 1

Cauliflowers 14 1

Potatoes 20 1

Oranges 10 1

Leeks 6 1

Bananas 8 1

Tomatoes 5 3

Grapes 2 1

Onions 18 1

Page 57: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Crates (24 kg)9 kg, 6 kg, 6 kg, 3 kg

7 kg, 14 kg

20 kg

10 kg, 6 kg

Item Weight of item (kg) Number of items required

Carrots 9 1

Apples 6 2

Pears 7 1

Courgettes 3 1

Cauliflowers 14 1

Potatoes 20 1

Oranges 10 1

Leeks 6 1

Bananas 8 1

Tomatoes 5 3

Grapes 2 1

Onions 18 1

Page 58: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Crates (24 kg)9 kg, 6 kg, 6 kg, 3 kg

7 kg, 14 kg, 8 kg

20 kg

10 kg, 6 kg

Item Weight of item (kg) Number of items required

Carrots 9 1

Apples 6 2

Pears 7 1

Courgettes 3 1

Cauliflowers 14 1

Potatoes 20 1

Oranges 10 1

Leeks 6 1

Bananas 8 1

Tomatoes 5 3

Grapes 2 1

Onions 18 1

Page 59: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Crates (24 kg)9 kg, 6 kg, 6 kg, 3 kg

7 kg, 14 kg

20 kg, 8 kg

10 kg, 6 kg

Item Weight of item (kg) Number of items required

Carrots 9 1

Apples 6 2

Pears 7 1

Courgettes 3 1

Cauliflowers 14 1

Potatoes 20 1

Oranges 10 1

Leeks 6 1

Bananas 8 1

Tomatoes 5 3

Grapes 2 1

Onions 18 1

Page 60: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Crates (24 kg)9 kg, 6 kg, 6 kg, 3 kg

7 kg, 14 kg

20 kg

10 kg, 6 kg, 8 kg

Item Weight of item (kg) Number of items required

Carrots 9 1

Apples 6 2

Pears 7 1

Courgettes 3 1

Cauliflowers 14 1

Potatoes 20 1

Oranges 10 1

Leeks 6 1

Bananas 8 1

Tomatoes 5 3

Grapes 2 1

Onions 18 1

Page 61: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Crates (24 kg)9 kg, 6 kg, 6 kg, 3 kg

7 kg, 14 kg

20 kg

10 kg, 6 kg, 8 kg

Item Weight of item (kg) Number of items required

Carrots 9 1

Apples 6 2

Pears 7 1

Courgettes 3 1

Cauliflowers 14 1

Potatoes 20 1

Oranges 10 1

Leeks 6 1

Bananas 8 1

Tomatoes 5 3

Grapes 2 1

Onions 18 1

Page 62: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Crates (24 kg)9 kg, 6 kg, 6 kg, 3 kg

7 kg, 14 kg, 5 kg

20 kg

10 kg, 6 kg, 8 kg

Item Weight of item (kg) Number of items required

Carrots 9 1

Apples 6 2

Pears 7 1

Courgettes 3 1

Cauliflowers 14 1

Potatoes 20 1

Oranges 10 1

Leeks 6 1

Bananas 8 1

Tomatoes 5 3

Grapes 2 1

Onions 18 1

Page 63: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Crates (24 kg)9 kg, 6 kg, 6 kg, 3 kg

7 kg, 14 kg

20 kg, 5 kg

10 kg, 6 kg, 8 kg

Item Weight of item (kg) Number of items required

Carrots 9 1

Apples 6 2

Pears 7 1

Courgettes 3 1

Cauliflowers 14 1

Potatoes 20 1

Oranges 10 1

Leeks 6 1

Bananas 8 1

Tomatoes 5 3

Grapes 2 1

Onions 18 1

Page 64: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Crates (24 kg)9 kg, 6 kg, 6 kg, 3 kg

7 kg, 14 kg

20 kg

10 kg, 6 kg, 8 kg

5 kg

Item Weight of item (kg) Number of items required

Carrots 9 1

Apples 6 2

Pears 7 1

Courgettes 3 1

Cauliflowers 14 1

Potatoes 20 1

Oranges 10 1

Leeks 6 1

Bananas 8 1

Tomatoes 5 3

Grapes 2 1

Onions 18 1

Page 65: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Crates (24 kg)9 kg, 6 kg, 6 kg, 3 kg

7 kg, 14 kg

20 kg

10 kg, 6 kg, 8 kg

5 kg, 5 kg

Item Weight of item (kg) Number of items required

Carrots 9 1

Apples 6 2

Pears 7 1

Courgettes 3 1

Cauliflowers 14 1

Potatoes 20 1

Oranges 10 1

Leeks 6 1

Bananas 8 1

Tomatoes 5 3

Grapes 2 1

Onions 18 1

Page 66: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Crates (24 kg)9 kg, 6 kg, 6 kg, 3 kg

7 kg, 14 kg

20 kg

10 kg, 6 kg, 8 kg

5 kg, 5 kg, 5 kg

Item Weight of item (kg) Number of items required

Carrots 9 1

Apples 6 2

Pears 7 1

Courgettes 3 1

Cauliflowers 14 1

Potatoes 20 1

Oranges 10 1

Leeks 6 1

Bananas 8 1

Tomatoes 5 3

Grapes 2 1

Onions 18 1

Page 67: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Crates (24 kg)9 kg, 6 kg, 6 kg, 3 kg

7 kg, 14 kg, 2 kg

20 kg

10 kg, 6 kg, 8 kg

5 kg, 5 kg, 5 kg

Item Weight of item (kg) Number of items required

Carrots 9 1

Apples 6 2

Pears 7 1

Courgettes 3 1

Cauliflowers 14 1

Potatoes 20 1

Oranges 10 1

Leeks 6 1

Bananas 8 1

Tomatoes 5 3

Grapes 2 1

Onions 18 1

Page 68: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Crates (24 kg)9 kg, 6 kg, 6 kg, 3 kg

7 kg, 14 kg, 2 kg, 18 kg

20 kg

10 kg, 6 kg, 8 kg

5 kg, 5 kg, 5 kg

Item Weight of item (kg) Number of items required

Carrots 9 1

Apples 6 2

Pears 7 1

Courgettes 3 1

Cauliflowers 14 1

Potatoes 20 1

Oranges 10 1

Leeks 6 1

Bananas 8 1

Tomatoes 5 3

Grapes 2 1

Onions 18 1

Page 69: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Crates (24 kg)9 kg, 6 kg, 6 kg, 3 kg

7 kg, 14 kg, 2 kg

20 kg, 18 kg

10 kg, 6 kg, 8 kg

5 kg, 5 kg, 5 kg

Item Weight of item (kg) Number of items required

Carrots 9 1

Apples 6 2

Pears 7 1

Courgettes 3 1

Cauliflowers 14 1

Potatoes 20 1

Oranges 10 1

Leeks 6 1

Bananas 8 1

Tomatoes 5 3

Grapes 2 1

Onions 18 1

Page 70: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Crates (24 kg)9 kg, 6 kg, 6 kg, 3 kg

7 kg, 14 kg, 2 kg

20 kg

10 kg, 6 kg, 8 kg

5 kg, 5 kg, 5 kg, 18 kg

Item Weight of item (kg) Number of items required

Carrots 9 1

Apples 6 2

Pears 7 1

Courgettes 3 1

Cauliflowers 14 1

Potatoes 20 1

Oranges 10 1

Leeks 6 1

Bananas 8 1

Tomatoes 5 3

Grapes 2 1

Onions 18 1

Page 71: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Crates (24 kg)9 kg, 6 kg, 6 kg, 3 kg

7 kg, 14 kg, 2 kg

20 kg

10 kg, 6 kg, 8 kg

5 kg, 5 kg, 5 kg

18 kg

Item Weight of item (kg) Number of items required

Carrots 9 1

Apples 6 2

Pears 7 1

Courgettes 3 1

Cauliflowers 14 1

Potatoes 20 1

Oranges 10 1

Leeks 6 1

Bananas 8 1

Tomatoes 5 3

Grapes 2 1

Onions 18 1

Page 72: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Crates (24 kg)9 kg, 6 kg, 6 kg, 3 kg

7 kg, 14 kg, 2 kg

20 kg

10 kg, 6 kg, 8 kg

5 kg, 5 kg, 5 kg

18 kg

Item Weight of item (kg) Number of items required

Carrots 9 1

Apples 6 2

Pears 7 1

Courgettes 3 1

Cauliflowers 14 1

Potatoes 20 1

Oranges 10 1

Leeks 6 1

Bananas 8 1

Tomatoes 5 3

Grapes 2 1

Onions 18 1

So the greengrocer

needs 6 crates.

Page 73: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Example 4Pack the following items into

bins of size 16: 14, 2, 7, 3, 1, 9, 12, 4, 6

How many bins are required?

Page 74: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

14, 2, 7, 3, 1, 9, 12, 4, 6Bin size 16

2

9

1 47 6

3

12

Bins

14

Page 75: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

14, 2, 7, 3, 1, 9, 12, 4, 6Bin size 16

2

9

1 47 6

3

12

Bins

14

Page 76: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

14, 2, 7, 3, 1, 9, 12, 4, 6Bin size 16

2

9

1 47 6

3

12

Bins

14

Page 77: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

14, 2, 7, 3, 1, 9, 12, 4, 6Bin size 16

2

9

1 4

7

63

12

Bins

14

Page 78: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

14, 2, 7, 3, 1, 9, 12, 4, 6Bin size 16

2

9

1 4

7

63

12

Bins

14

Page 79: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

14, 2, 7, 3, 1, 9, 12, 4, 6Bin size 16

2

9

1 4

7

6

3

12

Bins

14

Page 80: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

14, 2, 7, 3, 1, 9, 12, 4, 6Bin size 16

2

9

1

4

7

6

3

12

Bins

14

Page 81: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

14, 2, 7, 3, 1, 9, 12, 4, 6Bin size 16

29

1

4

7

6

3

12

Bins

14

Page 82: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

14, 2, 7, 3, 1, 9, 12, 4, 6Bin size 16

2

9

1

4

7

6

3

12

Bins

14

Page 83: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

14, 2, 7, 3, 1, 9, 12, 4, 6Bin size 16

2

9

1

4

7

6

3

12

Bins

14

Page 84: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

14, 2, 7, 3, 1, 9, 12, 4, 6Bin size 16

2

9

1

4

7

6

3

12

Bins

14

Page 85: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

14, 2, 7, 3, 1, 9, 12, 4, 6Bin size 16

2

9

1

4

7

6

3

12

Bins

14

Page 86: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

14, 2, 7, 3, 1, 9, 12, 4, 6Bin size 16

2

9

1

4

7

6

3

12

Bins

14

Page 87: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

14, 2, 7, 3, 1, 9, 12, 4, 6Bin size 16

2

9

1

4

7

6

3

12

Bins

14

We need 4 bins.

Page 88: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Example 5A music store is ordering musical instruments. They are packed into boxes

and delivered by a lorry. Each box can hold 20 kg.

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

How many boxes will be needed to deliver all the instruments?

Page 89: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 90: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 91: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 92: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 15 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 93: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg

15 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 94: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg

15 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 95: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 2 kg

15 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 96: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 2 kg, 2 kg

15 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 97: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 2 kg, 2 kg, 2 kg

15 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 98: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 2 kg, 2 kg

15 kg, 2 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 99: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 2 kg, 2 kg

15 kg, 2 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 100: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 2 kg, 2 kg, 7 kg

15 kg, 2 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 101: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 2 kg, 2 kg

15 kg, 2 kg, 7 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 102: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 2 kg, 2 kg

15 kg, 2 kg

7 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 103: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 2 kg, 2 kg

15 kg, 2 kg

7 kg, 7 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 104: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 2 kg, 2 kg

15 kg, 2 kg

7 kg, 7 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 105: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 2 kg, 2 kg, 1 kg

15 kg, 2 kg

7 kg, 7 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 106: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 2 kg, 2 kg, 1 kg

15 kg, 2 kg

7 kg, 7 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 107: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 2 kg, 2 kg, 1 kg

15 kg, 2 kg

7 kg, 7 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 108: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 2 kg, 2 kg, 1 kg

15 kg, 2 kg, 2 kg

7 kg, 7 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 109: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 2 kg, 2 kg, 1 kg

15 kg, 2 kg, 2 kg, 2 kg

7 kg, 7 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 110: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 2 kg, 2 kg, 1 kg

15 kg, 2 kg, 2 kg

7 kg, 7 kg, 2 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 111: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 2 kg, 2 kg, 1 kg

15 kg, 2 kg, 2 kg

7 kg, 7 kg, 2 kg, 2 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 112: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 2 kg, 2 kg, 1 kg

15 kg, 2 kg, 2 kg

7 kg, 7 kg, 2 kg, 2 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 113: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 2 kg, 2 kg, 1 kg

15 kg, 2 kg, 2 kg, 1 kg

7 kg, 7 kg, 2 kg, 2 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 114: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 2 kg, 2 kg, 1 kg

15 kg, 2 kg, 2 kg, 1 kg

7 kg, 7 kg, 2 kg, 2 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 115: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 2 kg, 2 kg, 1 kg

15 kg, 2 kg, 2 kg, 1 kg

7 kg, 7 kg, 2 kg, 2 kg,1 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 116: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 2 kg, 2 kg, 1 kg

15 kg, 2 kg, 2 kg, 1 kg

7 kg, 7 kg, 2 kg, 2 kg,1 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 117: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 2 kg, 2 kg, 1 kg

15 kg, 2 kg, 2 kg, 1 kg

7 kg, 7 kg, 2 kg, 2 kg,1 kg, 4 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 118: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 2 kg, 2 kg, 1 kg

15 kg, 2 kg, 2 kg, 1 kg

7 kg, 7 kg, 2 kg, 2 kg,1 kg

4 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 119: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 2 kg, 2 kg, 1 kg

15 kg, 2 kg, 2 kg, 1 kg

7 kg, 7 kg, 2 kg, 2 kg,1 kg

4 kg, 4 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 120: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 2 kg, 2 kg, 1 kg

15 kg, 2 kg, 2 kg, 1 kg

7 kg, 7 kg, 2 kg, 2 kg,1 kg

4 kg, 4 kg, 4 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 121: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 2 kg, 2 kg, 1 kg

15 kg, 2 kg, 2 kg, 1 kg

7 kg, 7 kg, 2 kg, 2 kg,1 kg

4 kg, 4 kg, 4 kg, 4 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 122: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 2 kg, 2 kg, 1 kg

15 kg, 2 kg, 2 kg, 1 kg

7 kg, 7 kg, 2 kg, 2 kg,1 kg

4 kg, 4 kg, 4 kg, 4 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 123: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 2 kg, 2 kg, 1 kg

15 kg, 2 kg, 2 kg, 1 kg

7 kg, 7 kg, 2 kg, 2 kg,1 kg, 18 kg

4 kg, 4 kg, 4 kg, 4 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 124: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 2 kg, 2 kg, 1 kg

15 kg, 2 kg, 2 kg, 1 kg

7 kg, 7 kg, 2 kg, 2 kg,1 kg

4 kg, 4 kg, 4 kg, 4 kg,18 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 125: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 2 kg, 2 kg, 1 kg

15 kg, 2 kg, 2 kg, 1 kg

7 kg, 7 kg, 2 kg, 2 kg,1 kg

4 kg, 4 kg, 4 kg, 4 kg

18 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 126: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 2 kg, 2 kg, 1 kg

15 kg, 2 kg, 2 kg, 1 kg

7 kg, 7 kg, 2 kg, 2 kg,1 kg, 1 kg

4 kg, 4 kg, 4 kg, 4 kg

18 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 127: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 2 kg, 2 kg, 1 kg

15 kg, 2 kg, 2 kg, 1 kg

7 kg, 7 kg, 2 kg, 2 kg,1 kg, 1 kg

4 kg, 4 kg, 4 kg, 4 kg

18 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 128: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 2 kg, 2 kg, 1 kg

15 kg, 2 kg, 2 kg, 1 kg

7 kg, 7 kg, 2 kg, 2 kg,1 kg, 1 kg

4 kg, 4 kg, 4 kg, 4 kg,1 kg

18 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

Page 129: Bin packing First-fit algorithm. 1 2 3 6 2 3 5 3 A B C D E F 4 Each block will be fitted into the first bin that has room for it. Bin packing First-fit

Boxes (20 kg)15 kg, 2 kg, 2 kg, 1 kg

15 kg, 2 kg, 2 kg, 1 kg

7 kg, 7 kg, 2 kg, 2 kg,1 kg, 1 kg

4 kg, 4 kg, 4 kg, 4 kg,1 kg

18 kg

Instrument Weight of instrument (kg)

Number of each instrument ordered

Guitars 15 2

Trumpets 2 3

Saxophones 7 2

Violins 1 1

Trombones 2 3

Flutes 1 2

Bassoons 4 4

Tubas 18 1

Cymbals 1 2

5 boxes are

needed.