Some complex expectations

Revision en2, by _Bishop_, 2021-07-04 13:59:20

Here is an interesting problem from the Newton School's June coding competition

Problem: There are $$$x$$$ apples and $$$y$$$ oranges. In one move you can pick an apple or an orange equiprobably and convert it to the other. What is the expected number of moves required to make the count of one of them zero? Constraints $$$0 \leq x, y \leq 10^9$$$

Intended solution: Let $$$E(x , y)$$$ be the expected number of moves with $$$x$$$ apples and $$$y$$$ oranges in the beginning. Quite obviously (or maybe not), we pick apples and oranges with probability $$$\frac{1}{2}$$$ and then we have the following transitions: $$$E(x , y) = 1 + \frac{E(x + 1, y - 1) + E(x - 1, y + 1)}{2}$$$. And also $$$E(x, 0) = E(0 , y) = 0$$$. And probably with a little guess work we can obtain $$$E(x , y) = xy$$$.

A different way: Somehow I interpreted the problem in a different way and landed in a difficult position. I went about thinking that we draw the fruits equiprobably so the probability that we pick up a fruit is $$$\frac{1}{x + y}$$$. This makes the probability that we draw an apple to be $$$\frac{x}{x + y}$$$ and that we draw an orange to be $$$\frac{y}{x + y}$$$. This took me to the following recurrence: $$$E(x , y) = 1 + \frac{x}{x + y}E(x - 1, y + 1) + \frac{y}{x + y}E(x + 1, y - 1)$$$ and that $$$E(x , 0) = E(0 , y) = 0$$$. Now, I want to know if this recurrence has any closed form solution. Are there methods to compute such recursive functions. Maybe some math-person knows how to solve it. Also, how does one even approach this problem with smaller constraints (I mean with $$$dp$$$ we run into cycles)?

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English _Bishop_ 2021-07-04 13:59:20 8
en1 English _Bishop_ 2021-07-01 20:45:59 1617 Initial revision (published)