Finding the average time complexity for a max algorithm
Let $\small n = \mathsf{len}(L)$ and $\small t_n$ be the times that $\small \mathsf{max}$ is assigned a value. For $\small 0 \leq i &lt; n$, define a random variable $\small X_i$ as
$$
\small
X_i = \begin{cases}
1 &amp; \text{if } L[i] &gt; \text{$\mathsf{max}$ in the $i$-th iteration of the algorithm}\\
0 &amp; \text{otherwise}
\end{cases}
$$
Then we have
$$
\small
t_n = 1 + \sum_{i=0}^{n-1} X_i
$$ By linearity of expectation,
$$
\small
\mathbb{E}[t_n] = 1 + \sum_{i=0}^{n-1}\mathbb{E}[X_i]
$$
Observe that $\small X_i = 1$ if and only if $\small L[i] &gt; \max\{L[0], L[1], \cdots, L[i-1]\}$. Therefore
\begin{align}
\small
\mathbb{E}[X_i] = \Pr[X_i = 1]  =&amp;\small \sum_{v=1}^{100} \Pr[L[0] &lt; v, L[1] &lt; v, \cdots, L[i-1] &lt; v, L[i] = v] \\
\small= &amp;\small \sum_{v=1}^{100} \left(\frac{v-1}{100}\right)^i \cdot \frac{1}{100}
\end{align}
We thus conclude
\begin{align}
\small
\mathbb{E}[t_n] =&amp;\ \small  1 + \sum_{i=0}^{n-1}\sum_{v=1}^{100} \left(\frac{v-1}{100}\right)^i \cdot\frac{1}{100} \\
\small =&amp;\ \small 1 + \frac{1}{100}\sum_{v=1}^{100}\sum_{i=0}^{n-1}\left(\frac{v-1}{100}\right)^i \\
\small =&amp;\ \small 1 + \frac{1}{100}\sum_{v=1}^{100}\frac{1 - \left(\frac{v-1}{100}\right)^n}{1 - \frac{v-1}{100}} \\
\small\text{(for sufficiently large $n$)}\quad\quad\approx&amp;\ \small1 + \frac{1}{100}\sum_{v=1}^{100} \frac{1}{1 - \frac{v-1}{100}} \\
\small = &amp;\ \small 1 + \sum_{v=1}^{100}\frac{1}{101-v} \\
\small =&amp;\ \small 1 + H_{100}
\end{align}
where $\small H_{100}$ is the $\small 100$-th harmonic number.