Good algorithm for combining items from N lists into one with balanced distribution?

前端 未结 7 977
北荒
北荒 2020-12-05 20:54

Let\'s say I have the three following lists

A1
A2
A3

B1
B2

C1
C2
C3
C4
C5

I\'d like to combine them into a si

7条回答
  •  無奈伤痛
    2020-12-05 21:50

    I'm thinking of a divide and conquer approach. Each iteration of which you split all the lists with elements > 1 in half and recurse. When you get to a point where all the lists except one are of one element you can randomly combine them, pop up a level and randomly combine the lists removed from that frame where the length was one... et cetera.

    Something like the following is what I'm thinking:

    - filter lists into three categories
        - lists of length 1
        - first half of the elements of lists with > 1 elements
        - second half of the elements of lists with > 1 elements
    - recurse on the first and second half of the lists if they have > 1 element
        - combine results of above computation in order
    - randomly combine the list of singletons into returned list 
    

提交回复
热议问题