A Practical Guide to Quantitative Finance Interviews
Contents
105

Chapter 5
Stochastic Process and Stochastic Calculus

In this chapter, we cover a few topics—Markov chain, random walk and martingale, dynamic programming—that are often not included in introductory probability courses. Unlike basic probability theory, these tools may not be considered to be standard requirements for quantitative researchers/analysts. But a good understanding of these topics can simplify your answers to many interview problems and give you an edge in the interview process. Besides, once you learn the basics, you’ll find many interview problems turning into fun-to-solve math puzzles.

5.1 Markov Chain

A Markov chain is a sequence of random variables X0,X1,⋯ ,Xn,⋯X_0,X_1,\cdots,X_n,\cdots with the Markov property that given the present state, the future states and the past states are independent:

P{Xn+1=j∣Xn=i,Xn−1=in−1,⋯ ,X0=i0}=pij=P{Xn+1=j∣Xn=i}P\{X_{n+1}=j\mid X_n=i,X_{n-1}=i_{n-1},\cdots,X_0=i_0\}=p_{ij}=P\{X_{n+1}=j\mid X_n=i\}

for all n,i0,⋯ ,in−1,i,n,i_0,\cdots,i_{n-1},i, and jj, where i,j∈{1,2,⋯ ,M}i,j\in\{1,2,\cdots,M\} represent the state space S={s1,s2,⋯ ,sM}S=\{s_1,s_2,\cdots,s_M\} of XX.

In other words, once the current state is known, past history has no bearing on the future. For a homogenous Markov chain, the transition probability from state ii to state jj does not depend on nn.1 A Markov chain with MM states can be completely described by an M×MM\times M transition matrix PP and the initial probabilities P(X0)P(X_0).

Transition matrix:

P={pij}=[p11p12⋯p1Mp21p22⋯p2M⋮⋮⋮⋮pM1pM2⋯pMM],P=\{p_{ij}\}=\begin{bmatrix}p_{11}&p_{12}&\cdots&p_{1M}\\p_{21}&p_{22}&\cdots&p_{2M}\\\vdots&\vdots&\vdots&\vdots\\p_{M1}&p_{M2}&\cdots&p_{MM}\end{bmatrix},

where pijp_{ij} is the transition probability from state ii to state jj.

Initial probabilities: P(X0)=(P(X0=1),P(X0=2),⋯ ,P(X0=M)), ∑i=1MP(X0=i)=1\displaystyle P(X_0)=(P(X_0=1),P(X_0=2),\cdots,P(X_0=M)),\ \sum_{i=1}^{M}P(X_0=i)=1.

The probability of a path: P(X1=i1,X2=i2⋯ ,Xn=in∣X0=i0)=pi0i1pi1i2⋯pin−1inP(X_1=i_1,X_2=i_2\cdots,X_n=i_n\mid X_0=i_0)=p_{i_0i_1}p_{i_1i_2}\cdots p_{i_{n-1}i_n}

Transition graph: A transition graph is often used to express the transition matrix graphically. The transition graph is more intuitive than the matrix, and it emphasizes 106 possible and impossible transitions. Figure 5.1 shows the transition graph and the transition matrix of a Markov chain with four states:

Four-state transition graph:1 to2 and4 each0.5;2 to1 at0.5 and3/4 each0.25;3 to2 and itself each0.4 and4 at0.2;4 absorbing ⟺i=1,2,3,4j=P=[00.500.50.500.250.2500.40.40.20001]1234\Longleftrightarrow\quad\begin{array}{rcc}&i=1,2,3,4&j=\\P=&\begin{bmatrix}0&0.5&0&0.5\\0.5&0&0.25&0.25\\0&0.4&0.4&0.2\\0&0&0&1\end{bmatrix}&\begin{array}{c}1\\2\\3\\4\end{array}\end{array}
Figure 5.1 Transition graph and transition matrix of the Play

