Greedy algorithm for variation of bin packing

68 Views Asked by At

Consider the bin packing problem where an input array of weights have to be packed in the minimum number of bins possible. Consider the two following restrictions. First, for any bin, a heavier weight cannot be stored after a lighter weight. Second, for any bin, the order in which the weights appear in the input array have to be respected in the bin. For example, $w_i$ cannot be stored after $w_j$ if $i<j$. There is no restriction on the maximum value of a weight or capacity of the bin. I want to design a greedy algorithm for this problem and prove it is no worse than any optimal solution.

My algorithm process one weight at a time and check the bins that are not empty and store it in the first available non-empty bin. If no non-empty bin is available then it stores it in a new empty bin. For example, with the input $[60, 40, 46, 18, 26]$ the output would be two bins: $[60, 40, 18]$ and $[46, 26]$. How can I prove that the number of bins of my algorithm is not greater than the output of any optimal algorithm?