---
title: "Timed Test 3"
book: "Interviews I: Maths, Probability and Speed"
subject: quant
language: en
chapter: 26
exercises: 0
source: https://one-course.com/books/quant/18/en/chapter/26-timed-test-3
license: CC-BY-NC-SA-4.0
credit: "One Quant Book, One Course (one-course.com)"
---

# Chapter 26 — Timed Test 3

Take it in one sitting, without notes or a calculator.

## Section A — 6 questions, 40 minutes

**Question 26.1.**

A cereal box holds one of three toys, with probabilities $\frac12$, $\frac13$ and $\frac16$, independently from box to box. On average, how many boxes do you buy to get all three?

**Answer to Question 26.1.**

The average is $7.3$ boxes.

Let $T_i$ be the wait for toy $i$. The time to get all is $\max T_i$, and inclusion–exclusion over minimums gives

$$
\mathbb{E}\max = \sum_i\frac{1}{p_i} - \sum_{i < j}\frac{1}{p_i + p_j} + \frac{1}{p_1 + p_2 + p_3}.
$$

The first sum is $2 + 3 + 6 = 11$. The pairs have $\frac56$, $\frac23$ and $\frac12$, which give $1.2 + 1.5 + 2 = 4.7$. The last term is 1. So the mean is $11 - 4.7 + 1 = 7.3$.

Sanity check: it must exceed 6, the wait for the rarest toy, and it does so by a little. Equal probabilities would give $5.5$, so uneven ones cost more.

**Classic wrong answer.** Using the equal-probability formula $3(1 + \frac12 + \frac13)$, which gives $5.5$.

**Question 26.2.**

Three fair dice are rolled. Which is more likely, a total of 9 or a total of 10? Give both probabilities.

**Answer to Question 26.2.**

A total of 10 is more likely: $\frac{27}{216}$ against $\frac{25}{216}$.

Both totals have six unordered partitions, which is why they can look equal. But the partitions have different numbers of orderings.

For 9: 126 (6), 135 (6), 144 (3), 225 (3), 234 (6), 333 (1), a total of 25.

For 10: 136 (6), 145 (6), 226 (3), 235 (6), 244 (3), 334 (3), a total of 27.

A check: by the symmetry $x \to 7 - x$, totals 10 and 11 have equal probability, as do 9 and 12. And an enumeration over the 216 outcomes confirms both numbers.

**Classic wrong answer.** Counting partitions as equally likely, which treats 333 like 126. The outcomes are the 216 ordered triples, and only they are equally likely.

**Question 26.3.**

A source sends four symbols with probabilities $\frac12$, $\frac14$, $\frac18$ and $\frac18$. What is the fewest expected bits per symbol of a prefix code? What is the entropy of the source?

**Answer to Question 26.3.**

Both are $1.75$ bits.

Huffman’s construction merges the two rarest symbols and repeats. It gives code lengths 1, 2, 3 and 3. The expected length is $\frac12 \cdot 1 + \frac14 \cdot 2 + \frac18 \cdot 3 + \frac18 \cdot 3 = 1.75$.

The entropy is $\sum p\log_2(1/p)$, with the same numbers, since each $\log_2(1/p)$ is an integer. So the code achieves the theoretical floor exactly.

Compare a fixed-length code, which takes 2 bits. The gain comes from using short words for frequent symbols.

**Follow-up.** *When does the code not reach the entropy?* When the probabilities are not powers of $\frac12$. For a source with probabilities $0.9$ and $0.1$, the code takes 1 bit a symbol, while the entropy is $0.47$. Coding blocks of symbols closes this gap.

**Question 26.4.**

$X$ is uniform on $[0, 1]$, and given $X$, $Y$ is uniform on $[0, X]$. What is the probability that $Y > \frac12$?

**Answer to Question 26.4.**

The probability is $\frac12(1 - \ln 2) \approx 0.153$.

Condition on $X = x$. For $x \le \frac12$, the event is impossible. For $x > \frac12$, it has chance $(x - \frac12)/x = 1 - \frac{1}{2x}$. So

$$
P = \int_{1/2}^1\left(1 - \frac{1}{2x}\right)dx = \frac12 - \frac12\ln 2.
$$

A second route uses the density of $Y$, which is $-\ln y$ on $(0, 1)$, found by integrating $1/x$ from $y$ to 1. Then $P = \int_{1/2}^1(-\ln y)\,dy = \frac12 - \frac12\ln 2$, the same.

The mean of $Y$ is $\frac14$, so a chance of $0.15$ to exceed $\frac12$ is reasonable.