Classification of states

State jj is accessible from state ii if there is a directed path in the transition graph from ii to jj (∃n\exists n such that Pij(n)>0P_{ij}^{(n)}>0). Let Tij=min⁡(n:Xn=j∣X0=i)T_{ij}=\min(n:X_n=j\mid X_0=i), then P(Tij<∞)>0P(T_{ij}<\infty)>0) if and only if state jj is accessible from state ii. States ii and jj communicate if ii is accessible from jj and jj is accessible from ii. In Figure 5.1, state 3 and 1 communicate. State 4 is accessible form state 1, but they do not communicate since state 1 is not accessible from state 4.

We say that state ii is recurrent if for every state jj that is accessible from ii, ii is also accessible from jj (∀j, P(Tij<∞)>0⇒P(Tij<∞)=1\forall j,\ P(T_{ij}<\infty)>0\Rightarrow P(T_{ij}<\infty)=1). A state is called transient if it is not recurrent (∃j, P(Tij<∞)>0\exists j,\ P(T_{ij}<\infty)>0 and P(Tij<∞)<1P(T_{ij}<\infty)<1). In Figure 5.1, only state 4 is recurrent. States 1, 2 and 3 are all transient since 4 is accessible from 1/2/3, but 1/2/3 are not accessible from 4.

Absorbing Markov chains: A state ii is called absorbing if it is impossible to leave this state (pii=1,pij=0,∀j≠ip_{ii}=1,p_{ij}=0,\forall j\ne i). A Markov chain is absorbing if it has at least one absorbing state and if from every state it is possible to go to an absorbing state. In Figure 5.1, state 4 is an absorbing state. The corresponding Markov chain is an absorbing Markov chain.

Equations for absorption probability: The probability to reach a specific absorbing state ss, a1,⋯ ,aMa_1,\cdots,a_M, are unique solutions to equations as=1a_s=1, ai=0a_i=0 for all absorbing state(s) i≠si\ne s, and ai=∑j=1Majpij\displaystyle a_i=\sum_{j=1}^{M}a_jp_{ij} for all transient states ii. These equations can be easily 107 derived using the law of total probability by conditioning the absorption probabilities on the next state.

Equations for the expected time to absorption: The expected times to absorption, μ1,⋯ ,μM\mu_1,\cdots,\mu_M, are unique solutions to the equations μi=0\mu_i=0 for all absorbing state(s) ii and μi=1+∑j=1mpijμj\displaystyle\mu_i=1+\sum_{j=1}^{m}p_{ij}\mu_j for all transient states ii. These equations can be easily derived using the law of total expectation by conditioning the expected times to absorption on the next state. The number 1 is added since it takes one step to reach the next state.

Gambler’s ruin problem

Player MM has $1 and player NN has $2. Each game gives the winner $1 from the other. As a better player, MM wins 2/32/3 of the games. They play until one of them is bankrupt. What is the probability that MM wins?

Solution: The most difficult part of Markov chain problems often lies in how to choose the right state space and define the transition probabilities PijP_{ij}’s, ∀i,j\forall i,j. This problem has fairly straightforward states. You can define the state space as the combination of the money that player MM has ($mm) and the money that player NN has ($nn): {(m,n)}={(3,0),(2,1),(1,2),(0,3)}\{(m,n)\}=\{(3,0),(2,1),(1,2),(0,3)\}. (Neither mm nor nn can be negative since the whole game stops when one of them goes bankrupt.) Since the sum of the dollars of both players is always $3, we can actually simplify the state space using only mm: {m}={0,1,2,3}\{m\}=\{0,1,2,3\}.

The transition graph and the corresponding transition matrix are shown in Figure 5.2.

