Let me describe the object before computing with it. X counts the tosses required, so X lives in one, two, three and so on, and the event X equals k is exactly one path: k minus one tails and then a head. The question asks for the expectation of that counting variable, which is a mean over an infinite support - not a probability of some event, which is the first place candidates slip.
There are three standard attacks and I will keep them visibly separate. Route A writes the mean as the series sum of k over two to the k - an arithmetic factor times a geometric one, an arithmetico-geometric progression - and sums it by shift-and-subtract. Route B conditions on the very first toss and gives a linear equation for the expectation. Route C adds up the tail probabilities.
I will take route A first, because that is what the question is really fishing for, and because the interesting part is not the algebra at all - it is the licence for the algebra. Then B and C, which never touch a series, so if A has a slip in the indexing or in the shift, the two will not agree.
One thing I will hold in mind and say out loud later: half of all runs stop on the first toss, so the median is one, and an answer of one would be a confusion of median with mean. I also note this is the same one-in-two, one-in-four world as the published Alice-and-Bob race question - but there the examiners asked who wins, which is the parity of this same first-head position, and here they ask how long you wait. Different functional of the same variable, so nothing from that treatment carries over except the coin.
To get k tosses I need k minus one tails, each with probability a half and independent, and then a head: so the mass at k is two to the minus k. Note the support starts at one, not at zero - I am counting tosses required, not tosses that failed - and that choice is what the whole indexing hinges on.
And I will not use a candidate law until I have checked that it really is one. The first eight masses run a half, a quarter, an eighth, all the way down to one two hundred fifty-sixth, and the running totals go one half, three quarters, seven eighths, and on to two hundred fifty-five two hundred fifty-sixths. The pattern is exactly one minus two to the minus n. The shortfall from one is nine point five three six seven four three times ten to the minus seven at twenty terms, and nine point zero nine times ten to the minus thirteen at forty. So the total is one: the experiment really does end.
Now the expectation is mass times value summed: the series I have to evaluate is one half plus two quarters plus three eighths plus four sixteenths. The multiplier k is arithmetic, the two to the minus k is geometric, hence the name arithmetico-geometric, hence the method: shift the series by one place and subtract, which kills the k.
Last line is insurance. If I had written the mass as two to the minus k minus one - the version that counts tails - the running mass would be one point nine nine nine nine nine eight after twenty terms and would head for two, not one. A distribution that weighs two is invisible in the final arithmetic unless you check the total, so I check it, and the same sloppiness would have handed me a mean of four.
I will draw it, because this distribution is a picture of a half, then a half of a half, and the shape carries information the algebra will not repeat. Each bar is half the one to its left, and eight bars already hold two hundred fifty-five two hundred fifty-sixths of the total, so almost all the probability is in the first few columns.
The first bar is the important one: exactly a half of all runs stop after a single toss. So the median is one by the smallest-value convention - though I will be precise, because two also satisfies the textbook inequalities here, a median is a boundary in this law, and that will matter when I report simulated medians.
The same bars give me the tail numbers I want as sanity anchors later: the chance of needing more than two tosses is a quarter, of needing at least ten is one in five hundred and twelve, of reaching twenty is about one point nine in a million, and past thirty it is nine point three times ten to the minus ten.
And here is what the figure proves rather than decorates: the expectation is the balance point of the bars. With a full half of the mass pinned at one and the rest trailing off to the right, the balance point is not one and not two-fifty-sixth-of-anything visible - it sits to the right of the tallest bar, which is exactly why the honest answer will be a number most runs never touch.
Here is route A. Write the mean as S, then write half of S on the line below and shift it one column to the right. That shift is the whole method, and it has a name in one phrase: displace, then subtract.
Now subtract the two lines column by column. In column k the top height is k over two to the k and the bottom height is k minus one over two to the k, the same denominator, so the gap in that column is exactly one over two to the k. The left side is S minus a half S, the right side is the plain geometric series a half plus a quarter plus an eighth, which sums to one. So a half S equals one and S equals two.
Before I go further, notice what I actually did: I never subtracted two infinite series. For a finite cutoff n the same two lines differ by the sum of one over two to the k up to n, minus one leftover term n over two to the n plus one, because the shifted row has a block hanging off the right edge. That identity is exact arithmetic - finite integers over finite powers of two - and it is numerically verified: at twenty terms the difference is zero point nine nine nine nine eight nine five zero nine five eight two five two zero and at forty terms zero point nine nine nine nine nine nine nine nine nine nine eight zero nine zero one.
Solving that finite identity gives S sub n as two minus n plus two over two to the n, and I checked it as an exact fraction for the first twelve values of n. So the shift-and-subtract partial sums are one point three seven five at three terms, one point seven eight one two five at five, one point nine eight eight two eight one two five at ten, one point nine nine nine nine seven nine zero one nine one six five zero three nine at twenty - short by two point one zero eight times ten to the minus five - and at forty terms one point nine nine nine nine nine nine nine nine nine nine six one eight zero one, short by three point eight two times ten to the minus eleven.
Then, and only then, I let n go to infinity on both sides, and the remainder goes with it, so the mean is two. Two is a limit here, not a tenth partial sum: reporting one point nine eight eight as the answer would be a computation of the first ten terms and nothing more.
Time to check the number against reality rather than against myself. I simulated actual coin tosses with a PCG64 generator, first seed five seven zero five seven zero, second seed one zero one zero five seven zero, each run tossed until the first head came up and stored with a cap of sixty-four tosses. The cap matters for honesty: the chance a run needs more than sixty-four tosses is five point four two times ten to the minus twenty, no run hit it in twenty-two million, and the bias it would introduce is two to the minus sixty-three of a toss. One disclosure about the design: the hundred-thousand-row cells are the first hundred thousand runs of the million-run stream at the same seed, so those three error bars are nested samples of one draw rather than three independent bites of apple.
Here are the means. First stream: two point zero zero one six four zero at a hundred thousand runs, one point nine nine nine nine six zero at a million, one point nine nine nine four six five at ten million. Second stream: two point zero zero eight eight nine zero, two point zero zero one four one nine, one point nine nine nine nine six nine. Against theory two, the standard errors are one point four one four two one three five six two four over root N, and I put the z on the board with every one of them: plus zero point three six six seven, plus one point nine eight seven nine, minus zero point zero two eight three, plus one point zero zero three four, minus one point one nine six one, minus zero point zero six nine five.
The largest of those is one point nine eight seven nine, at a hundred thousand runs in the second stream. I am not going to describe that as comfortably inside one standard error, because it is not inside one at all - it is nearly two. And I say which sd I divided by: the theoretical root two, which is finite, and the streams agree with it - empirical standard deviations one point four one four nine zero two and one point four one six three six three at a million runs, one point four one four three eight five and one point four one four two two four at ten million.
The error bars themselves need checking, because the usual slip is to say a tenfold sample halves the error. It does not: zero point zero zero four four seven two one four, zero point zero zero one four one four two one, zero point zero zero zero four four seven two one, and the ratio between neighbours is zero point three one six two two eight, which is one over root ten.
The event cells are the cheap test of the law itself, not just of the mean. The share of runs ending at one toss came out five hundred thousand three hundred twenty two and four hundred ninety nine thousand seven hundred twenty two, that is z of plus zero point six four four and minus zero point five five six against a half; needing more than two tosses gave minus zero point two five six and plus zero point six six three against a quarter; needing at least ten gave one thousand nine hundred thirty two and one thousand nine hundred seventy against an expected one thousand nine hundred fifty three point one two five, and the longest runs were twenty-one and twenty, with two runs at twenty or past it in each stream, which is what one point nine per million reaching twenty predicts.
One cell is past two standard errors and I will name it: at a hundred thousand runs in the first stream the rare cell had one hundred sixty eight hits against one hundred ninety five point three expected. Against the standard error built from the true probability that is minus one point nine five six, and against the one built from the observed frequency - which is seven per cent smaller here, zero point zero zero zero one two nine five versus zero point zero zero zero one three nine six - it is minus two point one zero nine. So the correct summary is: every mean cell inside two se, max one point nine nine, and one rare-event cell marginally outside; a single unlucky draw in a small-probability bin, not evidence against two.
Let me be the examiner on my own central step, because shift-and-subtract is exactly the place where correct answers get made by illegal moves. The rule is: you may subtract two series term by term once you have shown the two sides have limits, and you show it on the partial sums. That is what the second line does - it is an identity between finite quantities, nothing more, and it even keeps the leftover term n over two to the n plus one that the picture of the dashed block showed.
Only after that do I pass to the limit, and both sides have one: a minus two to the minus n goes to one, and n over two to the n plus one goes to zero. So half of the limit of S sub n is one, and the symbol S I used in beat 4 is just a name for that limit.
The rate is worth stating, because a hand-wave usually hides a plateau. The remainder is n plus two over two to the n, and consecutive remainders multiply by n plus three over two n plus four, which tends to a half: from nineteen to twenty it goes four point zero zero five times ten to the minus five to two point zero nine eight times ten to the minus five, and from thirty-nine to forty it goes seven point four six times ten to the minus eleven to three point eight two times ten to the minus eleven. A factor of about point five two near the start and about point five one there - a linear term divided by an exponential one, shrinking geometrically, never settling at a residue.
And the convergence itself is earned before any of it: the ratio of successive terms is k plus one over two k, tending to a half, so the series converges absolutely; and since every term is non-negative, the sum is the supremum of the finite partial sums by monotone convergence. That is the sentence that makes shifting, grouping and cancelling legitimate here - not a lucky feature of the number two.
Finally, the cautionary twin. Run the identical manipulation on the series with x equal to one - that is, on one plus two plus three plus four - and the partial sums are fifty-five, five thousand and fifty, five hundred and five thousand, five billion and five million at n equal to ten, a hundred, a thousand and a hundred thousand. There is no limit, so the two shifted rows are not two numbers and their difference is not a number. The minus one twelfth people quote from these exact steps is a regularisation of something else entirely. The method is licensed by the geometric factor being strictly inside one, and I would say that out loud even though this question never asks me to.
Now two checks that share no algebra with the series, because agreement between different kinds of argument is the only cheap insurance available on a whiteboard. Route B conditions on the first toss alone. Either a head, probability a half, and the total is one; or a tail, probability a half, one toss spent, and I am back where I began with the same law in front of me. So E equals a half times one plus a half times one plus E, that is one plus a half E, hence E equals two.
The bit worth marking here is why the same E reappears rather than a fresh unknown. Independence makes the future law identical after any finite string of tails, and the rules of this game care about the past through one fact only, that no head has landed yet - and E already prices that. So I state the renewal first, and only then do the arithmetic, which turns out to be the trivial part.
And I can see that fixed point is honest by iterating it: from zero the map E to one plus a half E runs one, one point five, one point seven five, one point eight seven five and on, with errors exactly a half, a quarter, an eighth, because the slope is a half; from five it comes down three point five, two point seven five, two point three seven five. Same limit from any start, so nothing in route B depends on where I began.
Route C is the one that explains the answer in a single visual line, so let me put it on the board. The mean is the sum over k of the tail probabilities starting at k equal to nought. The k equal to nought term is the probability that the run is longer than nought, which is one - every run pays its first toss, that is a whole unit of expectation on its own. The survivors, those needing more than one toss, contribute a half, then a quarter, then an eighth, and those add up to exactly one more. One plus one is two: that is why the mean is two and not one, even though half the runs are over at one. The partial sums run one, one point five, one point seven five up to two minus two to the minus n, short by nine point seven seven times ten to the minus four at n equal ten and nine point zero nine times ten to the minus thirteen at forty.
Two words of care on that route. It must start at k equal nought: starting at one gives exactly one, because the term you dropped was the toss everyone pays - and that off-by-one is the same slip as answering one. And the formula is not a trick peculiar to coins: I checked it on a uniform variable on one, two, three, four, where the mean is five halves and the tails are one, three quarters, two quarters, one quarter, summing to five halves as an exact fraction.
So the series, the linear equation and the tail ladder all say two, by three different kinds of argument. And note the failure mode they catch: if in route B you forget the toss the tail already spent you get E equal one, which is not merely wrong but impossible - the two lightest atoms alone give a mean of at least one point five - and the bars of beat three show that at a glance.
So the expected number of tosses is two, and I have it three times over: from the aligned subtraction, from a single linear equation, and from the tail ladder.
The series route has its own cross-check, which is a different operation rather than the same one run twice. Differentiate the geometric series one term at a time and you get the sum of k x to the k as x over one minus x squared, valid for x strictly inside the unit circle. At x equal to a half that is a half over a quarter, which is two - the same number, obtained by calculus instead of subtraction. Away from the coin it says the same thing and shows where the price is: at a third it gives zero point seven five, at four tenths one point one one one one one one one one one one, at nine tenths ninety, at ninety-nine hundredths nine thousand nine hundred. And the speed collapses near the edge: at nine tenths twenty terms only reach fifty-seven point one seven of the ninety, and at ninety-nine hundredths twenty terms reach a hundred eighty-three of nine thousand nine hundred.
Replace the fair coin by one that lands heads with probability p and nothing about the method changes: the shift factor is x equal to one minus p, the subtraction still leaves a plain geometric series, and the mean comes out one over p. Concretely: three tosses for a third, four for a quarter, six for a sixth, ten for a tenth, one point one one one one for nine tenths, one point zero one zero one for ninety-nine hundredths, and one for a two-headed coin, which is the correct trivial answer.
Now the part I would rather volunteer than be pushed into. The method dies in three distinct places and they die differently. First, x equal to one, which is p equal to zero: the partial sums of one plus two plus three are fifty-five, five thousand and fifty, and five billion and five million at n equal to ten, a hundred and a hundred thousand - there is no limit, one over p blows up, and the mean truly does not exist. Second, small p: the maths is still right but the check stops working, because the standard deviation is root one minus p over p, which is nine point four nine at p equal a tenth and ninety-nine point five at a hundredth, so the million-run error bar I quoted opens out to nine thousandths and a tenth of a toss. Third, and most generally, it is the geometric tail that does the work, not the arithmetic factor: swap it for a cubic power law and the mean still exists at one point three six eight four three two seven eight but the second moment grows like the log of the cutoff - six point two three at a thousand, eleven point nine seven at a million - so the variance does not exist and no plus-minus standard-error column could be written at all. For our coin the variance is two, finite, which is exactly the licence beat five spent.
If you want the spread as well: the same subtraction run twice more gives the second moment as six, so the variance is six minus four, which is two, and the standard deviation is root two, one point four one four two one three five six two four. The finite form is six minus n squared plus four n plus six over two to the n, which is four point four zero six two five at five terms and five point nine nine nine five three six five one four at twenty - convergence a good deal slower than the first moment's, and you can see why: squaring hands the tail more weight. The skewness is two point one two one three two zero three four three six, which is the reason a hundred thousand runs still produced a mean very nearly two standard-error units out in one stream.
And the second moment has a series-free derivation, which is a nice check of the check: the sum over k of two k plus one times the tail probability gives six point zero zero zero zero zero zero zero zero zero zero zero zero when summed to k equal four hundred. Different identity, same number.
The quantitative answer to is two typical is this. Runs needing ten or more tosses are about two in a thousand, but they hold one point zero seven four two one nine per cent of all the tosses thrown - in my million-run streams one thousand nine hundred thirty two runs carried twenty one thousand three hundred nineteen of two million tosses, and the other stream agreed at one point zero eight three eight eight one per cent. At twenty or past it the share drops to two thousandths of a per cent, so this mean is carried by the moderately long runs, not by monsters; that is a property of a geometric tail, and it is precisely what fails for the power-law example of the last beat.
Two more numbers answer the questions people usually ask next. After five tails the expected total is five plus two, so seven, and if I sum the conditional law directly it agrees, at seven point zero zero zero zero zero zero zero zero zero zero - the coin owes you nothing. Condition instead on a game that is forced to be short, and the mean drops the other way to eleven sevenths, one point five seven one four. And the quantiles tell you when you are likely to be finished: four tosses for ninety per cent, five for ninety-five, seven for ninety-nine, ten for ninety-nine point nine, fourteen for ninety-nine point nine nine.
Two small extensions if they are of interest. Truncate the experiment at n tosses and the mean is the tail ladder cut off, two minus two to the one minus n: one point nine three seven five at five, one point nine nine eight zero four six eight seven five at ten, the deficit being exactly one five hundred twelfth - which is the atom the cap creates, since anything at or beyond ten gets folded onto ten. And go for a second head instead of a first: the law becomes k minus one over two to the k, its mean sums to four point zero zero zero zero zero zero zero zero zero zero zero zero, which is two times one over p by additivity rather than by a new calculation, and summing my two independent simulated streams gives four point zero zero one three seven nine, z plus zero point six eight nine five against a standard error of two thousandths. Beyond that I would stop, because the question asked for the expectation and it is two.
Everything survives, and nothing needs a new idea. The mass at k becomes one minus p to the k minus one times p, the shift factor in the subtraction becomes x equal to one minus p, and the leftover geometric series has ratio x instead of a half, so the mean is one over p. Concretely three for a third, four for a quarter, six for a sixth, ten for a tenth, one point one one one one one one for nine tenths, one point zero one zero one zero one for ninety-nine hundredths, a hundred for a hundredth, and one for a two-headed coin.
Where it dies is worth naming twice, because the two deaths are different. At p equal to zero exactly, the geometric ratio is one, the subtraction has nothing to subtract, and no mean exists - one over p blowing up is not a rounding problem. And for small but positive p the answer is still exact while my beat five check would stop working: the standard deviation is root one minus p over p, nine point four eight six eight three three at a tenth and ninety-nine point four nine eight seven four four at a hundredth, so a million runs would come with an error bar of nine thousandths and a tenth of a toss instead of fourteen ten-thousandths.
The renewal route is the one that generalises cheapest: the same single equation E equals one plus one minus p times E gives one over p in one line, with no series touched at all. That asymmetry - the series generalising by algebra and the renewal by a sentence - is why I would hand the renewal as the proof and the series as the exercise.
Two is a good prediction for the long average and a poor one for any individual run, and the honest way to say that is with numbers. The variance is two, the standard deviation is root two, one point four one four two, so relative to its own size this variable has sd over mean of zero point seven zero seven one - the scatter of a single run is seven tenths of the mean, and its average distance from the mean is exactly one toss, half the mean. Neither is small next to an answer of two. The skewness is two point one two one three, so the distribution is heavily right-leaning: the mode and the conventional median are both one.
The quantiles are the practical answer. Ninety per cent of runs finish within four tosses, ninety-five within five, ninety-nine within seven, ninety-nine point nine within ten, and ninety-nine point nine nine within fourteen. So a run of two tosses is unremarkable, a run that reaches fourteen happens once in eight thousand, one that gets past fourteen once in sixteen thousand, and all of that is compatible with the mean being exactly two.
And the simulation puts that boundary between the mean and the typical run live. Across my six cells the empirical median read two four times and one twice, and that is not instability in the theory - it is just that both one and two satisfy the definition of a median here. The switch tracks the first-bar frequency exactly: zero point five zero zero three two two and zero point five zero zero two five zero, both of them above a half, gave a median of one, while zero point four nine eight nine eight zero, zero point four nine eight zero five zero, zero point four nine nine seven two two and zero point four nine nine nine four four gave a median of two. The mean never behaved like that; all six cells sat inside two standard errors.
No head is due, and the arithmetic of that is worth putting on the board rather than asserting. Given five tails, the total is five plus a fresh waiting time, so the conditional expectation is seven - and summing the conditional law directly does it too: given five tails the conditional mass is two to the minus, in brackets k minus five, for k from six upward, and k times that summed is seven point zero zero zero zero zero zero zero zero zero zero, so the shortcut and the grind agree. The unconditional expectation is still two at the start of any run, and the past contributes exactly the five you already spent.
The counting question has an amusing answer: the number of heads in a run is not random at all, it is identically one, because the experiment stops at the first one. So its expectation is one and its variance is zero. The number of tails is X minus one, which has expectation one and second moment three - so the two expectations coincide by accident and the spreads do not: the tails are the entire randomness.
If instead you are waiting for the second head, the law is genuinely different and the additivity shows up cleanly. The mass at k becomes k minus one over two to the k, its sum is one, and its mean is four - twice one over p, obtained by summing the two independent simulated streams which gave four point zero zero one three seven nine, a z of plus zero point six eight nine five against a standard error of two thousandths. That is the renewal argument earning its keep: two heads is two independent waits, no new series.
The cap creates a genuine atom, so it has to be priced rather than argued away. Capping at n tosses, the mean is the tail-sum cut off at the same place, which is two minus two to the one minus n: one point nine three seven five at five tosses, one point nine nine eight zero four six eight seven five at ten. The deficit from two is exactly one five hundred twelfth, which is the same one five hundred twelfth as the probability of needing ten or more - a nice identity, and both numbers were computed.
The leftover is not nothing and not somebody else's: with a hard cap, the event that no head appeared by ten tosses has probability two to the minus ten, nine point seven six five six two five times ten to the minus four, and those runs all sit on the value ten. That is why the capped mean is strictly below two - it underpays every run that would have gone long - and why the shortfall is the whole tail ladder beyond the cap - the sum over k from ten upward of the probability of needing more than k, which is two to the minus nine, twice the probability of exceeding ten because every further term halves.
Two consequences I would offer unprompted. First, the cap biases the mean downward in a systematic, computable way, so a capped simulation is not an unbiased estimator of two: at ten tosses the bias is one point nine five three per thousand, which is larger than the whole standard error of my million-run check, zero point zero zero one four one four. That is exactly the trap a careless Monte Carlo falls into, and it is why I capped at sixty-four instead, where the bias is two to the minus sixty-three. Second, if instead of stopping you restart, the renewal comes back and the mean returns to two as the solution of an equation, not as a limit.