All of the following arguments are based around the recursive formula that comes from conditioning on the first step:
m(i,j)=1+(1−p)⋅m(i−1,j)+p⋅m(i+1,j)
Suppose i>j:
Let's simplify notation by recognizing that shifting i and j equally has no effect:
m(i,j)≡m^(i−j)
If p≥.5, then the expectation is infinite. (This will follow from our solution to the p<.5 case.)
If p<.5, then:
m^(k)=1+(1−p)⋅m^(k−1)+p⋅m^(k+1)
⇒m^(k)−m^(k−1)=1+p⋅(m^(k+1)−m^(k−1))
We can guess and verify that
m^(k)=βk is linear.
⇒βk−β(k−1)=1+p(β(k+1)−β(k−1))
⇒β=1+2pβ
⇒β=11−2p
Note that
β does not depend on
k, so we guessed correctly. Our equation is satisfied for any
k by:
⇒m^(k)=k1−2p
In particular, we can see for
k=1:
m^(1)=1+(1−p)⋅m^(0)+p⋅m^(2)=1+2p1−2p=11−2p
Note that our expression for m^(k) has the correct boundary values: when p=0 it deterministically takes k steps, and the expression gets arbitrarily large as p goes to .5 from the left. In fact, this proves the expectation is infinite for the p≥.5 case since m^ is monotonically increasing in p.
Suppose i<j:
For any fixed j, there are finitely many states to consider and an equal number of equations.
m(0,j)=1+(1−p)⋅m(0,j)+p⋅m(1,j)
⇒p⋅m(0,j)=1+p⋅m(1,j)
⇒m(0,j)=1/p+m(1,j)
Now let's compute the next one:
m(1,j)=1+(1−p)⋅m(0,j)+p⋅m(2,j)
⇒p⋅m(1,j)=1+(1−p)/p+p⋅m(2,j)
⇒m(1,j)=(1+(1−p)/p)/p+m(2,j)
There is a pattern:
m(i,j)=Ai+m(i+1,j)
Where:
Ai=(1+(1−p)Ai−1)/p
A0=1/p
Thus:
Ai=∑k=0i(1−p)kpk+1
Recursing forward until j−1, we get:
m(j−1,j)=Aj−1+m(j,j)
⇒m(j−1,j)=Aj−1
Now, we can recurse backwards:
m(i,j)=∑n=ij−1An
⇒m(i,j)=∑n=ij−1∑k=0n(1−p)kpk+1
This can be simplified further by noticing
An is the sum of a finite geometric series. There are three cases to consider depending on the value of
r=(1−p)/p.
If (1−p)/p=1, then p=.5 and An=2(n+1), thus:
m(i,j)=∑n=ij−12(n+1)=j(j+1)−i(i+1)
If (1−p)/p<1, then p>.5 and An is a finite geometric series with r=(1−p)/p, thus:
An=1p(1−1−pp)−1(1−(1−pp)n+1)=(2p−1)−1(1−(1−pp)n+1)
Their summation is then:
m(i,j)=∑n=ij−1(2p−1)−1(1−(1−pp)n+1)=(2p−1)−1((j−i)−∑n=ij−1(1−pp)n+1)=(2p−1)−1((j−i)−p(2p−1)−1((1−pp)i+1−(1−pp)j+1))
If (1−p)/p>1, then p<.5 and An is a finite geometric series.
We can do exactly as in the previous case but by reversing the finite geometric series and using r=p/(1−p).
(I'll write this up at some point, but it's not mathematically harder than the previous case, just a bit messier notationally.)