Gambler’s ruin chain with absorbing states0 and3; from1/2 move down with probability1/3 and up with probability2/3 P={Pij}=[p0,0p0,1p0,2p0,3p1,0p1,1p1,2p1,3p2,0p2,1p2,2p2,3p2,0p2,1p2,2p2,3]=[10001302300130230001]P=\{P_{ij}\}=\begin{bmatrix}p_{0,0}&p_{0,1}&p_{0,2}&p_{0,3}\\p_{1,0}&p_{1,1}&p_{1,2}&p_{1,3}\\p_{2,0}&p_{2,1}&p_{2,2}&p_{2,3}\\p_{2,0}&p_{2,1}&p_{2,2}&p_{2,3}\end{bmatrix}=\begin{bmatrix}1&0&0&0\\\frac13&0&\frac23&0\\0&\frac13&0&\frac23\\0&0&0&1\end{bmatrix}
Figure 5.2 Transition matrix and transition graph for Gambler’s ruin problem

The initial state is X0=1X_0=1 (MM has $1 at the beginning). At state 1, the next state is 0 (MM loses a game) with probability 1/31/3 and 2 (MM wins a game) with probability 2/32/3. So p1,0=1/3p_{1,0}=1/3 and p1,2=2/3p_{1,2}=2/3. Similarly we can get p2,1=1/3p_{2,1}=1/3 and p2,3=2/3p_{2,3}=2/3. Both state 3 (MM wins the whole game) and state 0 (MM loses the whole game) are absorbing states.

To calculate the probability that MM reaches absorbing state 3, we can apply absorption probability equations:

108 a3=1,a0=0,anda1=∑j=03p1,jaj,a2=∑j=03p2,jaja_3=1,a_0=0,\quad\text{and}\quad a_1=\sum_{j=0}^{3}p_{1,j}a_j,\quad a_2=\sum_{j=0}^{3}p_{2,j}a_j

Plugging in the transition probabilities using either the transition graph or transition matrix, we have

a1=1/3×0+2/3×a2a2=1/3×a1+2/3×1}⇒{a1=4/7a2=6/7\left.\begin{aligned}a_1&=1/3\times0+2/3\times a_2\\a_2&=1/3\times a_1+2/3\times1\end{aligned}\right\}\Rightarrow\begin{cases}a_1=4/7\\a_2=6/7\end{cases}

So, starting from $1, player MM has 4/74/7 probability of winning.

Dice question

Two players bet on roll(s) of the total of two standard six-face dice. Player AA bets that a sum of 12 will occur first. Player BB bets that two consecutive 7s will occur first. The players keep rolling the dice and record the sums until one player wins. What is the probability that AA will win?

Solution: Many of the simple Markov chain problems can be solved using pure conditional probability argument. It is not surprising considering that Markov chain is defined as conditional probability:

P{Xn+1=j∣Xn=i,Xn−1=in−1,⋯ ,X0=i0}=pij=P{Xn+1=j∣Xn=i}.P\{X_{n+1}=j\mid X_n=i,X_{n-1}=i_{n-1},\cdots,X_0=i_0\}=p_{ij}=P\{X_{n+1}=j\mid X_n=i\}.

So let’s first solve the problem using conditional probability arguments. Let P(A)P(A) be the probability that AA wins. Conditioning P(A)P(A) on the first throw’s sum FF, which has three possible outcomes F=12F=12, F=7F=7 and F∉{7,12}F\notin\{7,12\}, we have

P(A)=P(A∣F=12)P(F=12)+P(A∣F=7)P(F=7)+P(A∣F∉{7,12})P(F∉{7,12})\begin{aligned}P(A)&=P(A\mid F=12)P(F=12)+P(A\mid F=7)P(F=7)\\&\quad+P(A\mid F\notin\{7,12\})P(F\notin\{7,12\})\end{aligned}

