St · Statistics & Probability

Closed Form for a 2D Random Walk Probability Distribution

Published By the 9to5Science editorial team

At a glance

  1. 1. Specify the walk

    Assume each step independently moves one unit north, south, east, or west, each with probability one quarter.

  2. 2. Check reachability

    A point (x, y) is reachable after n steps only if its Manhattan distance is at most n and the parities agree.

  3. 3. Count paths

    Choose how many steps are horizontal, then count their directions and the directions of the remaining vertical steps.

  4. 4. Divide by all paths

    Multiply the path count by 4 to the power negative n to get the probability.

A “2D random walk” can describe several different processes. Here, use the standard simple symmetric random walk on the square lattice: at each step, move one unit north, south, east, or west, with probability 1/41/4 for each direction. The steps are independent.

This model has a closed-form probability at every location after any fixed number of steps. The expression is a finite sum because the walk can use different numbers of horizontal and vertical steps to reach the same point.

The probability after n steps

Let Sn=(Xn,Yn)S_n=(X_n,Y_n) be the position after nn steps, starting at (0,0)(0,0). To reach (x,y)(x,y), suppose exactly aa of the nn steps are horizontal. The other n−an-a steps are vertical.

For the horizontal steps, the number east minus the number west must equal xx. Thus the number east is (a+x)/2(a+x)/2, and the number of ways to choose the horizontal directions is

(a(a+x)/2).\binom{a}{(a+x)/2}.

Likewise, the number of north steps must be (n−a+y)/2(n-a+y)/2, giving

(n−a(n−a+y)/2)\binom{n-a}{(n-a+y)/2}

ways to choose the vertical directions. There are (na)\binom{n}{a} ways to choose which step times are horizontal. Every complete sequence of nn directions has probability 4−n4^{-n}. Therefore,

Pr⁡(Sn=(x,y))=14n∑0≤a≤n,a≥∣x∣,n−a≥∣y∣,a≡x (mod 2),n−a≡y (mod 2)(na)(a(a+x)/2)(n−a(n−a+y)/2).\Pr(S_n=(x,y))=\frac{1}{4^n} \sum_{\substack{0\le a\le n,\\ a\ge |x|,\\ n-a\ge |y|,\\ a\equiv x\ (\mathrm{mod}\ 2),\\ n-a\equiv y\ (\mathrm{mod}\ 2)}} \binom{n}{a} \binom{a}{(a+x)/2} \binom{n-a}{(n-a+y)/2}.

The restrictions make each binomial coefficient meaningful. In particular, the number of horizontal steps must be at least ∣x∣|x|, and the number of vertical steps must be at least ∣y∣|y|. The parity conditions ensure that the horizontal and vertical steps can produce displacements xx and yy, respectively. When n≡x+y(mod2)n\equiv x+y\pmod 2, the vertical parity condition follows from the horizontal one.

An equivalent quick reachability test is

∣x∣+∣y∣≤nandn≡x+y(mod2).|x|+|y|\le n \quad\text{and}\quad n\equiv x+y\pmod 2.

If either condition fails, the probability is zero. If they hold, the sum above gives the probability.

Worked example: return to the origin after four steps

Find the probability of being at (0,0)(0,0) after n=4n=4 steps. The horizontal step count aa must be even, so the possible values are a=0,2,4a=0,2,4.

  • If a=0a=0, all four steps are vertical. There are (42)=6\binom{4}{2}=6 ways to take two north and two south steps.
  • If a=2a=2, choose the two horizontal times in (42)=6\binom{4}{2}=6 ways. The horizontal directions can be ordered in (21)=2\binom{2}{1}=2 ways, and so can the vertical directions. This gives 6⋅2⋅2=246\cdot2\cdot2=24 paths.
  • If a=4a=4, all four steps are horizontal, with (42)=6\binom{4}{2}=6 ways to balance east and west.

There are 6+24+6=366+24+6=36 successful direction sequences, out of 44=2564^4=256 equally likely sequences. Hence

Pr⁡(S4=(0,0))=36256=964.\Pr(S_4=(0,0))=\frac{36}{256}=\frac{9}{64}.

Another point: (1,1) after two steps

Here, one step must be horizontal and one vertical, so a=1a=1 is the only term. There are (21)=2\binom{2}{1}=2 choices for which step is horizontal, and both directions are then forced: east and north. Thus

Pr⁡(S2=(1,1))=242=18.\Pr(S_2=(1,1))=\frac{2}{4^2}=\frac18.

The two possible paths are east-then-north and north-then-east.

Common mistakes

Using the wrong step model. The formula above assumes exactly one cardinal direction is chosen at each step. In another common model, the horizontal and vertical coordinates each independently move by +1+1 or −1-1 on every tick. That walk moves diagonally on the square lattice, so it has a different distribution; its coordinates are independent, and each coordinate has a binomial distribution after shifting and rescaling.

Treating the coordinates as independent in the cardinal-direction model. At a fixed step count, a move allocated to the horizontal coordinate is not also a vertical move. The horizontal and vertical displacements are therefore not independent, even though the direction choices at different times are independent.

Ignoring parity. A walk cannot reach a point merely because its Manhattan distance is at most nn. Each step changes the parity of x+yx+y, so the parity of the endpoint must match the parity of nn.

Forgetting to count step positions. Counting only the possible horizontal and vertical direction sequences misses the choices of which times are horizontal. The factor (na)\binom{n}{a} accounts for those choices.

References

  1. Probability and Random Processes, Geoffrey Grimmett and David Stirzaker

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.