Space Basketball Probability

This comic was posted by xkcd last friday:

I thought I’d estimate the number of throws needed to make 30 shots in a row. How long will this take?

A coin flipping problem

This problem is pretty much the same as the following coin flipping problem: What is the expected number of coin flips needed before you get N consecutive tails?

This is a pretty well-known problem, and google will tell you a lot. The only difference is the probability of success (50% for a fair coin, and 30% for a free throw), but let’s start simple.

 

Expected number of flips before getting one tail

Let’s start with getting a single tail. Intuitively, we should expect 2 flips are needed on average to get a tail, but let’s work it out.

The expected value E is the weighted average over possible outcomes, weighted by the odds of each outcome. In this scenario, the number of flips required could be k = 1, 2, 3, 4, … and so on. For each number of flips k required, we then figure out the odds of that outcome:

  • k = 1: These are the odds of getting tail at the start. The probability is 1/2.
  • k = 2: These are the odds of getting head, then tail. This comes out to (1/2)(1/2) = 1/4.
  • k = 3: These are the odds of getting head, head, then tail. This is $(1/2)^3 = 1/8$.
  • $\ldots$

Following the pattern, if you require exactly $k$ flips then you had $k-1$ heads followed by a tail, and the odds of this are $(1/2)^k$. The expected value is then the sum \begin{align*} E &= \sum_{outcome} ({\rm outcome})*({\rm odds}) \newline &= \ \ \sum_{k = 1}^{\infty} k (1/2)^k \newline &= 1 \cdot \frac{1}{2} + 2 \cdot \frac{1}{4} + 3 \cdot \frac{1}{8} + 4 \cdot \frac{1}{16} + … \end{align*} This is a known variant of the geometric series. The general sum can be expressed as \begin{align*} \sum_{k = 1}^{\infty} kx^k = \frac{x}{(x-1)^2} \end{align*} valid for all $|x| < 1$. Setting $x = 1/2$ then gives $E = 2$.

So, our initial guess was right: you’d expect to need 2 flips before getting a tail.

 

Expected number of flips to get two consecutive tails

Let’s consider a slightly more complex case. This time, we want the expected number of flips before getting two tails in a row.

Just as before we could list all possible scenarios, with the odds of each scenario, and take the weighted average. Instead, we will use a nice trick to simplify our calculations: if you fail after one or two flips, then your expected number E of flips increases by that amount!

To see what this means, let’s run over the possible scenarios but only for the first two flips:

  • If the first flip is head, then your expected value at this point is $E+1$. This happens with probability 1/2.
  • If the first flip is tail, and then head, then your expected value becomes $E+2$. This happens with probability 1/4.
  • If your first two flips are tail, then you are done. This happens with probability 1/4.

Since this covers all possible outcomes, the expected value can then be computed as the sum of expected values for each outcome, weighted by the odds of that outcome. This gives
\begin{align*} E &= \frac{1}{2}(E+1) + \frac{1}{4}(E+2) + \frac{1}{4}(2). \end{align*} This simplifies to \begin{align*} E &= (\frac{1}{2} + \frac{1}{4})E + (\frac{1}{2} + \frac{2}{4} + \frac{2}{4}) \newline &= \frac{3}{4}E + \frac{6}{4}. \end{align*} Solving gives $E=6$. So we’d expect about 6 flips before seeing two consecutive tails.

 

Expected number of flips to get N consecutive tails

We can use the same trick as above to go from $2$ to $N$. This time, we look at the possible scenarios for the first N flips and the expected value of each scenario.

If your coin flips start as:

  • a head, then your expected value becomes $E+1$. The odds of this are 1/2.
  • a tail, followed by a head, your expected value becomes $E+2$. The odds are 1/4.
  • tail, tail, then head, then your expected value becomes $E+3$. The odds are 1/8.
  • (N-1) tails, then head, then your expected value becomes $E+N$. The odds are (1/2)^N.
  • N tails, then you’re done. The odds of this are also (1/2)^N.

Summing up the expected value of each outcome, we obtain

\begin{align*} E &= \frac{1}{2}(E+1) + \frac{1}{4}(E+2) + \frac{1}{8}(E+3) + … + \frac{1}{2^N}(E+N) + \frac{1}{2^N} N. \end{align*}

Collecting terms, this simplifies to \begin{align*} E = \left(\sum_{k=1}^N \frac{1}{2^k}\right) E + \left( \sum_{k=1}^N \frac{k}{2^k} \right) + \frac{1}{2^N} N.
\end{align*}

As before, these sums are variants of the geometric series. Their general values are \begin{align*} &\sum_{k=1}^N x^k = \frac{x^{N+1} - 1}{x-1}\newline &\sum_{k=1}^N kx^k = \frac{(Nx - N - 1)x^{N+1} + x}{(x-1)^2}. \end{align*}

Setting $x = \frac{1}{2}$ and solving for $E$ gives $E = 2^{N+1} - 2$. Hence we should expect to flip on average $2^{N+1} - 2$ coins before getting $N$ consecutive tails.

As we see the number of coin flips needed grows rapidly with $N$. Here are the first six values:

 

Back to Space Basketball

We can use a similar logic to solve our original problem. In the coin problem the odds of success/failure were 50%/50%, while our free throw success/failure rates were 30%/70%.

In general, denote by

  • p: the chance of success for free throws.
  • q: the chance of failure for free throws.

In our setting these values are $p = 0.30$ and $q = 1 - p = 0.70$.

Let’s compute the expected number E of free throws needed to make N shots in a row. Like the previous case, we can break down the expected value in terms of what happens on the first $N$ throws:

  • If the 1st throw is a failure, then the expectation becomes $E+1$. The odds of this are $q$.
  • If we get success, then failure, the expectation is $E+2$. The odds of this are $pq$.
  • If we get success, success, then failure, the expectation becomes $E+3$ with odds $p^2q$.
  • If we get (N-1) successes then failure, the expectation is $E+N$ with odds $p^{N-1}q$.
  • If we get N successes, we are done. The odds of this are $p^N$.

The expected value $E$ is again the sum of expectations over all outcomes, weighted by the odds of each outcome. In other words,

$$ E = q(E+1) + pq(E+2) + p^2q(E+3) + … + p^{N-1}q(E+N) + p^N N. $$

Solving this using the same technique as above (and remembering $q = 1 - p$), we obtain

$$ E = \frac{1-p^N}{p^N(1-p)}. $$

Now, our free throw accuracy is 30%, and so our expected number of shots before getting N=30 consecutive shots in is roughly

$$ E \approx 6.93848×10^{15} = 6,938,480,000,000,000.$$

A non-starter.

Kawhi Leonard is listed as having free throw accuracy of 88.9% this season. His expected number of shots to make 30 in a row, for comparison, is about

$$ E \approx 298 $$

which is way more manageable.

We can get professional player stats for the 2020 Basketball season from various sites. For example, the average NBA player had a free throw success rate of 77.1% in the last season. Collecting a few players, we can see how long each player needs to make 30 shots in a row.

player free throw success rate expected value
Devin Booker 0.916 154
Kawhi Leonard 0.889 298
Kyle Lowry 0.861 634
Average NBA Player 0.771 10675
LeBron James 0.697 166558