Then we tackle each component on the right hand side. Using simple permutation, we can easily see that P(F=12)=1/36P(F=12)=1/36, P(F=7)=6/36P(F=7)=6/36, P(F∉{7,12})=29/36P(F\notin\{7,12\})=29/36. Also it is obvious that P(A∣F=12)=1P(A\mid F=12)=1 and P(A∣F∉{7,12})=P(A)P(A\mid F\notin\{7,12\})=P(A). (The game essentially starts over again.) To calculate P(A∣F=7)P(A\mid F=7), we need to further condition on the second throw’s total, which again has three possible outcomes: E=12E=12, E=7E=7, and E∉{7,12}E\notin\{7,12\}.

P(A∣F=7)=P(A∣F=7,E=12)P(E=12∣F=7)+P(A∣F=7,E=7)P(E=7∣F=7)+P(A∣F=7,E∉{7,12})P(E∉{7,12}∣F=7)=P(A∣F=7,E=12)×1/36+P(A∣F=7,E=7)×6/36+P(A∣F=7,E∉{7,12})×29/36=1×1/36+0×6/36+P(A)×29/36=1/36+29/36P(A)\begin{aligned}P(A\mid F=7)&=P(A\mid F=7,E=12)P(E=12\mid F=7)\\&\quad+P(A\mid F=7,E=7)P(E=7\mid F=7)\\&\quad+P(A\mid F=7,E\notin\{7,12\})P(E\notin\{7,12\}\mid F=7)\\&=P(A\mid F=7,E=12)\times1/36+P(A\mid F=7,E=7)\times6/36\\&\quad+P(A\mid F=7,E\notin\{7,12\})\times29/36\\&=1\times1/36+0\times6/36+P(A)\times29/36=1/36+29/36P(A)\end{aligned}

Here the second equation relies on the independence between the second and the first rolls. If F=7F=7 and E=12E=12, AA wins; if F=7F=7 and E=7E=7, AA loses; if F=7F=7 and 109 E∉{7,12}E\notin\{7,12\}, the game essentially starts over again. Now we have all the necessarily information for P(A)P(A). Plugging it into the original equation, we have

P(A)=P(A∣F=12)P(F=12)+P(A∣F=7)P(F=7)+P(A∣F∉{7,12})P(F∉{7,12})=1×1/36+6/36×(1/36+29/36P(A))+29/36P(A)\begin{aligned}P(A)&=P(A\mid F=12)P(F=12)+P(A\mid F=7)P(F=7)\\&\quad+P(A\mid F\notin\{7,12\})P(F\notin\{7,12\})\\&=1\times1/36+6/36\times(1/36+29/36P(A))+29/36P(A)\end{aligned}

Solving the equation, we get P(A)=7/13P(A)=7/13.

This approach, although logically solid, is not intuitively appealing. Now let’s try a Markov chain approach. Again the key part is to choose the right state space and define the transition probabilities. It is apparent that we have two absorbing states, 12 (AA wins) and 7-7 (BB wins), at least two transient states, SS (starting state) and 7 (one 7 occurs, yet no 12 or 7-7 occurred). Do we need any other states? Theoretically, you can have other states. In fact, you can use all combination of the outcomes of one roll and two consecutive rolls as states to construct a transition matrix and you will get the same final result. Nevertheless, we want to consolidate as many equivalent states as possible. As we just discussed in the conditional probability approach, if no 12 has occurred and the most recent roll did not yield 7, we essentially go back to the initial starting state SS. So all we need are states SS, 7, 7-7 and 12. The transition graph and probability to reach state 12 are shown in Figure 5.3.

Dice-roll chain with transient S and7, absorbing7-7 and12, transition labels1/36,6/36,29/36

Probability to absorption state 12

a12=1,a7−7=0aS=1/36×1+6/36×a7+29/36×aSa7=1/36×1+6/36×0+29/36×aS}⇒aS=7/13\left.\begin{aligned}a_{12}&=1,\quad a_{7-7}=0\\a_S&=1/36\times1+6/36\times a_7+29/36\times a_S\\a_7&=1/36\times1+6/36\times0+29/36\times a_S\end{aligned}\right\}\Rightarrow a_S=7/13
Figure 5.3 Transition graph and probability to absorption for dice rolls

