If you flip a coin $n$ times, what is the probability distribution of the longest "run" (sequence of consecutive heads or tails) which will occur? Or if that's not possible, what is the average?
I have tried everything I know of and have never been able to solve this... I wondered if someone would have any ideas.
I'm assuming the answer to this is known - it is related to the iconic "stats magic trick" where the professor tells which sequences of coin flips are real and which are human-created by looking at the length of the longest run (humans naturally switch too often).
As my "contribution" here are some computer simulations that got the average for the first few $n$ flips (I averaged over 100,000 trials): $$\begin{cases}n=1&1.0\\n=2&1.49856\\n=3&2.00221 \\n=4&2.37459 \\n=5&2.6846 \\n=10&3.66115 \\n=50&5.97501 \\n=200&7.98442 \end{cases}$$
Clarification: Given $n$ flips of a fair coin, what is the probability that the longest run is of length $k$? And (if that has no closed form) what is the average longest run?