A Comparison Of Two Methods For Random Labelling of Balls by Vectors of Integers

Doron ZEILBERGER^{1}

Greg Kirk[Ki] raised the question of comparing the following two ways for labelling balls. Given r pre-determined positive integers n_{i}, (1 ≤ i ≤ r), and given N balls (N large), consider two ways to randomly assign r− component vectors of integers (a_{1}, …, a_{r}) to them, such that 1 ≤ a_{i} ≤ n_{i}. We will call these vectors ‘labels’. Of course altogether there are ∏_{i=1}^{r} n_{i} possible labels.

First Way: You put all the balls in one big pot. For i = 1, …, r, at the i^{th} iteration, line up n_{i} smaller pots, each with capacity N/n_{i} balls, and labeled with labels 1 through n_{i}, and, uniformly at random, distribute them into these smaller pots. Assign the i^{th} component of the vector-label of each ball, a_{i}, to be the label of the pot in which it was dropped. Having done that, you dump all the balls back into the big pot, and go on to the next iteration.

Second Way: Do the same as above for i = 1, except that at the end of the first iteration you do not dump back the balls into the large ball but proceed as follows. For i = 2, …, r, assuming that the balls have already received their first i − 1 components, leaving the balls in their pots from the (i − 1)^{th} iteration, you line-up n_{i} new pots, each with a capacity of N/n_{i} balls, and labeled with labels 1 through n_{i}. For each of the n_{i−1} pots from the previous iteration, individually, we uniformly at random, distribute their contents into the new pots, each of the n_{i} new pots getting exactly N/(n_{i−1}n_{i}) balls from each of the n_{i−1} pots from the previous, (i − 1)^{th} iteration.

Note that in the First Way, assuming that we can reuse the pots, we need 1 + max(n_{1}, …, n_{r}) pots, one of which should have a capacity of N balls, while in the Second Way, we need max(1 + n_{1}, n_{1} + n_{2}, …, n_{r−1} + n_{r}) pots.

The goal is to maximize the ‘equal representation’ of all the possible ∏_{i=1}^{r} n_{i} vector-labels. It is obvious, with either way, that the probability of a ball to be assigned any given label is ∏_{i=1}^{r} n_{i}^{−1}, and hence that the expected number of balls to be given label v, for each of v ∈ ∏_{i=1}^{r}[1, n_{i}], is N ∏_{i=1}^{r} n_{i}^{−1}.

It is intuitively obvious that in the Second Way the ‘spread’ in the distribution is less than in the First Way. In fact, when r = 2, the Second Way gives a perfect way of equi-distribution. We are guaranteed that the number of balls given any particular label (a_{1}, a_{2}) is exactly N/(n_{1}n_{2}).

Throughout this note we assume that N is divisible by lcm(n_{1}n_{2}, n_{2}n_{3}, …, n_{r−1}n_{r}). For any statement P, χ(P) is 1 or 0 according to whether P is true or false, respectively.

The way to quantify ‘spread’ is via standard deviation, or its square, the variance. By symmetry it is enough to pick any one fixed label, v, say v = (1, …, 1).

1 Department of Mathematics, Temple University, Philadelphia, PA 19122, USA. zeilberg@math.temple.edu . Sup-

ported in part by the NSF. Version of Dec 19, 1994.

The ‘random variable’ on a given ‘experiment’ is the ‘number of balls labeled v’. To compute its variance, we will use an old trick, described beautifully in section 8.2 of the modern classic [GKP]. This trick can also be used to find the average (i.e. first moment), in which case it is even easier to use, and higher moments, in which case it is (usually) harder to use.

Let S denote the set of all possible outcomes of the ‘labelling experiment’. The total number of outcomes, in the First Way is

|S| = ∏_{i=1}^{r} \frac{N!}{(N/n_{i})!^{n_{i}}} .

For each outcome s, let α(s) be the quantity ‘number of balls that receive the (fixed) label v’.

Let’s first compute the average of this quantity (even though we know the answer, just as a warm-up for the calculation of the variance, that would follow). We have

∑_{s∈S} α(s) = ∑_{s∈S} ∑_{j=1}^{N} χ(the j^{th} ball is labelled v)

= ∑_{j=1}^{N} ∑_{s∈S_{j}} 1,  (Greg)

where the inner sum extends over the set of outcomes, let’s call it S_{j}, of s ∈ S for which the j^{th} ball was labelled v. By symmetry, this inner sum is independent of j, and equals

∏_{i=1}^{r} \frac{(N − 1)!}{((N/n_{i}) − 1)!(N/n_{i})!^{n_{i}−1}} ,

since at each iteration one of the balls (the j^{th}) is committed to lend in one of the pots (Pot v_{i} in the i^{th} iteration.)

Hence the sum in (Greg) equals:

N ∏_{i=1}^{r} \frac{(N − 1)!}{((N/n_{i}) − 1)!(N/n_{i})!^{n_{i}−1}} ,

