# Probability of number of groups of continuous same object when ordering two types of objects

(Apology for the title, I struggled to find a better way to describe the question in a single sentence.)

Let there be $$m$$ identical black balls $$\Huge\bullet$$, $$n$$ identical white balls; consider randomly ordering them. For example, with $$m = 6, n = 4$$: $$\overbrace{\Huge\bullet\Huge\bullet\Huge\bullet}\;\underbrace{\Huge\circ\;\,\Huge\circ}\;\Huge\bullet\Huge\circ\Huge\circ\Huge\bullet\Huge\bullet$$

And let $$r$$ be the number of groups of continuous black balls (over braced), and $$s$$ be the number of groups of continuous white balls (underbraced). So in the example, $$r = 3, s = 2$$.

What is the probability of $$\mathrm{P}(r, s)$$ with some given $$r, s$$? what about $$\mathrm{P}(r)$$ given some $$r$$?

My thoughts:

So the probability $$\mathrm{P}(r, s)$$ should be

• If $$r = s$$, the ordering may start with either black or white, and end with another, so $$2 \times f(m, n, r, s)$$

• If $$| r - s | = 1$$, it must start and end with the color of more groups, so $$f(m, n, r, s)$$.

• If $$| r - s| > 1$$, it is impossible, so its $$0$$.

Where $$f(m, n, r, s) = \frac{\small\text{ways to divide } m \text{ balls into } r \text{ distinct groups of one or more balls} \;\times\; \text{ways to divide } n \text{ balls into } s \text{ groups of one or more balls}}{\text{all ways to order two types of balls}} \\ = \displaystyle\frac{\displaystyle\binom{m - 1}{r - 1}\binom{n - 1}{s - 1}}{\displaystyle\binom{m + n}{m}}$$

And for $$\mathrm{P}(r)$$, since for any $$r$$, $$s$$ can only be one of $$r + 1, r, r - 1$$ to have probability, I simply substituted $$s$$ with them, summed it up and got the result: $$\frac{(n - 1)!\,(m - 1)!\,m!\,n!}{(m + n)!\,(m - r)!\,(r - 1)!\,} \left[ {2 \over (n - r)!\,(r - 1)!} + {1 \over (n - r + 1)!\,(r - 2)!} + {1 \over (n - r - 1)!\,r!}\right] \\[1ex] = \frac{(n - 1)!\,(m - 1)!\,m!\,n!}{(m + n)!\,(m - r)!\,(r - 1)!} \left[ n^2 + n \over (n - r + 1)!\,r! \right]$$

But these are both extremely bulky, and very complicated, so I wonder is there a better approach to solving this problem, better with a result not requiring conditions? Or did I do something terribly wrong?

• You can't casually invoke Stars and Bars like this, as the various outcomes are not generally equi-probable.
– lulu
Aug 3, 2022 at 11:14
• I would start by working it out recursively (might help to distinguish those strings that begin with $b$ from those that begin with $w$). If nothing else, that will make it easy to reliably compute a whole lot of examples.
– lulu
Aug 3, 2022 at 11:15
• As a quicker way to see that your formula can not be correct, let $m$ be large and $n=1$. Then of course $s=1$ but $r$ can only be $1$ or $2$, depending on where the single white ball is placed. Your formula gives a non-zero value for any $r$ from $1$ to $m$.
– lulu
Aug 3, 2022 at 11:55