Conditional Probability, Independence & Bayes

Study Sheet

Conditional Probability, Independence & Bayes

Competition counting & probability, Unit 8

Conditional Probability P(AB)P(A\mid B)

Concept
Probability once you already know something

The conditional probability of AA given that BB has occurred is

P(AB)=P(AB)P(B),P(B)>0.P(A\mid B) = \frac{P(A\cap B)}{P(B)}, \qquad P(B) > 0.

Conditioning on BB shrinks the sample space to just the outcomes in BB: we ask what fraction of BB's probability also lies in AA. Rearranging gives the form you will use constantly,

P(AB)=P(AB)P(B)=P(BA)P(A).P(A\cap B) = P(A\mid B)\,P(B) = P(B\mid A)\,P(A).

In a finite equally-likely setting this is simply P(AB)=ABBP(A\mid B) = \dfrac{|A\cap B|}{|B|}: recount inside the restricted world BB.

Example
Worked example: a die given “even”

A fair die is rolled. Given that the result is even, what is the probability it is greater than 33?

Solution. Let B={2,4,6}B=\{2,4,6\} and A={4,5,6}A=\{4,5,6\}. Then AB={4,6}A\cap B=\{4,6\}, so

P(AB)=ABB=23.P(A\mid B) = \frac{|A\cap B|}{|B|} = \frac{2}{3}.

Knowing “even” throws away the odd outcomes; we only compare within {2,4,6}\{2,4,6\}.

Example
Worked example: two cards without replacement

Two cards are drawn from a standard 5252-card deck without replacement. What is the probability the second is a heart given the first was a heart?

Solution. After removing one heart, 1212 hearts remain among 5151 cards, so

P(2nd heart1st heart)=1251=417.P(\text{2nd heart}\mid\text{1st heart}) = \frac{12}{51} = \frac{4}{17}.

Conditioning literally updates the deck.

Tip

Pitfall. P(AB)P(A\mid B) and P(BA)P(B\mid A) are different numbers. “The probability of a rash given measles” is near 11; “the probability of measles given a rash” is tiny. Swapping the two is the single most common conditional-probability error.

The Multiplication Rule & Probability Trees

Concept
Chaining conditional probabilities

Solving P(AB)=P(AB)P(B)P(A\mid B)=\frac{P(A\cap B)}{P(B)} for the intersection gives the multiplication rule:

P(AB)=P(B)P(AB).P(A\cap B) = P(B)\,P(A\mid B).

For a sequence of stages it chains (the chain rule):

P(A1A2A3)=P(A1)P(A2A1)P(A3A1A2).P(A_1\cap A_2\cap A_3) = P(A_1)\,P(A_2\mid A_1)\,P(A_3\mid A_1\cap A_2).

A probability tree draws this: each branch carries a conditional probability, and the probability of a full path is the product of the branch probabilities along it. Probabilities on branches leaving a node sum to 11; probabilities of the leaves sum to 11.

Reminder — The differentiation rules:(xn)=nxn1,(fg)=fg+fg,(fg)=fgfgg2,(f(g(x)))=f(g(x))g(x)(x^{n})'=nx^{n-1},\quad (fg)'=f'g+fg',\quad \left(\tfrac{f}{g}\right)'=\frac{f'g-fg'}{g^{2}},\quad \big(f(g(x))\big)'=f'(g(x))g'(x)

Multiply along a path for a leaf; add leaves for an event.

Example
Worked example: drawing two aces

Two cards are drawn without replacement. Probability both are aces?

Solution. Multiply along the path:

P(ace1ace2)=452351=122652=1221.P(\text{ace}_1\cap\text{ace}_2) = \frac{4}{52}\cdot\frac{3}{51} = \frac{12}{2652} = \frac{1}{221}.
Example
Worked example: reading a two-stage tree

A box has 22 red and 33 blue balls. Draw two without replacement. Probability of exactly one red?

Solution. Two paths give “one red”: RB and BR.