**Classic wrong answer.** Using $X$’s mean, $\frac12$, as if $Y$ were uniform on $[0, \frac12]$, which gives 0. A value cannot replace a distribution here.

**Question 26.5.**

Two players take turns rolling a die, and A goes first. A wins by rolling a 6. B wins by rolling a 5 or a 6. What is the probability that A wins?

**Answer to Question 26.5.**

A wins with probability $\frac38$.

Each full round, A wins with chance $\frac16$. If A fails, B wins with chance $\frac13$. So the game continues to another round with chance $\frac56 \cdot \frac23 = \frac59$.

Let $a$ be A’s chance. Then $a = \frac16 + \frac59a$, which gives $a = \frac16 \cdot \frac94 = \frac38$.

A check: B’s chance is $\frac56 \cdot \frac13/(\frac49) = \frac58$, and the two add to 1. So going first is not enough to offset a target that is twice as easy. With equal targets of a 6, A would have $\frac{6}{11}$.

**Classic wrong answer.** Adding up only A’s first roll, or giving $\frac13$ by comparing the two chances directly, $\frac16/(\frac16 + \frac13)$. That ignores who rolls first.

**Question 26.6.**

Three vertices of a regular hexagon are chosen at random. How likely are they to form a right triangle? What about an equilateral triangle?

**Answer to Question 26.6.**

A right triangle has probability $\frac35$, and an equilateral one has probability $\frac{1}{10}$.

There are $\binom63 = 20$ triangles. The hexagon’s vertices lie on a circle, so a triangle has a right angle exactly when two of its vertices form a diameter. There are 3 diameters. Each can be combined with any of the 4 other vertices, which gives 12 triangles, all different, since a triangle cannot contain two diameters.

So the right triangles have $\frac{12}{20}$. The equilateral triangles are the two formed by alternate vertices, so $\frac{2}{20}$. The remaining 6 are isosceles with an obtuse angle: three neighbouring vertices. An enumeration confirms the counts.

**Classic wrong answer.** Trying to compute angles for each case. The diameter criterion gives the count at once.

## Section B — 6 questions, 60 minutes

**Question 26.7.**

A permutation of $1, \dots, 8$ is chosen at random. How likely is it that the element 8 lies in a cycle of length exactly 3? What is the expected number of cycles?

**Answer to Question 26.7.**

The probability is $\frac18$, and the expected number of cycles is $H_8 = \frac{761}{280} \approx 2.72$.

Follow the cycle from 8. It closes at the first step with chance $\frac18$, the value $\pi(8) = 8$. Otherwise it continues to another element, and closes at the next step with chance $\frac17$, and so on. The chance that it has length 3 is $\frac78 \cdot \frac67 \cdot \frac16 = \frac18$. All lengths from 1 to 8 are equally likely, by the same cancellation.

For the number of cycles, use that each element $i$ in a cycle of length $L_i$ contributes $1/L_i$, with total 1 per cycle. So the count is $\sum_i1/L_i$, and its mean is $8 \cdot \frac18(1 + \frac12 + \dots + \frac18) = H_8$. Counting by brute force over all permutations gives the same.

**Follow-up.** *What is the mean length of the cycle holding a given element?* $(n + 1)/2 = 4.5$, the mean of the uniform on 1 to 8. Note that this is larger than the average cycle length, $8/H_8 = 2.94$, an inspection effect.

**Question 26.8.**

A disease affects 1% of people, independently. You pool the blood of 10 people and test the pool once. If it is positive, you test all 10 individually. What is the expected number of tests per person?

**Answer to Question 26.8.**

About $0.196$ tests per person, a saving of about 80%.

The pool costs one test, or $\frac{1}{10}$ per person. With chance $1 - 0.99^{10}$, the pool is positive, and each person takes one more test. So the mean per person is

$$
\frac{1}{10} + 1 - 0.99^{10} = 0.1 + 0.0956 = 0.1956.
$$

For the value, $0.99^{10} \approx e^{-0.1} \approx 0.904$.

The best pool size balances the two terms: for $f(k) = 1/k + 1 - 0.99^k$, the minimum is near $k \approx 1/\sqrt{p} = 10$. An exact search shows that pools of 10 and 11 are almost the same. So 10 is a good design.

**Follow-up.** *If the rate rises to 30%, is pooling still useful?* Barely. A pool of 2 costs $1.01$ per person, the best pool, of 3, costs $0.99$, and larger pools cost more. So it no longer pays to bother.

**Question 26.9.**

You keep rolling a fair die and keep a running total. What is the probability that the running total ever equals exactly 6? What is the long-run chance of hitting a large number $n$?

**Answer to Question 26.9.**

The probability is $\frac16(\frac76)^5 \approx 0.360$, and for large $n$ it tends to $\frac27$.