Here the transition probability is again derived from conditional probability arguments. Yet the transition graph makes the process crystal clear.

Coin triplets

Part A. If you keep on tossing a fair coin, what is the expected number of tosses such that you can have HHH (heads heads heads) in a row? What is the expected number of tosses to have THH (tails heads heads) in a row?

Solution: The most difficult part of Markov chain is, again, to choose the right state space. For the HHH sequence, the state space is straightforward. We only need four states: S (for the starting state when no coin is tossed or whenever a T turns up before HHH), H, HH, and HHH. The transition graph is

110
HHH waiting chain: S,H,HH,HHH with heads moving right, tails returning to S, HHH absorbing

At state S, after a coin toss, the state will stay at S when the toss gives a T. If the toss gives an H, the state becomes H. At state H, it has 1/21/2 probability goes back to state S if the next toss is T; otherwise, it goes to state HH. At state HH, it also has 1/21/2 probability goes back to state S if the next toss is T; otherwise, it reaches the absorbing state HHH.

So we have the following transition probabilities: PS,S=12P_{S,S}=\frac12, PS,H=12P_{S,H}=\frac12, PH,S=12P_{H,S}=\frac12, PH,HH=12P_{H,HH}=\frac12, PHH,S=12P_{HH,S}=\frac12, PHH,HHH=12P_{HH,HHH}=\frac12, and PHHH,HHH=1P_{HHH,HHH}=1.

We are interested in the expected number of tosses to get HHH, which is the expected time to absorption starting from state S. Applying the standard equations for the expected time to absorption, we have

μS=1+12μS+12μHμH=1+12μS+12μHHμHH=1+12μS+12μHHHμHHH=0}⇒{μS=14μH=12μHH=8μHHH=0\left.\begin{aligned}\mu_S&=1+\tfrac12\mu_S+\tfrac12\mu_H\\\mu_H&=1+\tfrac12\mu_S+\tfrac12\mu_{HH}\\\mu_{HH}&=1+\tfrac12\mu_S+\tfrac12\mu_{HHH}\\\mu_{HHH}&=0\end{aligned}\right\}\Rightarrow\begin{cases}\mu_S=14\\\mu_H=12\\\mu_{HH}=8\\\mu_{HHH}=0\end{cases}

So from the starting state, the expected number of tosses to get HHH is 14.

Similarly for expected time to reach THH, we can construct the following transition graph and estimate the corresponding expected time to absorption:

THH waiting chain with states S,T,TH,THH and half-probability transitions; THH absorbing μS=1+12μS+12μTμT=1+12μT+12μTHμTH=1+12μT+12μTHHμTHH=0}⇒{μS=8μT=4μTH=2μTHH=0\left.\begin{aligned}\mu_S&=1+\tfrac12\mu_S+\tfrac12\mu_T\\\mu_T&=1+\tfrac12\mu_T+\tfrac12\mu_{TH}\\\mu_{TH}&=1+\tfrac12\mu_T+\tfrac12\mu_{THH}\\\mu_{THH}&=0\end{aligned}\right\}\Rightarrow\begin{cases}\mu_S=8\\\mu_T=4\\\mu_{TH}=2\\\mu_{THH}=0\end{cases}

So from the starting state S, the expected number of tosses to get THH is 8.

Part B. Keep flipping a fair coin until either HHH or THH occurs in the sequence. What is the probability that you get an HHH subsequence before THH?2

111

Solution: Let’s try a standard Markov chain approach. Again the focus is on choosing the right state space. In this case, we begin with starting state S. We only need ordered subsequences of either HHH or THH. After one coin is flipped, we have either state T or H. After two flips, we have states TH and HH. We do not need TT (which is equivalent to T for this problem) or HT (which is also equivalent to T as well). For three coin sequences, we only need THH and HHH states, which are both absorbing states. Using these states, we can build the following transition graph:

