Running time of selection sort
The inner loop will iterate $n - r + 1$ times for each iteration of the outer loop. To find the total runtime, we can sum this expression over $r = 1$ to $r = n$:
\begin{align*}
\sum_{r = 1}^{n} (n - r + 1) &amp;= n^2 - \left(\sum_{r = 1}^{n} r\right) + n \\
&amp;= n^2 - \frac{n(n + 1)}{2} + n \\
&amp;= \frac{1}{2}n^2 + \frac{1}{2}n
\end{align*}
which is $\Theta(n^2)$.

To simplify the proof, we can note that the sequence $(n - r + 1)_{r \in [1, n]}$ is just the sequence $1, 2, \ldots, n$, which you can see by substituting $r = 1$ and $r = n$ into $(n - r + 1)$. We know that this sum $\sum_{i = 1}^{n} i$ equals $\frac{n(n + 1)}{2}$, giving the same result as the first method.