I was recently asked a question which I forgot the intuition for, so I wanted to write a post that approaches it from a few different perspectives and share how I got my intuition back. In the interest of entertaining myself I have reworded the problem with a ridiculous scenario that still preserves the mathematical statement of the problem.
Imagine you get into a high speed chase with the cops. You catch a lucky break and veer out of sight but end up crashing meters from the last location where the cops saw you. You proceed to get out of the vehicle and continue running away on foot, but in a state of shock, each stride you either take one step away from the cops with probability or accidentally take a step backwith probability .
Your safehouse is just 1,000 meters away from where the cops last saw you (), but if you take too many steps back you’ll end up being captured by the cops, who are looking for you at your last known location .
Assume the distance you cover in a single step is meters and you’re physically capable of taking steps as small as meters or as large as meters (you’re either superhuman or you have a collection of ender pearls in your inventory).
What step size should you take assuming you have infinite time, and will only get caught if you stumble to ?
Parameters:
I’ll lead with the intuition and a relatively simple argument first.
First Solution (Quick)#
The larger steps you take, the more variance you’ll experience per step. For example, if you bounce meters then you have a probability of getting arrested after just one step. On the other hand, if you take a small step like meters, you only move a little bit, but it’ll take you 1,000 steps to cover the same total distance (and I do mean distance in the physics sense of the word, not displacement).
For a given we know that the variance of your position increases with the number of steps, but for a given number of steps it decreases when you take smaller steps; so what we’re really trying to get at is the tradeoff between having more small steps versus fewer large steps. From the first example we considered it is already apparent that smaller steps are better for the first step, but we can build our intuition more by thinking about what happens when you take more and more smaller steps. Imagine taking the limit for a fixed distance traveled:
As you take smaller and smaller steps you have to take proportionately more steps to move the same distance. Your net displacement is the sum of these steps:
In the limit of infinitely many steps converges to the expectation value of a single step:
Hence your net displacement converges to:
which is just a number, not a random variable. In other words, in the limit of infinitely small steps you literally just walk in a straight line, never backtracking towards the police, which is ideal. The closest we can get to that based on the constraints is taking steps of meters, so we choose that as our preferred answer.
Let’s explore what this means from a highly related, but slightly different perspective. To reiterate, a walk is described by your initial position plus the cumulative sum of a sequence of random steps:
Each step is IID and can be expressed as:
where is sampled from a distribution that yields with probability or with probability . In other words each step has a variance proportional to , and the sum of steps has a variance proportional to:
Notice that shows up with a power of and shows up with a power of . Hence, when we take the limit of small steps, but keep the amount of distance traveled constant we fix a factor of , but the remaining keeps shrinking, collapsing the variance to 0.
Simulations#
Of course, when I needed it the most, I didn’t have the intuition above because I panicked. I was able to come up with the explanation above by doing my favourite past-time activity: writing up Monte Carlo simulations 😀
I generated 3 simulations of paths taken for each value of and plotted them in the figure below, along with the expected value . By adjusting the slider at the bottom of the figure you can switch between , and to see how the step size affects the ‘stability’ of escape attempts.
Interactive Monte Carlo Simulations: Effect of Step Size on Escape Probability
In-depth solution#
In this section I’ll share a more complicated solution which is how I originally understood this problem, but it’s too long and impractical to use in an interview setting unless you happen to memorize the final answer (which I never do).
Let’s forget about the original problem statement for now, and just treat it like a Markov process with absorbing boundary conditions at and . Fix the step size and define the grid of valid states as , where . As in the original prompt we’ll denote the probability of moving towards in a given step by , and we’ll let . For convenience, denote the probability of escaping the police, starting at state by . That is,
Trivially, at and we have,
Doing a ’next-step’ analysis, we observe that if you’re at state now, then after one step you will either be at or , at which point if we knew and then we could calculate as,
Using the fact that we can write the left hand side as
Subtracting the latter from the RHS yields
Now, if we define and introduce the inverse odds we can rearrange eqn (1) as
Induction then tells us
On the other hand, using the definition of we observe that . So, in combination with eqn (2) we have
To solve for we apply the boundary condition :
And so,
Eqn (3) can be used to solve our original problem. Since and we immediately see that taking smaller steps is equivalent to sending $m$ and $N$ to infinity at the same rate, so
And clearly we should pick the smallest possible value of permitted.