Need some help with an algorithm, math heavy. Not homework. :P

Page 2 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.

br0wn

Senior member
Jun 22, 2000
572
0
0
ZaneNBK: opps never mind, I did wrong analysis. Your method is faster
than mine.

My method takes O(n log n) because of sorting (just once though) in the beginning.
However, you can do O(n) sorting is you can spend extra memory.
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
Originally posted by: ZaneNBK
Ameesh, your algorithm doesn't work if some of the buckets have quantities WAY over the total average (average of buckets + quantity to allocate added in before dividing).

ergeorge, that method is the direct method but is too slow unfortunately.

Not sure why it would be slow
You only need to sort it once, and then maintain it in sorted order.