P=2534RB+3524BR=620+620=1220=35.P = \underbrace{\frac{2}{5}\cdot\frac{3}{4}}_{RB} + \underbrace{\frac{3}{5}\cdot\frac{2}{4}}_{BR} = \frac{6}{20}+\frac{6}{20} = \frac{12}{20} = \frac{3}{5}.

Multiply along each path, then add the paths that satisfy the event.

Tip

Tip. Trees turn “and” into multiplication and “or” into addition automatically. Whenever a problem unfolds in stages (draw, then draw; test, then confirm), sketch the tree before writing any algebra.

Independence

Concept
When knowing BB tells you nothing about AA

Events AA and BB are independent exactly when

P(AB)=P(A)P(B),P(A\cap B) = P(A)\,P(B),

equivalently (when the conditionals are defined) P(AB)=P(A)P(A\mid B) = P(A) and P(BA)=P(B)P(B\mid A)=P(B). Learning that BB happened does not change the probability of AA.

For several events, mutual independence requires the product rule to hold for every subcollection, not just pairs. Pairwise independence does not imply mutual independence.

Example
Worked example: independent vs. dependent draws

Draw a card, replace it, reshuffle, draw again. Are “first is a heart” and “second is a heart” independent?

Solution. With replacement the deck resets: P(2nd heart1st heart)=14=P(2nd heart)P(\text{2nd heart}\mid\text{1st heart}) = \tfrac14 = P(\text{2nd heart}), so yes. Without replacement it was 125114\tfrac{12}{51}\neq\tfrac14, so no. Replacement is the usual switch between independent and dependent.

Example
Worked example: testing the definition

Roll two fair dice. Let A=A= “first die is 2\le 2” and B=B= “sum is 77”. Independent?

Solution. P(A)=26=13P(A)=\tfrac{2}{6}=\tfrac13, P(B)=636=16P(B)=\tfrac{6}{36}=\tfrac16. The pairs with first die 2\le 2 and sum 77 are (1,6),(2,5)(1,6),(2,5), so P(AB)=236=118P(A\cap B)=\tfrac{2}{36}=\tfrac{1}{18}. Check: P(A)P(B)=1316=118P(A)P(B)=\tfrac13\cdot\tfrac16=\tfrac{1}{18}. Equal, so independent.

Tip

Pitfall. Independent is not the same as mutually exclusive. Disjoint events with positive probability are strongly dependent: if AB=A\cap B=\varnothing then P(AB)=0P(A)P(A\mid B)=0\neq P(A). Always test independence with the product rule, never by intuition.

The Law of Total Probability

Concept
Break an event across a partition of causes

Let B1,B2,,BnB_1,B_2,\dots,B_n partition the sample space (disjoint, together all outcomes, each P(Bi)>0P(B_i)>0). For any event AA,

P(A)=i=1nP(ABi)P(Bi).P(A) = \sum_{i=1}^{n} P(A\mid B_i)\,P(B_i).

Each term is one path of a tree: choose the scenario BiB_i, then let AA happen inside it. This is the workhorse for computing an overall probability when the world splits into cases.

Example
Worked example: two urns

Urn 1 has 33 red, 11 white; Urn 2 has 11 red, 33 white. Flip a fair coin to pick an urn, then draw a ball. Probability the ball is red?

Solution. Partition by the urn:

P(R)=P(RU1)P(U1)+P(RU2)P(U2)=3412+1412=38+18=12.P(R) = P(R\mid U_1)P(U_1) + P(R\mid U_2)P(U_2) = \frac34\cdot\frac12 + \frac14\cdot\frac12 = \frac{3}{8}+\frac{1}{8} = \frac12.
Example
Worked example: defective parts from three machines

Machines A, B, C make 50%,30%,20%50\%, 30\%, 20\% of output with defect rates 1%,2%,3%1\%, 2\%, 3\%. Probability a random item is defective?

Solution.

P(D)=(0.01)(0.50)+(0.02)(0.30)+(0.03)(0.20)=0.005+0.006+0.006=0.017.P(D) = (0.01)(0.50) + (0.02)(0.30) + (0.03)(0.20) = 0.005 + 0.006 + 0.006 = 0.017.

