Expected number of weighings to get heaviest rock

262 Views Asked by At

You are given ten rocks and you would like to find the heaviest one. With each weighing you randomly select two of the rocks and determine which of the rocks is heavier. What is the expected number of weighing you need in order to tell which rock is the heaviest?

One can see by inspection that for $n=2$ the answer is $1$, and for $n=3$ the answer satisfies

$E_3=1+\frac 23 \cdot 2 +\frac 13 \cdot \frac 23 \cdot 3+\frac 13 \cdot \frac 13 \cdot \frac 23 \cdot 4 + \dots$

which one can compute comes to $\frac 72$.

I dont see how this approach is scalable though.

EDIT: The question seems to imply that you can repeat a pair of rocks. Indeed in my computation for $E_3$ I assumed you could (otherwise the answer would just be $2$). Also, yes, assume we can say $A>B$ at each step (i.e. no equality. Also I'm not sure that would change the problem, given that we know one rock is the heaviest and we only need to find that one)

1

There are 1 best solutions below

1
On

Here's a more general question:

Partition a set $X$ of $N$ elements into disjoint non-empty subsets $X_1, X_2,\dots, X_m$ with $|X_i|=n_i$. Pick randomly from $X$ uniformly, with replacement. Let $T$ be the number of pairs picked when you've found at lest one element from each $X_i$. What is the expected value of $T$?

In your question, if we have $n$ rocks, $X$ is the set of all $\frac{n(n-1)}{2}$ pairs of rocks, and $m=n-1$, with $X_i$ the set of all pairings containing $i$ and a heavier rock (so $n_i=n-1-i$.)

Basically, in order to be sure that you know the largest, you have to have shown that each other rock is smaller than some rock.

[If you know one rock is absolutely heaviest, the possibility that two rocks can be equal definitely still changes the question, since picking $i,j$ with rocks $i,j$ of the same weight eliminates both rocks from contention.

But you'd have to know something about the probability of equal-weighted rocks to answer that question, so it is likely you want all the weights different.]

I think you are going to need an inclusion-exclusion argument above - if $p_k$ is the odds that at choice $k$ you have not found a set of representatives, then $p_k$ is an inclusion-exclusion count based on which $X_i$ you have picked a representative out of.

In the general question, letting $A_i$ be the number of ways after $k$ choices that we haven't found an element of $X_i$. For each non-empty $S\subseteq \{1,...,m\}$ let $A_{S}=\cap_{i\in S} A_i$. Then we have:

$$\left|\bigcup_i A_i\right|=\sum_{S\neq\emptyset} (-1)^{||S|-1}|A_S|$$

And we have that $|A_S|=(N-\sum_{i\in S}n_i)^k$.

So the probability $p_k$ that we have not finished at step $k$ is:

$$p_k=\frac{1}{N^k}\left|\bigcup_i A_i\right| =\sum_{S}(-1)^{|S|-1}\left(\frac{N-\sum_{i\in S} n_i}{N}\right)^k=\sum_{S}(-1)^{|S|-1}(1-p_S)^k$$

where $p_S=\frac{\sum_{i\in S} n_i}{N}$.

But the expected value of $T$ is just $1+\sum_{k=1}^{\infty}p_k$. Swapping sums, we get:

$$\begin{align}E(T)&=1+\sum_{S} (-1)^{|S|-1}\sum_{k=1}^{\infty} (1-p_S)^k\\ &=1+\sum_{S} (-1)^{|S|-1}\frac{1-p_S}{p_S}\\ &=1+\sum_{S} (-1)^{|S|-1}\frac{N}{\sum_{i\in S} n_i} + \sum_{S} (-1)^{|S|}\\ &= \sum_{S} (-1)^{|S|-1}\frac{N}{\sum_{i\in S} n_i} \end{align}$$

That's going to be a frightening sum, unfortunately.

In your case, $S=\{1,\dots,n-1\}$ for $n$ rocks, and $n_i=i, N=\frac{n(n-1)}{2}$.

For three rocks this gives $3(1+1/2-1/(1+2)) = \frac{7}{2}$. For four rocks, this value is:

$$6\left(1+\frac{1}{2}+\frac{1}{3}-\frac{1}{1+2}-\frac{1}{1+3}-\frac{1}{2+3} + \frac{1}{1+2+3}\right)=\frac{73}{10}$$


Amusingly, there is a generating function approach to this value that gives an integral.

Define $q_n(x)=\frac{1-(1-x)(1-x^2)\cdots(1-x^{n-1})}{x}$, which is a polynomial, then $$\int_{0}^{1} q_n(x)\,dx = \sum_{S} \frac{(-1)^{|S|-1}}{\sum_{i\in S} i}$$

Understanding $q_n$ might give us a good approximation for $E(T)$.

As it turns out, $q_n(x)$ is monotonic increasing sequence of functions on $[0,1]$, and:

$$\prod_{i=1}^{\infty}(1-x^i) = \sum_{k=1}^{\infty} (-1)^k \left(x^{k(3k-1)/2}+x^{k(3k+1)/2}\right)$$

So $$\begin{align} \int_{0}^1 q_n(x)\,dx &\to \sum_{k=1}^{\infty}(-1)^{k-1}\left(\frac{2}{(3k-1)k} + \frac{2}{(3k+1)k}\right)\\ &=\sum_{k} (-1)^{k-1}\frac{12}{9k^2-1} \end{align}$$

Wolfram Alpha gives this sum as:

$$\frac{4\pi}{\sqrt{3}}-6\approx 1.2552$$

This means that $E(T)$ for $n$ large is going to be asymptotic to $\left(\frac{4\pi}{\sqrt{3}}-6\right)\frac{n(n-1)}{2}$.

Note that even in the case of $n=4$, the ratio is $\frac{73}{60}\approx 1.21667$, and the ratio increases with $n$, an never exceeds $\approx 1.2552$.

For $n=10$, then, the value will be close to $45\cdot 1.2552\approx 56.5$.

A little Ruby scripting yields the exact value for $n=10$:

$$\frac{439114299698079671}{7779931002283440}\approx 56.44192725734945$$