How do I prove the runtime of an algorithm with Big O notation? I don't know much about O notation, I just I know how to compare sets of functions with each other and I'm also familiar with the master theorem.
But how do I do this? Is it just $O(n^2)$ because there are $2$ loops? That doesn't sound right. The loop in COUNTSMALLER doesn't have else so it's less expensive than the other one. I just know that cnt <- 0 is $O(1)$ but I don't know exactly about the loops. Am I supposed to do something with $T(n) = a T(n/b) + f(n)$? I could do that if you give me $a$ and $b$ but I have to idea how to get those or if this even makes sense.
This algorithm doesn't terminate if some elements are equal btw, I guess we can assume that all elements in the array $A$ are unique.
SORT(A)
1 i <- 1
2 while i < len(A) do
3 j <- COUNTSMALLER(i, A) + 1
4 if i = j then
5 i <- i + 1
6 else
7 A[i] <-> A[j]
8 end if
9 end while
COUNTSMALLER(i, A)
1 cnt <- 0
2 for j <- 1 to len(A) do
3 if A[i] > A[j] then
4 cnt <- cnt + 1
5 end if
6 end for
7 return cnt
```