Here are a couple of useful points to help you understand how to find the complexity of a function.
- Measure the number of iterations
- Measure the complexity of each operation at each iteration
For the first point, you see the terminating condition is v < m
, where v
is 0 initially, and m
is the size of the list. Since v
increments by one at each iteration, the loop runs at most (at least) N
times, where N
is the size of the list.
Now, for the second point. Per iteration we have -
c.append(min(l))
Where min
is a linear operation, taking O(N)
time. append
is a constant operation.
Next,
l.remove(min(l))
Again, min
is linear, and so is remove
. So, you have O(N)
+ O(N)
which is O(N)
.
In summary, you have O(N)
iterations, and O(N)
per iteration, making it O(N ** 2)
, or quadratic.