The algorithm of the need to group files of different sizes into approximately equal blocks

I'm trying to find an algorithm that will help me group various files of different sizes into groups of "n" about the same size.

Any ideas on how to achieve this?

+3
source share
3 answers
Find the target group size. This is the sum of all sizes divided by n.
Create a list of sizes.
Sort the files decreasing in size. 
for each group
    while the remaining space in your group is bigger than the first element of the list
        take the first element of the list and move it to the group
    for each element
        find the elemnet for which the difference between group size and target group size is minimal
    move this elemnt to the group

This does not give optimal results, but it is easy to implement and get good results. For an optimal solution, you need an exhaustive search that is NP complete.

+6
source

K , . , , 1-, k- .

+2

, , n, . bin, .

Netlib fortran code, ( , / ).

+1

Source: https://habr.com/ru/post/1715054/


All Articles