St · Statistics & Probability

How to Find the Expected Squared Distance in a Random Walk

Published By the 9to5Science editorial team

At a glance

  1. 1. Define distance

    Specify the graph, the distance measure, and the random walk’s starting state or distribution.

  2. 2. Find transition probabilities

    Use the transition matrix to determine the probability of being at each vertex after the chosen number of steps.

  3. 3. Square distances

    Measure each possible endpoint’s distance from the reference vertex, then square that distance.

  4. 4. Take the expectation

    Multiply each squared distance by its endpoint probability and add the results.

“Expected value of the distance square” is not a unique quantity: you must specify what is moving, how distance is measured, and what the distance is measured from. A common graph-theory interpretation is the expected squared graph distance from the starting vertex to the position of a random walker after a fixed number of steps.

For that interpretation, find the probability of ending at each vertex, square its distance from the start, and take the probability-weighted sum. The method also applies to other random processes once you identify their possible outcomes and distances.

Expected squared distance on a graph

Let a random walk start at vertex uu, and let XnX_n be its position after nn steps. Write d(u,v)d(u,v) for the graph distance between vertices uu and vv: the number of edges in a shortest path. The quantity of interest is

E[d(u,Xn)2]=∑vPr⁡(Xn=v) d(u,v)2.\mathbb{E}\big[d(u,X_n)^2\big] =\sum_{v} \Pr(X_n=v)\,d(u,v)^2.

The square applies to the distance for each possible outcome before you take the expectation. In general,

E[D2]≠(E[D])2,\mathbb{E}[D^2] \ne \big(\mathbb{E}[D]\big)^2,

where D=d(u,Xn)D=d(u,X_n). In fact, E[D2]=Var⁡(D)+(E[D])2\mathbb{E}[D^2]=\operatorname{Var}(D)+(\mathbb{E}[D])^2.

Compute it using a transition matrix

For a finite, time-homogeneous Markov walk, encode the walk in its transition matrix PP, where PijP_{ij} is the probability of moving from vertex ii to vertex jj in one step. If the walk starts at uu, the probability of being at vv after nn steps is the (u,v)(u,v) entry of PnP^n. Therefore,

E[d(u,Xn)2]=∑v(Pn)uv d(u,v)2.\mathbb{E}\big[d(u,X_n)^2\big] =\sum_v (P^n)_{uv}\,d(u,v)^2.

The matrix-power formula assumes the walk is Markov and its transition probabilities are fixed over time. For a walk whose starting vertex is itself random, let α\alpha be its starting probability distribution. The probability distribution after nn steps is αPn\alpha P^n, so, provided every vertex with positive probability under αPn\alpha P^n is connected to a fixed reference vertex rr, the expected squared distance from rr is

∑v(αPn)v d(r,v)2.\sum_v (\alpha P^n)_v\,d(r,v)^2.

Worked example: a walk on a three-vertex path

Consider the path 00—11—22. A simple random walk moves to a uniformly chosen neighbor. Start at vertex 00 and take two steps.

The first step must go from 00 to 11. From 11, the walk moves to 00 or 22, each with probability 1/21/2. Thus

Pr⁡(X2=0)=12,Pr⁡(X2=2)=12.\Pr(X_2=0)=\frac12,\qquad \Pr(X_2=2)=\frac12.

The distances from the starting vertex 00 are d(0,0)=0d(0,0)=0 and d(0,2)=2d(0,2)=2. Squaring and weighting by the probabilities gives

E[d(0,X2)2]=12(02)+12(22)=2.\mathbb{E}\big[d(0,X_2)^2\big] =\frac12(0^2)+\frac12(2^2)=2.

For comparison, the expected distance is E[d(0,X2)]=12(0)+12(2)=1\mathbb{E}[d(0,X_2)]=\frac12(0)+\frac12(2)=1, whose square is 11, not 22. This illustrates why you must square each possible distance before averaging.

Common mistakes

  • Squaring the mean instead of taking the mean square. Compute ∑vPr⁡(Xn=v)d(u,v)2\sum_v \Pr(X_n=v)d(u,v)^2, not (∑vPr⁡(Xn=v)d(u,v))2\left(\sum_v \Pr(X_n=v)d(u,v)\right)^2.
  • Using the wrong distance. Graph distance counts edges in a shortest path. If vertices have coordinates and you mean straight-line distance, use the Euclidean distance instead; the calculation is still a probability-weighted sum of squared distances.
  • Ignoring the reference point or time. Distance after one step can differ from distance after many steps, and distance from the start differs from distance between two independently sampled positions.
  • Assuming every edge is equally likely. Uniform choice among a vertex’s neighbors defines the usual simple random walk. Weighted edges or other transition rules require their own transition probabilities.

If the intended quantity is the squared displacement of a one-dimensional or multidimensional walk, use the same expectation rule with the square of the displacement. For example, for a one-dimensional walk with position SnS_n, the squared displacement from the origin is Sn2S_n^2, so its expected value is E[Sn2]\mathbb{E}[S_n^2]. The distance convention and the walk’s step distribution determine how to evaluate it.

References

  1. Markov Chains
  2. Random Walks and Electric Networks

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