A weighted average of the defect rates, weighted by production share.

Tip

Tip. The weights P(Bi)P(B_i) must sum to 11 and the cases must not overlap. When you see “there are several types/sources, each with its own rate,” reach for total probability.

Bayes' Theorem

Concept
Reversing the conditioning

Combining P(BiA)=P(ABi)P(Bi)P(B_i\cap A)=P(A\mid B_i)P(B_i) with the law of total probability gives Bayes' Theorem:

P(BiA)=P(ABi)P(Bi)jP(ABj)P(Bj)=P(ABi)P(Bi)P(A).P(B_i\mid A) = \frac{P(A\mid B_i)\,P(B_i)}{\displaystyle\sum_{j} P(A\mid B_j)\,P(B_j)} = \frac{P(A\mid B_i)\,P(B_i)}{P(A)}.

It converts the prior P(Bi)P(B_i) (belief before the evidence) into the posterior P(BiA)P(B_i\mid A) (belief after seeing AA). The numerator is one path; the denominator is all paths reaching AA.

Example
Worked example: which urn produced the red ball?

Using the two-urn setup above, a red ball was drawn. Probability it came from Urn 1?

Solution.

P(U1R)=P(RU1)P(U1)P(R)=341212=3/81/2=34.P(U_1\mid R) = \frac{P(R\mid U_1)P(U_1)}{P(R)} = \frac{\frac34\cdot\frac12}{\frac12} = \frac{3/8}{1/2} = \frac34.

The red ball is evidence that shifts belief toward the red-heavy urn.

Example
Worked example: the defective came from machine C?

For the three machines above, a defective item is found. Probability it was machine C's?

Solution.

P(CD)=(0.03)(0.20)0.017=0.0060.017=6170.353.P(C\mid D) = \frac{(0.03)(0.20)}{0.017} = \frac{0.006}{0.017} = \frac{6}{17} \approx 0.353.

Even though C makes only 20%20\% of output, its high defect rate makes it responsible for over a third of defects.

Tip

Tip. A clean recipe: (1) list the scenarios BiB_i and their priors, (2) attach the likelihood P(ABi)P(A\mid B_i) to each, (3) multiply for each path, (4) divide the target path by the sum of all paths. Steps 1--3 are just a tree; Bayes is only the final division.

Classic Traps: Monty Hall, Two-Child, False Positives

Concept
Why these fool everyone

Each trap hides a conditioning step. The intuition “symmetry means 50/5050/50” fails because the evidence is not symmetric across the hidden scenarios. Draw the tree, weight by priors, and let Bayes overrule the gut.

Example
Monty Hall, fully explained

Three doors hide one car and two goats. You pick a door; the host --- who knows where the car is --- opens a different door revealing a goat, then offers a switch. Should you switch?

Solution. Your first pick is right with probability 13\tfrac13 and wrong with probability 23\tfrac23. The host's guaranteed goat-reveal gives no new information about your original door, so:

  • 2pt
  • If you initially picked the car (13\tfrac13), switching loses.
  • If you initially picked a goat (23\tfrac23), the host is forced to reveal the other goat, so the remaining door hides the car --- switching wins.

Therefore P(win by switching)=23P(\text{win by switching}) = \tfrac23, double the 13\tfrac13 from staying. The key is that the host's choice is constrained by knowledge; a host opening a random door would change the analysis.

Example
The false-positive (medical-test) paradox

A disease affects 11 in 10001000 people. A test is 99%99\% accurate both ways (sensitivity 99%99\%, specificity 99%99\%). You test positive. What is the probability you actually have the disease?

Solution. Let DD be disease, ++ a positive test. Priors P(D)=0.001P(D)=0.001, P(Dc)=0.999P(D^c)=0.999.

P(+D)=0.99,P(+Dc)=0.01.P(+\mid D)=0.99,\qquad P(+\mid D^c)=0.01.

By Bayes,

P(D+)=(0.99)(0.001)(0.99)(0.001)+(0.01)(0.999)=0.000990.00099+0.00999=0.000990.010980.090.P(D\mid +) = \frac{(0.99)(0.001)}{(0.99)(0.001)+(0.01)(0.999)} = \frac{0.00099}{0.00099+0.00999} = \frac{0.00099}{0.01098} \approx 0.090.

Only about 9%9\%! Because the disease is rare, the many false positives from the huge healthy population swamp the few true positives. The base rate dominates.

Example
The two-child problem and its ambiguity

A family has two children.

  • 2pt
  • “At least one is a boy.” Probability both are boys? Sample space {BB,BG,GB,GG}\{BB,BG,GB,GG\} is equally likely; condition on at least one boy: {BB,BG,GB}\{BB,BG,GB\}, of which BBBB is one. Answer 13\tfrac13.
  • “The older is a boy.” Probability both boys? Now condition on {BB,BG}\{BB,BG\}: answer 12\tfrac12.

Same family, different information, different answers --- see Going Deeper for why the phrasing matters.

Tip

Pitfall. In every trap, how the information was obtained changes the conditioning set. “I met one of the children and he's a boy” is not the same evidence as “at least one child is a boy,” even though both mention a boy. Model the process, not just the sentence.

Going Deeper: Bayesian Updating, Conditioning, and Ambiguity

Concept
Belief as something you update

Bayesian updating treats probability as a state of belief refined by evidence. The posterior after one observation becomes the prior for the next:

P(HE1,E2)    P(E2H)P(E1H)P(H)posterior after E1.P(H\mid E_1, E_2) \;\propto\; P(E_2\mid H)\,\underbrace{P(E_1\mid H)\,P(H)}_{\text{posterior after }E_1}.

Independent pieces of evidence multiply their likelihood ratios. A rare hypothesis can still win if the evidence is strong enough, and a common one can survive weak evidence --- exactly the tension in the medical-test example.

Example
Worked example: updating twice

The rare disease (P(D)=0.001P(D)=0.001) test above comes back positive; a second independent test (same accuracy) is also positive. Now find P(D++)P(D\mid ++).

Solution. Use the first posterior P(D+)0.0902P(D\mid +)\approx 0.0902 as the new prior:

P(D++)=(0.99)(0.0902)(0.99)(0.0902)+(0.01)(0.9098)0.08930.0893+0.00910.907.P(D\mid ++) = \frac{(0.99)(0.0902)}{(0.99)(0.0902)+(0.01)(0.9098)} \approx \frac{0.0893}{0.0893+0.0091} \approx 0.907.

Two positives push belief from 9%9\% to about 91%91\%. Evidence compounds.

Example
Worked example: why conditioning defies intuition

Why does “at least one boy” give 13\tfrac13 but “the older is a boy” give 12\tfrac12?

Solution. Conditioning removes outcomes unevenly. “Older is a boy” eliminates GGGG and GBGB, leaving two equally likely worlds BB,BGBB,BG. “At least one boy” eliminates only GGGG, leaving three worlds BB,BG,GBBB,BG,GB, and BBBB is just one of them. The information “at least one” is weaker --- it does not pin down which child --- so it cuts the space less. Intuition fails because we imagine the evidence naming a specific child when it does not.

Example
Worked example: the ambiguity made precise

“A family has two children; I tell you at least one is a boy born on a Tuesday. Both boys?” The Tuesday detail, seemingly irrelevant, shifts the answer to 1327\tfrac{13}{27}, not 13\tfrac13.

Solution sketch. Each child is one of 1414 equally likely (gender, weekday) types. Counting the ordered pairs containing at least one “boy-Tuesday” gives 2727; those with two boys give 1313; hence 13270.481\tfrac{13}{27}\approx 0.481. The lesson: the more specifically the evidence identifies a child, the closer the answer creeps to 12\tfrac12. Ambiguous wording has no single “right” answer until the sampling process is fixed.

Tip

Big picture --- conditioning is re-weighting your world. Every result in this unit is one identity, P(AB)=P(AB)P(B)P(A\cap B)=P(A\mid B)P(B), read in different directions:

  • 2pt
  • Forward (trees, multiplication, total probability): split into cases, multiply along paths, add paths to get P(A)P(A).
  • Backward (Bayes): once AA is observed, divide the target path by all paths to get P(BiA)P(B_i\mid A) --- prior times likelihood, normalized.
  • Independence is the special case where conditioning changes nothing: P(AB)=P(A)P(A\mid B)=P(A).
  • The traps all come from misreading which outcomes the evidence keeps. Always model the process that produced the information, weight by the priors (mind the base rate), and trust the arithmetic over the gut.

The Odds Form of Bayes & Sequential Updating

Concept
Bayes as a multiplier on odds

Write Bayes' theorem for two competing hypotheses HH and its complement HcH^c and divide the two versions. The awkward normalizing denominator P(E)P(E) cancels, leaving the odds form:

P(HE)P(HcE)posterior odds=P(EH)P(EHc)likelihood ratio (LR)P(H)P(Hc)prior odds.\underbrace{\frac{P(H\mid E)}{P(H^c\mid E)}}_{\text{posterior odds}} =\underbrace{\frac{P(E\mid H)}{P(E\mid H^c)}}_{\text{likelihood ratio (LR)}} \cdot\underbrace{\frac{P(H)}{P(H^c)}}_{\text{prior odds}}.

Updating is now pure multiplication: posterior odds == LR ×\times prior odds. For a stream of conditionally independent pieces of evidence E1,,EnE_1,\dots,E_n the likelihood ratios simply multiply,

P(HE1,,En)P(HcE1,,En)=(k=1nP(EkH)P(EkHc))P(H)P(Hc).\frac{P(H\mid E_1,\dots,E_n)}{P(H^c\mid E_1,\dots,E_n)} =\left(\prod_{k=1}^{n}\frac{P(E_k\mid H)}{P(E_k\mid H^c)}\right)\frac{P(H)}{P(H^c)}.

This is iterated Bayesian updating: each posterior is the next prior, and in odds language the whole computation collapses to one product. Recover a probability at the end via p=odds1+oddsp=\dfrac{\text{odds}}{1+\text{odds}}.

Example
Worked example: three positive tests, done in odds

A disease has prevalence P(D)=11000P(D)=\tfrac{1}{1000}. A test has sensitivity P(+D)=0.99P(+\mid D)=0.99 and false-positive rate P(+Dc)=0.01P(+\mid D^c)=0.01, giving likelihood ratio LR=0.990.01=99\mathrm{LR}=\tfrac{0.99}{0.01}=99. Three independent tests all read positive. Find P(D+++)P(D\mid {+}{+}{+}).

Solution. Prior odds =1/1000999/1000=1999=\dfrac{1/1000}{999/1000}=\dfrac{1}{999}. Multiply by LR\mathrm{LR} once per positive:

posterior odds=9931999=970299999971.3.\text{posterior odds}=99^3\cdot\frac{1}{999}=\frac{970299}{999}\approx 971.3.

Convert back:

P(D+++)=971.31+971.30.99897.P(D\mid {+}{+}{+})=\frac{971.3}{1+971.3}\approx 0.99897.

One positive left belief near 9%9\% (the base rate dominated); the odds form shows why each extra positive multiplies the odds by 9999, so three positives overwhelm even a 11-in-10001000 prior.

Example
Worked example: mixed evidence (a positive then a negative)

Same test. A patient tests positive, then negative on an independent retest. What is P(D)P(D) now?

Solution. The negative test has its own likelihood ratio P(D)P(Dc)=0.010.99=199\dfrac{P(-\mid D)}{P(-\mid D^c)}=\dfrac{0.01}{0.99}=\dfrac{1}{99}. Chain both:

posterior odds=99+1991999prior=1999.\text{posterior odds}=\underbrace{99}_{+}\cdot\underbrace{\tfrac{1}{99}}_{-}\cdot\underbrace{\tfrac{1}{999}}_{\text{prior}}=\frac{1}{999}.

The two tests exactly cancel, returning belief to the prior 11000\tfrac{1}{1000}. Contradictory evidence multiplies to a net ratio of 11 --- a fact almost invisible in the fraction form but obvious in odds.

Tip

Tip. Whenever a problem chains several independent clues toward one yes/no hypothesis, switch to odds: multiply the prior odds by each likelihood ratio, then convert once at the end. It sidesteps the denominator entirely and makes “how much does this clue matter?” literally a multiplier.

Markov Chains & Transition Matrices

Concept
Memoryless step-by-step randomness

A Markov chain moves among states 1,,m1,\dots,m so that the next state depends only on the current one, not the past history:

P(Xn+1=jXn=i, Xn1,)=P(Xn+1=jXn=i)=:pij.P(X_{n+1}=j\mid X_n=i,\ X_{n-1},\dots)=P(X_{n+1}=j\mid X_n=i)=:p_{ij}.

Collect these into the transition matrix P=[pij]P=[p_{ij}]; each row sums to 11. If the current distribution over states is a row vector v\mathbf{v}, then after one step it is vP\mathbf{v}P, and after nn steps vPn\mathbf{v}P^{n}. The (i,j)(i,j) entry of PnP^{n} is exactly P(Xn=jX0=i)P(X_n=j\mid X_0=i) --- multi-step probabilities are just matrix powers.

A stationary distribution π\boldsymbol{\pi} satisfies πP=π\boldsymbol{\pi}P=\boldsymbol{\pi} with iπi=1\sum_i\pi_i=1: the chain, once in π\boldsymbol{\pi}, stays distributed as π\boldsymbol{\pi} forever. An absorbing state has pii=1p_{ii}=1 (once entered, never left).

Example
Worked example: sunny/rainy two-step and long-run

Weather follows a chain on states (Sunny, Rainy) with

P=[0.80.20.40.6].P=\begin{bmatrix} 0.8 & 0.2 \\ 0.4 & 0.6 \end{bmatrix}.

(a) If today is sunny, probability it is rainy the day after tomorrow? (b) What fraction of days are sunny in the long run?

Solution. (a) Compute the two-step matrix:

P2=[0.80.20.40.6][0.80.20.40.6]=[0.720.280.560.44].P^2=\begin{bmatrix} 0.8 & 0.2 \\ 0.4 & 0.6 \end{bmatrix} \begin{bmatrix} 0.8 & 0.2 \\ 0.4 & 0.6 \end{bmatrix} =\begin{bmatrix} 0.72 & 0.28 \\ 0.56 & 0.44 \end{bmatrix}.

The (Sunny \to Rainy) entry is 0.280.28.

(b) Solve πP=π\boldsymbol{\pi}P=\boldsymbol{\pi} with π=(πS,πR)\boldsymbol{\pi}=(\pi_S,\pi_R), πS+πR=1\pi_S+\pi_R=1. The first component gives 0.8πS+0.4πR=πS0.8\pi_S+0.4\pi_R=\pi_S, i.e. 0.4πR=0.2πS0.4\pi_R=0.2\pi_S, so πS=2πR\pi_S=2\pi_R. With πS+πR=1\pi_S+\pi_R=1 we get πS=23, πR=13\pi_S=\tfrac23,\ \pi_R=\tfrac13. Sunny two-thirds of the time.

Example
Worked example: a three-state absorbing chain

A token sits on states A,B,CA,B,C with CC absorbing:

P=[0121212012001].P=\begin{bmatrix} 0 & \tfrac12 & \tfrac12 \\[2pt] \tfrac12 & 0 & \tfrac12 \\[2pt] 0 & 0 & 1 \end{bmatrix}.

Starting at AA, what is the probability of eventual absorption at CC? (Here it is forced, so instead find the probability that the token visits BB before being absorbed.)

Solution. From AA the first move is to BB or CC with probability 12\tfrac12 each. It visits BB before absorption iff the very first step lands on BB (from BB the only escape is to CC eventually, but the “before absorption” visit is already secured). Hence P(visit BX0=A)=12P(\text{visit }B\mid X_0=A)=\tfrac12. To confirm absorption is certain, note CC is reachable from both AA and BB and is absorbing, so with probability 11 the token is eventually trapped at CC: powers PnP^n push all mass into column CC.

Tip

Tip. Rows of PP must each sum to 11 --- always sanity-check this first. Multi-step questions (nn days later, nn moves later) are PnP^n; “in the long run / eventually / steady state” questions are the stationary equation πP=π\boldsymbol{\pi}P=\boldsymbol{\pi}. Never confuse a single large power with the stationary vector unless the chain has actually settled.

Gambler's Ruin

Concept
Reaching NN before 00

A gambler holding $k\$k bets $1\$1 per round, winning with probability pp and losing with probability q=1pq=1-p, until reaching a target $N\$N (win) or $0\$0 (ruin). Let rkr_k be the probability of reaching NN before 00 starting from kk. Conditioning on the first bet (this is first-step analysis) gives the recurrence

rk=prk+1+qrk1,r0=0, rN=1.r_k=p\,r_{k+1}+q\,r_{k-1},\qquad r_0=0,\ r_N=1.

Solving this linear recurrence yields the classic formulas

rk={kN,p=q=12 (fair game),1(q/p)k1(q/p)N,pq (biased game).r_k=\begin{cases}\dfrac{k}{N}, & p=q=\tfrac12 \ \text{(fair game)},\\[10pt] \dfrac{1-(q/p)^k}{1-(q/p)^N}, & p\neq q\ \text{(biased game)}.\end{cases}

The fair case is a straight line in kk; the biased case is governed by the ratio q/pq/p.

Example
Worked example: fair game, doubling your money

You start with $50\$50 and play a fair game (p=12p=\tfrac12), quitting at $0\$0 or $100\$100. Probability you reach $100\$100?

Solution. With k=50k=50, N=100N=100, p=q=12p=q=\tfrac12:

r50=kN=50100=12.r_{50}=\frac{k}{N}=\frac{50}{100}=\frac12.

In a fair game the chance of hitting the target before ruin is just your current fortune as a fraction of the target --- no arithmetic beyond a ratio.

Example
Worked example: a slightly unfair game

A gambler starts at $1\$1, wants to reach $5\$5, and wins each $1\$1 bet with probability p=0.4p=0.4 (so q=0.6q=0.6, ratio q/p=32q/p=\tfrac32). Probability of success?

Solution. Use the biased formula with k=1, N=5, q/p=32k=1,\ N=5,\ q/p=\tfrac32:

r1=1(3/2)11(3/2)5=11.517.59375=0.56.593750.0758.r_1=\frac{1-(3/2)^1}{1-(3/2)^5}=\frac{1-1.5}{1-7.59375}=\frac{-0.5}{-6.59375}\approx 0.0758.

Only about 7.6%7.6\%. A small per-bet disadvantage compounds brutally over the distance to the target: fighting the house edge across many rounds is nearly hopeless. (Contrast the fair game, where the same k/N=15=20%k/N=\tfrac15=20\%.)

Tip

Big picture. Gambler's ruin is the template for every “random walk with two barriers” problem: set rkr_k for the boundary event, condition on the first step to get rk=prk+1+qrk1r_k=p\,r_{k+1}+q\,r_{k-1}, and impose the boundary values. The same recurrence machinery reappears in fair-coin streak problems, tennis deuce, and best-of-NN series.

First-Step Analysis & Conditional Expectation (Unit 9 Preview)

Concept
Condition on the first move to set up equations

First-step analysis solves “how long / how likely” questions on a chain by conditioning on the very first transition and using the memoryless property: after one step the problem looks like the same problem from the new state. This turns a hard infinite process into a small linear system.

For expected times it uses the tower property of conditional expectation,

E[T]=iE[Tfirst step to i]P(first step to i),E[T]=\sum_i E[T\mid \text{first step to }i]\,P(\text{first step to }i),

where reaching a new state ii contributes the 11 step already taken plus the expected remaining time Ei[T]E_i[T] from ii. Letting ek=E[steps to absorption from k]e_k=E[\text{steps to absorption from }k] typically yields a recurrence such as ek=1+pek+1+qek1e_k=1+p\,e_{k+1}+q\,e_{k-1} with e=0e=0 at absorbing states. This conditional-expectation viewpoint is the gateway to Unit 9.

Example
Worked example: expected flips to get two heads in a row

Let ee be the expected number of fair-coin flips to first see HH. Track states by current progress: S0S_0 (no useful streak), S1S_1 (one HH so far). Let a=E[flips from S0]a=E[\text{flips from }S_0], b=E[flips from S1]b=E[\text{flips from }S_1].

Solution. First-step analysis on each state:

a=1+12b+12a,b=1+120+12a.a=1+\tfrac12\,b+\tfrac12\,a,\qquad b=1+\tfrac12\cdot 0+\tfrac12\,a.

From the first equation 12a=1+12ba=2+b\tfrac12 a=1+\tfrac12 b\Rightarrow a=2+b. Substitute into the second: b=1+12a=1+12(2+b)=2+12bb=1+\tfrac12 a=1+\tfrac12(2+b)=2+\tfrac12 b, so 12b=2b=4\tfrac12 b=2\Rightarrow b=4, and a=6a=6. The expected number of flips is 6\boxed{6}. (The general pattern for a streak of nn heads is 2n+122^{n+1}-2.)

Example
Worked example: expected duration of a fair gambler's game

In the fair gambler's-ruin game (p=12p=\tfrac12), let eke_k be the expected number of bets until hitting 00 or NN from $k\$k. Find a formula.

Solution. Condition on the first bet:

ek=1+12ek+1+12ek1,e0=eN=0.e_k=1+\tfrac12\,e_{k+1}+\tfrac12\,e_{k-1},\qquad e_0=e_N=0.

Rewrite as ek+12ek+ek1=2e_{k+1}-2e_k+e_{k-1}=-2: the second difference is constant, so eke_k is quadratic. Trying ek=k(Nk)e_k=k(N-k) gives (k+1)(Nk1)2k(Nk)+(k1)(Nk+1)=2(k+1)(N-k-1)-2k(N-k)+(k-1)(N-k+1)=-2, which checks, and e0=eN=0e_0=e_N=0. Hence

ek=k(Nk).e_k=k(N-k).

Starting at the midpoint k=N/2k=N/2 the game lasts an expected N2/4N^2/4 bets --- surprisingly long. First-step analysis converts the recurrence directly into the answer.

Tip

Bridge to Unit 9. Everything here is one idea: condition on the first step, then reuse the structure of the problem. For probabilities it gives rk=prk+1+qrk1r_k=p\,r_{k+1}+q\,r_{k-1}; for expected times it gives ek=1+pek+1+qek1e_k=1+p\,e_{k+1}+q\,e_{k-1}. The tool is conditional expectation and its tower property, E[X]=E[E[XY]]E[X]=E\big[E[X\mid Y]\big] --- the central engine of Unit 9. Master first-step analysis now and expectation will feel like the same move applied to averages instead of probabilities.

Formulas, Proofs & Tips

Tip
Conditional probability and Bayes’ theorem
P(AB)=P(AB)P(B),P(AB)=P(BA)P(A)P(B)P(A\mid B)=\frac{P(A\cap B)}{P(B)},\qquad P(A\mid B)=\frac{P(B\mid A)P(A)}{P(B)}

What it means. Knowing BB happened shrinks the sample space to BB. Bayes reverses the conditioning.

Example. If P(AB)=0.1P(A\cap B)=0.1 and P(B)=0.5P(B)=0.5, then P(AB)=0.10.5=0.2P(A\mid B)=\tfrac{0.1}{0.5}=0.2.

Why it works. Once BB is known, only outcomes inside BB remain possible, so probabilities are rescaled by dividing by P(B)P(B). Bayes follows because P(AB)P(A\cap B) can be written two ways: P(AB)P(B)=P(BA)P(A)P(A\mid B)P(B)=P(B\mid A)P(A).

Tip. AA and BB are independent exactly when P(AB)=P(A)P(A\mid B)=P(A), i.e. P(AB)=P(A)P(B)P(A\cap B)=P(A)P(B).