Competing HHH and THH Markov chain: initial S branches to T or H; T/TH lead to absorbing THH, H/HH lead to HHH unless tails send them to T
Figure 5.4 Transition graph of coin tosses to reach HHH or THH

We want to get the probability to reach absorbing state HHH from the starting state S. Applying the equations for absorption probability, we have

aHHH=1,aTHH=0aS=12aT+12aHaT=12aT+12aTH,aH=12aT+12aHHaTH=12aT+12aTHH,aHH=12aT+12aHHH}⇒{aT=0, aTH=0aS=18aH=14aHH=12\left.\begin{aligned}a_{HHH}&=1,\quad a_{THH}=0\\a_S&=\tfrac12a_T+\tfrac12a_H\\a_T&=\tfrac12a_T+\tfrac12a_{TH},\quad a_H=\tfrac12a_T+\tfrac12a_{HH}\\a_{TH}&=\tfrac12a_T+\tfrac12a_{THH},\quad a_{HH}=\tfrac12a_T+\tfrac12a_{HHH}\end{aligned}\right\}\Rightarrow\begin{cases}a_T=0,\ a_{TH}=0\\a_S=\frac18\\a_H=\frac14\\a_{HH}=\frac12\end{cases}

So the probability that we end up with the HHH pattern is 1/81/8.

This problem actually has a special feature that renders the calculation unnecessary. You may have noticed that aT=0a_T=0. Once a tail occurs, we will always get THH before HHH. The reason is that the last two coins in THH is HH, which is the first two coins in sequence HHH. In fact, the only way that the sequence reaches state HHH before THH is that we get three consecutive Hs in the beginning. Otherwise, we always have a T before the first HH sequence and always end in THH first. So if we don’t start the coin flipping sequence with HHH, which has a probability of 1/81/8, we will always have THH before HHH.

Part C. (Difficult) Let’s add more fun to the triplet game. Instead of fixed triplets for the two players, the new game allows both to choose their own triplets. Player 1 chooses a triplet first and announces it; then player 2 chooses a different triplet. The players again toss the coins until one of the two triplet sequences appears. The player whose chosen triplet appears first wins the game.

112

If both player 1 and player 2 are perfectly rational and both want to maximize their probability of winning, would you go first (as player 1)? If you go second, what is your probability of winning?3

Solution: A common misconception is that there is always a best sequence that beats other sequences. This misconception is often founded on a wrong assumption that these sequences are transitive: if sequence A has a higher probability occurring before sequence B and sequence B has a higher probability occurring before sequence C, then sequence A has a higher probability occurring before sequence C. In reality, such transitivity does not exist for this game. No matter what sequence player 1 chooses, player 2 can always choose another sequence with more than 1/21/2 probability of winning. The key, as we have indicated in Part B, is to choose the last two coins of the sequence as the first two coins of player 1’s sequence. We can compile the following table for each pair of sequences:

Table 5.1 Player 2’s winning probability with different coin sequence pairs
2’s winning
Probability
Player 1
HHHTHHHTHHHTTTHTHTHTTTTT
HHH/1/82/51/23/105/122/51/2
THH7/8/1/23/41/31/21/23/5
HTH3/51/2/1/33/81/21/27/12
HHT1/21/42/3/1/25/82/37/10
TTH7/102/35/81/2/2/31/41/2
THT7/121/21/23/81/3/1/23/5
HTT3/51/21/21/33/41/2/7/8
TTT1/22/55/123/101/22/51/8/

Row triplets: Player 2.

As shown in Table 5.1 (you can confirm the results yourself), no matter what player 1’s choices are, player 2 can always choose a sequence to have better odds of winning. The best sequences that player 2 can choose in response to 1’s choices are highlighted in bold. In order to maximize his odds of winning, player 1 should choose among HTH, HTT, THH and THT. Even in these cases, player 2 has 2/32/3 probability of winning.

