Suppose you toss a coin $N$ times. What is the expected longest run of consecutive heads or tails in $N$ tosses?
e.g., suppose $N = 5$. If the sequence is HHTTT, then the longest length here is 3. If the sequence is HTHHT, then the longest length is 2.
I think this is a rather difficult problem. Is there a trick to get an answer easily for a generic $N$?
I attempted induction and failed. Here's what I tried.
Start with N = 1. The sequences are:
$$ H \\ T $$
Where $L(1) = 1 \implies E[L(1)] = 1$ and $L(N)$ is the longest consecutive number of heads or tails among $n$ tosses.
Then we consider $N = 2$. Each time we have a branching factor of 2, where we can "tack" on a "H" or "T" to the sequences for $N = 1$, so we have $$ HH \ HT \\ TH \\ TT $$
Here the $E[L(2)] = 0.25 * 2 + 0.25 * 1 + 0.25 * 1 + 0.25 * 2 = 1.5$.
Now for $N = 3$, we have $$ HHH \\ HHT \\ HTH \\ HTT \\ THH \\ THT \\ TTH \\ TTT $$
Here, $E[L(3)] = 1/8(3 + 2 + 1 + 2 + 2 + 1 + 2 + 3) = 2$. So based on this, I thought maybe we can induce $E[L(N)] = (N+1) / 2$.
but....for $N = 4$, we have $$ HHHH \\ HHHT \\ HHTH \\ HHTT \\ HTHH \\ HTHT \\ HTTH \\ HTTT \\ THHH \\ THHT \\ THTH \\ THTT \\ TTHH \\ TTHT \\ TTTH \\ TTTT $$
Here, $E[L(4)] = 1/16(4 + 3 + 2 + 2 + 2 + 1 + 2 + 3 + 3 + 2 + 1 + 2 + 2 + 2 + 3 + 4) = 2.375$
So $E[L(N)] = (N+1) / 2$ is not valid. So then I took a look at the realizations of $L(N)$, it appears that for each $N$, we have $2$ sequences with $L(N) = 1$ (obviously the alternating case) and $2$ sequences with $L(N) = N$ (obviously the all tails or all heads case). Then for $L(N) = 2$, it seems we have $2^{N - 1}$, and for $L(N) = 3$, we have $2^{N - 2}$.
e.g., for $n = 4$, when $L(N) = 3$, we have $2^{2}$ cases.
So in general, it seems we have that $L(N) = i$ with multiplicity $2^{N - i + 1}$ for $i = 2, \ldots, N$ and when $i = 1$, we have $L(N) = 2$.
So it seems we have $$ E[L(N)] = \frac{1}{2^N}\left(2 + \sum_{i=2}^{N} i 2^{N - i + 1} \right) $$
But this formula breaks for $n = 5$...For example, $L(5) = 3$ has 10 distinct cases $$ HHTTT \\ HTHHH \\ HTTTH \\ HHHTH \\ HHHTT \\ THHHT \\ THTTT \\ TTHHH \\ TTTHH \\ TTTHT \\ $$
At this point, I gave up.