We are given a set of M objects in a stack S. In each iteration, an object (say O) is popped out of the stack. With probability $p_1$, O gives rise to 2 new objects which are added to S, thus S now contains $M+1$ objects. With probability $p_2$, O gives to rise to 1 new object and added to S, thus S contains M objects . With probability $1-(p_1 + p_2)$, O does not generate any new object, so S contains $M-1$ objects.
How to compute the expected number of iterations before which the stack becomes empty?
An intuitive approach-: If we denote $z$ to be the change in the number of objects in S at each iteration, then $E[z] = p_1\cdot 1 + p_2 \cdot 0 + (1-p_1-p_2)\cdot -1 = −1+2p_1+p_2$. So the expected number of iterations for stack to become empty is $M/(1-2 p_1 - p_2)$. Further assume, $1-2p_1-p_2 > 0$, to prevent unbounded stack growth.
If the intuitive approach is correct, can someone provide me a hopefully simple but rigorous proof as to why it is correct.
More specifically, I am trying to wrap my head around the idea that without computing a probability distribution of the number of items in S at each iteration, simply computing the expectation of the change in number of items is sufficient.
One wants to compute every $E(T_M)$, where $T_M$ denotes the number of moves necessary to empty a stack of size $M$.
Until the stack becomes empty, its size performs a random walk on the set of nonnegative integers $M$, whose steps from every positive $M$ are $M\to M+1$, $M\to M$ and $M\to M-1$, with respective probabilities $p_1$, $p_2$ and $p_3=1-p_1-p_2$. Thus, if $p_1\geqslant p_3$, every $E(T_M)$ is infinite.
If $p_1<p_3$, that is, if $2p_1+p_2<1$, we first make use of the elementary remark that, to empty a stack of size $M$, one must first reach a stack of size $M-1$, then reach a stack of size $M-2$, and so on until a stack of size $0$. By homogeneity, this shows that $$E(T_M)=ME(T_1)$$ for every positive $M$. On the other hand, starting from size $1$, the usual one-step decomposition yields $$E(T_1)=1+p_1E(T_2)+p_2E(T_1)+p_3\,0$$ thus, $$E(T_1)=\frac1{1-2p_1-p_2}$$ and, finally, for every $M$,