I am working with Big O and I got this exercise I am working on.
I know the first line is running in constant time. But I am confused on how to measure the while-loop.
I am working with Big O and I got this exercise I am working on.
I know the first line is running in constant time. But I am confused on how to measure the while-loop.
The outer loop runs $n$ times.
The inner runs $n-i-1$ times, and since $i \le n$, it runs at most $n$ times.
Therefore, the total is at most $n\cdot n = n^2$.
Actually, it is $n^2/2+O(n)$, but $O(n^2)$ is enough.