algorithm - Distribute list elements between two lists equitatively -
algorithm - Distribute list elements between two lists equitatively -
i have list 'n' elements (lets 10 ie), want distribute elements 2 lists, each 1 balanced other criteria, evaluating valour of each element. ie output should 2 lists 5 elements aproximately balanced each other.
thanks time.
you employ greedy strategy (i'm not give "optimal" results, should give relatively results @ least).
start finding total value of elements in list, v. goal create 2 lists each value half amount (ideally close 1/2*v possible). start 3 lists, list_original, list_1, list_2.
pull off items list_original (starting largest, working way downwards smallest) , set them list_1 if , if adding them list_1 doesn't cause total value of list_1 exceed 1/2*v. else goes list_2.
the result list_1 @ 1/2*v , list_2 @ to the lowest degree 1/2*v. in event subset of items sums 1/2*v might equality. haven't tried prove/disprove yet. depending on how close balanced result has be, plenty (it should @ to the lowest degree fast).
algorithm list statistics distribution backtracking
Comments
Post a Comment