fairly Select set elements base on element count

57 Views Asked by At

Please consider this scenario: For example we have 4 sets that each one has some elements.

Case 1) in each case there are 10 elements and we want to select 4 elements from sets.It's obvious that we should select one element from each sets.

Case 2)in each case there are 10 elements and we want to select 5 elements from sets.It's obvious that we should select one element from each sets and in random one remaining element from on set.

Now consider this element's count vary in sets. for example in set 1 we have 10000 element, set 2 have 2000 element, set 3 has 5000 element and set 4 has 10 element and we want to select 5 elements. For example we should select 3 elements from set 1, 1 from set 2 and one from set 3 and 0 from set 1.

Is there Mathematical concept that help me calculate this selection distribution? In simple case we can use Proportionality but in complex case (For example) reach to number 3 for a set with 10000 elements can not derive from Proportionality.

How I can select elements proportional to elements count in sets.

1

There are 1 best solutions below

0
On BEST ANSWER

This method should do the trick for most cases:

Add the total number of elements in all the sets. Call this number $k$.

Then the number of elements you should take from a set of size $m$ is $\frac{m}{k}\times r$. Where $r$ is the number of elements you have to take in total. Of course this number may not be an integer. So round it.

Do this for each set. Notice that it is possible you get more or less elements than $r$ in total. To fix this add $1$ or substract $1$ to the sets that where altered the most when rounded