algorithmbest-fit

best fit algorithm


I was asked to make an algorithm to do the best fit for some music in the minimum number of folders .

The folders has a fixed size ( like the folders can only hold 100 minutes of music ).

for example : i have music with these lengths ( 50 - 30 -20 - 20 -80 - 70 -15 - 15) and the folder size is 100 mins .

The result should be 3 folders .

I don't even know how the algorithm works . any ideas ?!


Solution

  • It looks like bin packing problem which is NP-hard Problem.So you have to try every possible combination until the sum of a certain combination exceeds the target number, you can stop calculating that branch and move on to the next branch.

    Now you can optimize your result and count the minimum number of combinations whose sum is 100 or any target number and that minimum will give you the Number of folders needed for storing the data.I hope it helps.