I have a list of 100,000 objects. Every list element has a \"weight\" associated with it that is a positive int from 1 to N.
What is the most efficient way to select
A solution that runs in O(n) would be to start out with selecting the first element. Then for each following element either keep the element you have or replace it with the next one. Let w be the sum of all weights for elements considered so far. Then keep the old one with probability w/(w+x) and choose the new one with p=x/(w+x), where x is the weight of the next element.