Let $p_n$ be the chance of hitting $n$, with $p_0 = 1$. Conditioning on the last roll, for $n \le 6$,

$$
p_n = \frac16(p_{n - 1} + \dots + p_0).
$$

So $p_1 = \frac16$, and $p_{n + 1} = p_n + \frac16p_n = \frac76p_n$ for $n \ge 1$ up to 5. Thus $p_6 = \frac16(\frac76)^5$. An exact recursion in fractions gives this number.

For large $n$, renewal theory says that hits occur at a rate of one per mean step, and the mean step is $3.5$. So $p_n \to 1/3.5 = \frac27 = 0.286$.

Note that $p_6$ is the largest of the $p_n$: from 6 onwards, the bound on the number of earlier terms in the recursion takes effect.

**Classic wrong answer.** Enumerating the compositions of 6 and weighting each by $(\frac16)^k$. That works, but it is the slow form of the same answer.

**Question 26.10.**

A stick of length 1 is broken at a uniform random point, and the two pieces become the sides of a rectangle. What is the average area of the rectangle? How likely is the area to exceed $\frac{3}{16}$?

**Answer to Question 26.10.**

The average area is $\frac16$, and the area exceeds $\frac{3}{16}$ with chance $\frac12$.

With the break at $x$, uniform on $[0, 1]$, the area is $x(1 - x)$, whose mean is $\frac12 - \frac13 = \frac16$. The area exceeds $\frac{3}{16}$ when $(x - \frac14)(x - \frac34) < 0$, that is when $x$ lies between $\frac14$ and $\frac34$, and this has chance $\frac12$.

A check: the shorter piece $S$ has mean $\frac14$ and the longer $L$ has mean $\frac34$, with product $\frac{3}{16}$. But $L = 1 - S$, so their covariance is $-\operatorname{Var}(S) = -\frac{1}{48}$, and $\frac{3}{16} - \frac{1}{48} = \frac16$.

**Classic wrong answer.** Giving $\frac{3}{16}$, the product of the mean pieces, or $\frac14$, the area at the mean break. The first ignores that the pieces are negatively correlated, and the second is the largest area possible, reached by a single break point.

**Why it matters.** The mean of a product is the product of the means only without correlation. The average of price times volume is not the average price times the average volume.

**Question 26.11.**

An at-the-money three-month call on a stock at 100 with 16% volatility is worth about $0.4S\sigma\sqrt{T}$, with zero rates. Estimate the price of the straddle. What daily move makes a delta-hedged holder break even, using 252 days?

**Answer to Question 26.11.**

The straddle costs about $6.4$, and the daily break-even move is about 1, or 1%.

The call is worth $0.4 \times 100 \times 0.16 \times 0.5 = 3.2$. At the money with zero rates, put and call have the same value, by parity. So the straddle costs $6.4$.

The factor comes from $2\phi(0)\frac12 \approx 0.4$: the call is $S(2\Phi(\frac12\sigma\sqrt{T}) - 1)$, and it is linear in a small argument.

A delta-hedged option earns $\frac12\Gamma S^2(r^2 - \sigma^2\Delta t)$ per step, so it breaks even when the daily return equals $\sigma\sqrt{\Delta t} = 16\%/\sqrt{252} = 1.01\%$. That is the rule of 16: annual vol over 16 is the daily move.

**Classic wrong answer.** Comparing the $\pm 6.4$ break-even at expiry with daily moves. A hedged holder’s result depends on the sum of squared moves, not on where the stock ends.

**Follow-up.** *What does the straddle cost at one year?* $6.4 \times 2 = 12.8$, since the time scale doubles the root.

**Question 26.12.**

A random permutation of $1, \dots, 10$ is written in a line. A position is a local maximum if its value exceeds those of its neighbours, and each end has only one neighbour. How many local maxima are there on average?

**Answer to Question 26.12.**

The average is $\frac{11}{3}$.

Use indicators. An interior position, with two neighbours, has the largest of three random distinct values with chance $\frac13$. An end position, with one neighbour, has chance $\frac12$.

There are 8 interior positions and 2 ends, so the mean is $\frac83 + 1 = \frac{11}{3}$. Brute force for small $n$ follows the general formula $(n + 1)/3$.

The result is about one in three positions, which is the rate at which a random series makes a peak. So if a chart seems to have fewer turning points than this, the series has a trend or a memory.

**Follow-up.** *What is the count of runs of ascents, for $n = 10$?* The number of ascents has mean $4.5$, and maximal ascending runs number one more than the descents, so $5.5$ on average. These are the same indicators with pairs in place of triples.
