Number of peaks in a random iid sequence Let $X_1,X_2,\ldots, X_\ell$ be a sequence of continuous iid random variables. Define a peak to occur at time $n$ if $X_{n-1}<X_n>X_{n+1}$. Then, how to show that as $\ell\rightarrow\infty$, the asymptotic proportion of times that a peak occurs is equal to $1/3$ with probability one (almost surely)?
 A: Since $X_i$'s are iid, by symmetry $X_{n-1}, X_n$, and $X_{n+1}$ are equally probable to be the maximum of the three. 
This means $X_n$ has a probability of $1/3$ to be a peak (first and last position excluded).
Define the Bernoulli random variable $Y_n$ to be $1$ if $X_n$ is a peak and zero otherwise. 
Then by the above argument we have $E[Y_n] = 1/3$. Let the number of peaks be $Z:=\sum_{n\le \ell} Y_n$.
 By the linearity of expectation, we have:
$$E[Z] = \frac{\ell-2} {3}$$ 
So the expected proportion of peaks tends to $1/3$.
It remains to show that the actual ratio (not just the expected value) almost surely tends to the $1/3 \ell$. Observe that $Y_n$'s are not generally independent. However, $Y_n$ and $Y_m$ are independent if $|m-n|\ge 3$. Let us partition the $Y_n$'s into three classes, each of size (roughly) $\ell/3$ based on the remainder of $n$ in division by three. Then within each partition the random variables are mutually independent. Let $Z_1, Z_2, Z_3$ be the sum of $Y_n$'s in the three partitions mentioned above. We can apply the Chernoff bound $\Pr\big[|Z_1-E[Z_1] | > t\big] < 2\exp(-6t^2/\ell)$ with $t = \sqrt{\ell \log \ell}$ to get 
$$\Pr\bigg[|Z_1-E[Z_1] | > \sqrt{\ell \log \ell}\bigg] < 2\ell^{-6}$$
The same argument holds for $Z_2$ and $Z_3$. Then, by the union bound, and the triangle inequality we get:
$$\Pr\bigg[\left|Z_1+Z_2+Z_3-E[Z_1+Z_2+Z_3] \right| > 3\sqrt{\ell \log \ell}\bigg] < 6\ell^{-6}$$
Note that $Z=Z_1+Z_2+Z_3$; hence:
$$\Pr\bigg[\left|Z-E[Z] \right| > 3\sqrt{\ell \log \ell}\bigg] < 6\ell^{-6}$$
Thus, with probability at least $1-6\ell^{-6}$ we have 
$$\frac{Z}{\ell}\in \left(\frac{\ell-2-3\sqrt{\ell \log \ell}} {3\ell}, \frac{\ell-2+3\sqrt{\ell \log \ell}} {3 \ell}\right)$$
Thus, the limit proportion is $1/3$ by the sandwich theorem. 