113

Color balls

A box contains nn balls of nn different colors. Each time, you randomly select a pair of balls, repaint the first to match the second, and put the pair back into the box. What is the expected number of steps until all balls in the box are of the same color? (Very difficult)

Solution: Let NnN_n be the number of steps needed to make all balls the same color, and let Fi,i=1,2,⋯ ,nF_i,i=1,2,\cdots,n, be the event that all balls have color ii in the end. Applying the law of total expectation, we have

E[Nn]=E[Nn∣F1]P[F1]+E[Nn∣F2]P[F2]+⋯+E[Nn∣Fn]P[Fn].E[N_n]=E[N_n\mid F_1]P[F_1]+E[N_n\mid F_2]P[F_2]+\cdots+E[N_n\mid F_n]P[F_n].

Since all the colors are symmetric (i.e., they should have equivalent properties), we have P[F1]=P[F2]=⋯=P[Fn]=1/nP[F_1]=P[F_2]=\cdots=P[F_n]=1/n and E[Nn]=E[Nn∣F1]=E[Nn∣F2]=E[Nn∣Fn]E[N_n]=E[N_n\mid F_1]=E[N_n\mid F_2]=E[N_n\mid F_n]. That means we can assume that all the balls have color 1 in the end and use E[Nn∣F1]E[N_n\mid F_1] to represent E[Nn]E[N_n].

So how do we calculate E[Nn∣F1]E[N_n\mid F_1]? Not surprisingly, use a Markov chain. Since we only consider event F1F_1, color 1 is different from other colors and colors 2,⋯ ,n2,\cdots,n become equivalent. In other words, any pairs of balls that have no color 1 ball involved are equivalent and any pairs with a color 1 ball and a ball of another color are equivalent if the order is the same as well. So we only need to use the number of balls that have color 1 as the states. Figure 5.5 shows the transition graph.

Color-count states1,2,...,i−1,i,i+1,...,n−1,n; neighboring transitions and self-loops, state n absorbing
Figure 5.5 Transition graph for all nn balls to become color 1

State nn is the only absorbing state. Notice that there is no state 0, otherwise it will never reach F1F_1. In fact, all the transition probability is conditioned on F1F_1 as well, which makes the transition probability pi,i+1∣F1p_{i,i+1}\mid F_1 higher than the unconditional probability pi,i+1p_{i,i+1} and pi,i−1∣F1p_{i,i-1}\mid F_1 lower than pi,i−1p_{i,i-1}. For example, p1,0∣F1=0p_{1,0}\mid F_1=0 and p1,0=1/np_{1,0}=1/n. (Without conditioning, each ball is likely to be the second ball, so color 1 has 1/n1/n probability of being the second ball.) Using the conditional transition probability, the problem essentially becomes expected time to absorption with system equations:

E[Ni∣F1]=1+E[Ni−1∣F1]×Pi,i−1∣F1+E[Ni∣F1]×Pi,i∣F1+E[Ni+1∣F1]×Pi,i+1∣F1.\begin{aligned}E[N_i\mid F_1]&=1+E[N_{i-1}\mid F_1]\times P_{i,i-1}\mid F_1\\&\quad+E[N_i\mid F_1]\times P_{i,i}\mid F_1+E[N_{i+1}\mid F_1]\times P_{i,i+1}\mid F_1.\end{aligned} 114

To calculate Pi,i−1∣F1P_{i,i-1}\mid F_1, let’s rewrite the probability as P(xk+1=i−1∣xk=i,F1)P(x_{k+1}=i-1\mid x_k=i,F_1), ∀k=0,1,⋯\forall k=0,1,\cdots, to make the derivation step clearer:

