I think that I am trying to solve a problem somewhat similar to a knapsack problem. I am not sure though.
Please see the input given below and my solution. There are three types of items and 4 buckets. The problem is to keep the items as uniformly as possible in the 4 buckets. i.e. the capacity of the buckets (or number of items in the bucket) should be equal (or close to equal). You can also keep the items from different types in the same bucket.
item-type : A B C #items : 12 36 25
One simple solution I am using currently is as follows:
Since there are 4 buckets, each bucket should get
(sum of items)/4. For the above example input data, it is
(12 + 36 + 25)/4, i.e. approximately 18 items. The capacity of each of the bucket should be "CLOSE" to 18.
Then start keeping the items of type A into the first bucket until the number of items become 18. However, still we need 6 more items for the first bucket as the number of type A items are 12. Therefore keep 6 items of the type B into the first bucket so that the capacity of the first bucket will be 18. Like this fill the other three buckets also.
Finally the four buckets are as follows:
Bucket-1: (12 A items, 6 B items) Bucket-2: (18 B items) Bucket-3: (12 B items, 6 C items) Bucket-4: (19 C items).
I think that the time complexity of this problem is O(N^2), N is the number of buckets.
It would be great if someone helps me to improve the solution further.
Note-1: We can mix items of different types in the same bucket.
Note-2: We also need to somehow keep the information of type of the item in the bucket.