medium · Waiting times for patterns in coin tosses
A fair coin is tossed repeatedly and independently.
Track only what a pattern needs next, which makes each chain two states.
For HH, let from a fresh start and the expected further wait after a head. From a fresh start the next toss is a head (move to the state) or a tail (start over):
From the state a head finishes and a tail sends you back to the start:
Substituting gives and , hence and .
For TH, let be the wait from a fresh start and the wait once a tail has appeared. The difference is in the state: a head finishes, and a tail leaves you exactly where you were.
So and .
HH overlaps itself: after a head, a tail destroys the progress you had made and returns you to the start. TH cannot overlap itself in that way — once a tail has appeared you are permanently one head away, and a further tail keeps you one head away. Progress toward TH is never lost, progress toward HH is, so HH waits longer. This is exactly the correlation term in Conway's leading-number algorithm: a pattern's expected waiting time grows with its self-overlap.
HH appears before TH if and only if the first two tosses are both heads, so the probability is .
The forward direction is immediate. For the converse, suppose the first two tosses are not HH. If the first toss is a tail, then TH completes at the very first head that appears, and no HH can have occurred earlier because every toss before that first head is a tail. If the first toss is a head and the second a tail, the same argument applies from the second toss onward. Either way TH comes first.
Note. Compare with HT, where the answer is : after the first head, the next toss decides between HH and HT immediately. Pattern races are decided by overlap structure, not by the individual pattern probabilities, and swapping one letter changes the answer.
medium · Maximum likelihood: Fisher information, exact bias, MSE
Let be i.i.d. exponential with rate , density for .
The log-likelihood is , with derivative , so
For one observation, has , a constant, so
Standard MLE asymptotics then give
Let (shape , rate ). For ,
so for and for . Since ,
The MLE overestimates the rate, for the reason Jensen's inequality predicts: is a strictly convex function of , so its mean exceeds . It is nonetheless consistent — the bias and the variance both vanish as .
Write , which is exactly unbiased. Using the moments above,
Comparing numerators, against , the unbiased version wins for every , by
Now optimize over the whole family . Its MSE is
a convex quadratic in minimized at , giving
smaller still. So the ranking is , then , then the MLE — and note that the optimal does not depend on the unknown , so this estimator is actually usable.
Note. Two lessons sit on top of each other here. The MLE's optimality is asymptotic, and at finite a deterministic rescaling beats it; and unbiasedness is not the objective, since the MSE-optimal member of the family is biased low on purpose. The tempting wrong answer is that must be best because it is the unbiased one.
Two new problems every morning at 8am · every day so far