and hence the average is:

av = N ∏_{i=1}^{r} \frac{\frac{(N−1)!}{((N/n_{i})−1)!(N/n_{i})!^{n_{i}−1}}}{\frac{(N)!}{(N/n_{i})!^{n_{i}}}} =

N ∏_{i=1}^{r} \frac{1}{n_{i}} ,

as expected (sic!). Variance and Standard Deviation Let’s recall a few elementary facts about variance. The standard deviation is defined to be the square root of the variance. Suppose that we have a finite set S, and there is some numerical attribute (random variable) X(s) for every element s ∈ S. Then the variance, V (X), is the ‘average of the squares of the ‘deviation from the average”, i.e.

V (X) = \frac{∑_{s∈S}(X(s) − av)^{2}}{|S|} ,

where |S| is the number of elements of S. It is easier to compute the related quantity:

W (X) = \frac{∑s∈S \binom{X(s)}{2}}{|S|} .

Simple algebra shows that:

V (X) = 2W (X) + av − av^{2} .

Now we are ready to compute W (α).

W (α) = \frac{1}{|S|} ∑_{s∈S} \binom{α(s)}{2} = \frac{1}{|S|} ∑_{s∈S} ∑_{1≤i<j≤N} χ( the i^{th} and the j^{th} balls are both labelled v)

= \frac{1}{|S|} ∑_{1≤i<j≤N} [ Number of outcomes with the i^{th} and j^{th} balls both labelled v]  (Kirk)

By symmetry, the summand is independent of (i, j) and is easily seen to be equal to

∏_{i=1}^{r} \frac{(N − 2)!}{((N/n_{i}) − 2)!(N/n_{i})!^{n_{i}−1}}

since, at each of the r iterations, two balls are committed to lend at a predetermined pot (the v_{i}^{th} pot at the i^{th} iteration.)

Simple algebra yields

W (α) = \binom{N}{2} ∏_{i=1}^{r} n_{i}^{−2} \frac{(1 − n_{i}/N)}{(1 − 1/N)} .

It follows that

V (α) = av − av^{2} + 2W (α) = \frac{N}{∏_{i=1}^{r} n_{i}} − \frac{N^{2}}{∏_{i=1}^{r} n_{i}^{2}} + N(N − 1) ∏_{i=1}^{r} n_{i}^{−2} \frac{(1 − n_{i}/N)}{(1 − 1/N)} .

Assuming that N is large, so that 1/N is small, and using the approximation 1/(1 − x) = 1 + x + O(x^{2}), we get the following proposition.

Proposition 1: The average number of occurrences of any given vector v as a label, in the First Way, is N/ ∏_{i=1}^{r} n_{i}, and its variance is:

\frac{N}{∏_{i=1}^{r} n_{i}} − \frac{N}{∏_{i=1}^{r} n_{i}^{2}} (1 + ∑_{i=1}^{r}(n_{i} − 1)) + O(1) .

Analysis of the Second Way

Here the total number of outcomes is

|S| = \frac{N!}{(N/n_{1})!^{n_{1}}} ∏_{i=2}^{r} [\frac{(N/(n_{i−1})!}{(N/(n_{i−1}n_{i}))!^{n_{i}}} ]^{n_{i−1}} .

Using an analogous argument as before, the number of outcomes with the i^{th} and j^{th} balls labelled v equals

\frac{(N − 2)!}{((N/n_{1}) − 2)!(N/n_{1})!^{n_{1}−1}} ∏_{i=2}^{r} \frac{((N/n_{i−1}) − 2)!}{((N/n_{i−1}n_{i}) − 2)!(N/(n_{i−1}n_{i}))!^{n_{i}−1}} [\frac{(N/n_{i−1})!}{(N/(n_{i−1}n_{i}))!^{n_{i}}} ]^{n_{i−1}−1} .

Simple algebra yields that

W (α) = \binom{N}{2} ∏_{i=1}^{r} n_{i}^{−2} · \frac{(1 − n_{1}/N)}{(1 − 1/N)} · ∏_{i=2}^{r} \frac{(1 − n_{i−1}n_{i}/N)}{(1 − n_{i−1}/N)} ,

which, as before leads to the following proposition. Proposition 2: The average number of occurrences of any given vector v, as a label, in the Second Way, is N/ ∏_{i=1}^{r} n_{i}, and its variance is:

\frac{N}{∏_{i=1}^{r} n_{i}} − \frac{N}{∏_{i=1}^{r} n_{i}^{2}} (n_{1} + ∑_{i=2}^{r}(n_{i} − 1)n_{i−1}) + O(1) ,

which is slightly smaller. References

[GKP] R. L. Graham, D. E. Knuth, and O. Patashnik, “Concrete Mathematics”, second edition, Addison Wesley, 1993.

[Ki] G. Kirk, private communication, (in ‘Jeff’s Bagels Coffee Bar’, Rocky Hill, NJ, Nov. 1993).