P(xk+1=i−1∣xk=i,F1)=P(xk=i,xk+1=i−1,F1)P(xk=i,F1)=P(F1∣xk+1=i−1,xk=i)×P(xk+1=i−1∣xk=i)×P(xk=i)P(F1∣xk=i)×P(xk=i)=P(F1∣xk+1=i−1)×P(xk+1=i−1∣xk=i)P(F1∣xk=i)=i−1n×i(n−i)n(n−1)i/n=(n−i)×(i−1)n(n−1)\begin{aligned}P(x_{k+1}=i-1\mid x_k=i,F_1)&=\frac{P(x_k=i,x_{k+1}=i-1,F_1)}{P(x_k=i,F_1)}\\&=\frac{P(F_1\mid x_{k+1}=i-1,x_k=i)\times P(x_{k+1}=i-1\mid x_k=i)\times P(x_k=i)}{P(F_1\mid x_k=i)\times P(x_k=i)}\\&=\frac{P(F_1\mid x_{k+1}=i-1)\times P(x_{k+1}=i-1\mid x_k=i)}{P(F_1\mid x_k=i)}\\&=\frac{\dfrac{i-1}{n}\times\dfrac{i(n-i)}{n(n-1)}}{i/n}=\frac{(n-i)\times(i-1)}{n(n-1)}\end{aligned}

The first equation is simply the definition of conditional probability; the second equation is the application of Bayes’ theorem; the third equation applies the Markov property. To derive P(F1∣xk=i)=i/nP(F_1\mid x_k=i)=i/n, we again need to use symmetry. We have shown that if all the balls have different colors, then we have P[F1]=P[F2]=⋯=P[Fn]=1/nP[F_1]=P[F_2]=\cdots=P[F_n]=1/n. What is the probability of ending in a given color, labeled as cc, if ii of the balls are of color cc? It is simply i/ni/n. To see that, we can label the color of each of the ii balls of color cc as cj,j=1,⋯ ,ic_j,j=1,\cdots,i (even though they are in fact the same color). Now it’s obvious that all balls will end with color cjc_j with probability 1/n1/n. The probability for cc is the sum of probabilities of cjc_j’s, which gives the result i/ni/n.

Similarly we have P(F1∣xk+1=i−1)=(i−1)/nP(F_1\mid x_{k+1}=i-1)=(i-1)/n. For P(xk+1=i−1∣xk=i)P(x_{k+1}=i-1\mid x_k=i), we use a basic counting method. There are n(n−1)n(n-1) possible permutations to choose 2 balls out of nn balls. In order for one color 1 ball to change color, the second ball must be color 1, which has ii choices; the first ball needs to be another color, which has (n−i)(n-i) choices. So P(xk+1=i−1∣xk=i)=i(n−i)n(n−1)\displaystyle P(x_{k+1}=i-1\mid x_k=i)=\frac{i(n-i)}{n(n-1)}.

Applying the same principles, we can get

P(xk+1=i∣xk=i,F1)=(n−i)×2in(n−1),P(xk+1=i+1∣xk=i,F1)=(n−i)×(i+1)n(n−1).P(x_{k+1}=i\mid x_k=i,F_1)=\frac{(n-i)\times2i}{n(n-1)},\quad P(x_{k+1}=i+1\mid x_k=i,F_1)=\frac{(n-i)\times(i+1)}{n(n-1)}.

Plugging into E[Ni∣F1]E[N_i\mid F_1] and simplifying E[Ni∣F1]E[N_i\mid F_1] as ZiZ_i, we have

(n−i)×2i×Zi=n(n−1)+(n−i)(i+1)Zi+1+(n−i)(i−1)Zi−1.(n-i)\times2i\times Z_i=n(n-1)+(n-i)(i+1)Z_{i+1}+(n-i)(i-1)Z_{i-1}. 115

Using these recursive system equations and the boundary condition Zn=0Z_n=0, we can get Z1=(n−1)2Z_1=(n-1)^2.4