Assignment On: Course Title: Design and Analysis of Algorithms Course Code: CSE 3203
Assignment On: Course Title: Design and Analysis of Algorithms Course Code: CSE 3203
ID: 1505001
Introduction
The fundamental aim of bin packing is to pack a collection of objects into well defined regions
called bins, so that they do not overlap. Packing algorithms sound intimidating and for good
reason. In popular culture, we associate algorithms with complex, advanced technology. In
reality, an algorithm is just a means of solving problems really quickly. In the world of supply
chain management, packing algorithms help warehouse managers address what’s known as the
bin packing problem— the issue of packing multiple items of various sizes into a finite number
of bins (in this case, shipping boxes).
Given n items with sizes S1,S2,…..Sn such that 0 ≤ Si ≤ 1 for 1 ≤ i ≤ n, pack them into the
fewest number of unit capacity bins.
The bin packing problem consists of packing items of varying sizes into a finite number of bins
of fixed capacity. The objective is to minimize the number of bins used to pack all the items.
Approximation algorithms allow for getting a solution close to the optimal solution of an
optimization problem in polynomial time. For given problem instance I, Approximation Ratio is
the ratio of algo(I) and opt(I).
There are many variations of the problem. Items may be packed by weight or price. Items may
be fragmented and packed separately for a certain cost. When packed together, items may
occupy less space such as the case in VM (virtual machine) packing. The most common
variations of the bin packing problem are:
Knapsack
1-Dimensional Bin Packing
Cutting Stock Problem
Variable Size Bin Packing Problem (VSBPP)
2-Dimensional Bin Packing Problem
Example: Items - 0.5, 0.3, 0.4, 0.8, 0.2, 0.2, 0.2 and bin capacity 1
0.2
0.3 0.2
0.2
0.5
0.4 0.8
The benefit of this method is that you don’t need a lot of dedicated warehouse space. The minute
additional items cannot fit into the bin, it’s shipped off to the end customer.
Example: Items – 0.4, 0.7, 0.1, 0.3, 0.8, 0.2, 0.5 and bin capacity 1
0.3
0.2
0.1 0.5
0.7
0.4
Example: Items – 0.4, 0.7, 0.1, 0.3, 0.8, 0.2, 0.5 and bin capacity 1
0.3
0.2
0.8 0.5
0.1
0.7
0.4
Example: Items – 0.2, 0.5, 0.4, 0.1, 0.3, 0.8 and bin capacity 1
0.3
0.1 0.8
0.5 0.4 0.7
0.2
https://onlinejudge.org/external/11/1149.pdf
This is the problem link of uva bin packing problem. In this problem there are several items with
different weight is given. We need to find out the minimum number of bin are require to pack
them in it. So the solution is given below.
Problem Solution
#include<bits/stdc++.h>
int main()
int t;
cin>>t;
while(t--)
int n;
cin>>n;
int x;
cin>>x;
int arr[100000+5];
for(int i=0;i<n;i++)
cin>>arr[i];
sort(arr,arr+n);
int l=0,r=n-1;
int ans=0;
while(l<=r)
if(arr[l]+arr[r]<=x)
l++;
r--;
else r--;
ans++;
cout<<ans<<endl;
if(t)cout<<endl;
return 0;
Sample Output: