Hexa Scholar

Simple random walk

A small gold clay figure stands on a dark tiled walkway, with gold footprints scattered around its tile and a few farther away.
Footprints around the starting tile, and a few farther out.

The question

A walker tosses a fair coin 100 times, stepping right on heads, left on tails. About how far from the start does it end?

Guess first, then run a thousand walks and see.

  1. 1 SeeGuess the distance, then run the walks.
  2. 2 TryLonger walks, and a coin that leans.
  3. 3 ProveBuild the proof, line by line.
  4. 4 ApplyEndpoints, diffusion and a roulette wheel.
Before you start · 3 quick checks on a mean, a variance and counting toss sequences, about 3 min

Two ideas before you start

2 ideas

A walk adds up coin tosses

Figure: the path of a walk over twelve coin tosses, with a dashed line at its end position. It needs JavaScript.

Tosses:

Sequence A: 7 heads 5 tails S₁₂ = 7 − 5 = 2

Each head moves the walker one step right, drawn as a step up, and each tail one step left, drawn as a step down. After n tosses its position is the number of heads minus the number of tails.

Exact definition

Steps. \(\xi_1, \xi_2, \dots\) are independent, and each equals \(+1\) or \(-1\) with probability \(\tfrac{1}{2}\): a fair coin, heads \(+1\) and tails \(-1\).

The walk. \(S_0 = 0\) and \(S_n = \xi_1 + \dots + \xi_n\) for \(n \ge 1\). The distance from the start after \(n\) steps is \(\lvert S_n\rvert\). The card shows three fixed sequences of 12 tosses, typed in by hand, not drawn at random.

Count the sequences

Figure: bars counting the toss sequences that end at each position, with the count above each bar. It needs JavaScript.

Tosses n:

n = 4: 2⁴ = 16 sequences most likely: S₄ = 0, 6/16

All head-and-tail sequences of n tosses are equally likely. Ending at k takes (n + k)/2 heads, so the bar at k counts the sequences with that many heads.

Exact definition

Distribution. \(S_n = k\) exactly when \(h - (n - h) = k\), where \(h\) counts the steps up, so \(h = (n + k)/2\). Each of the \(2^n\) sequences of steps has probability \(2^{-n}\), so

\[P(S_n = k) = \binom{n}{(n + k)/2}/2^n\]

when \(n + k\) is even and \(\lvert k\rvert \le n\), and \(P(S_n = k) = 0\) otherwise.

Fine print: names and the model

The walk on this page is also called the symmetric simple random walk on the integers. With a coin that lands heads with probability \(p \ne \tfrac{1}{2}\) it is a biased walk; 2 Try uses one.

\(S_n\) has the parity of \(n\): after an even number of steps the walker stands on an even position, after an odd number on an odd one. Every exact statement on this page assumes independent steps with fixed probabilities.

1 See

Guess, then run the walks

How the runner works

Each walk takes 100 steps of \(+1\) or \(-1\), each with probability \(\tfrac{1}{2}\), independently. The walks come from a fixed seed, seed 1, so the same walks come back on every visit. The runner holds 1,000 walks, and moving \(c\) rescores the walks already run. Check my band compares your \(c\) with the exact probabilities, which do not depend on the seed, so on a small set of walks the narrowest band that holds 95% of them can differ from the exact answer.

2 Try

Longer walks, and a coin that leans

A prediction first, then a quick guess. The explorer opens once you answer the guess.

A coin that leans

3 Prove

Why the squared distance averages n

Theorem

Assumptions. \(n \ge 2\) is an integer, and the steps \(\xi_1, \dots, \xi_n\) are independent, each equal to \(+1\) or \(-1\) with probability \(\tfrac{1}{2}\). The walk is \(S_n = \xi_1 + \dots + \xi_n\).

Conclusion.

\[\begin{aligned} \operatorname{E}[S_n] &= 0, \\ \operatorname{E}[S_n^2] &= \operatorname{Var}(S_n) = n, \\ \operatorname{E}[\lvert S_n\rvert] &\lt \sqrt{n}. \end{aligned}\]

So the root-mean-square distance from the start is exactly \(\sqrt{n}\), and the average distance is smaller. For one step the distance is 1 for sure, and the two agree.

Facts the proof uses.

  1. Linearity: \(\operatorname{E}[X + Y] = \operatorname{E}[X] + \operatorname{E}[Y]\) and \(\operatorname{E}[cX] = c\operatorname{E}[X]\) for random variables with finite means, independent or not.
  2. If \(X\) and \(Y\) are independent and have finite means, then \(\operatorname{E}[XY] = \operatorname{E}[X]\operatorname{E}[Y]\).
  3. If \(\operatorname{E}[X^2]\) is finite, then \(\operatorname{Var}(X) = \operatorname{E}[X^2] - (\operatorname{E}[X])^2\), and \(\operatorname{Var}(X) \ge 0\), with equality only when \(X\) is constant with probability 1. The lesson on expectation and variance proves the shortcut.

Each option is one step of the proof. Pick the one that is true for every \(n \ge 2\).

What else follows
4 Apply

Problems

Counting sequences, the theorem of 3 Prove and the box after it give every answer.

Key point For a fair walk, \(P(S_n = k)\) counts sequences: \(\binom{n}{(n + k)/2}/2^n\). For steps of \(+1\) with probability \(p\) and \(-1\) with probability \(q = 1 - p\), \(\operatorname{E}[S_n] = n(p - q)\) and \(\operatorname{Var}(S_n) = 4npq\). Distances grow like \(\sqrt{n}\): 100 times as many steps make the root-mean-square distance only 10 times as large.
Level Introductory Prerequisites expectation and variance; counting toss sequences is refreshed in Before you start Time ~35 min

Further reading