If I need to determine the algorithmic complexity of a process with a cost set by a given function, is it just a question of giving O(n^2 log n) – or whatever the big O happens to be?
Also, isn’t big O just going to be the highest order of any term in the polynomial? If I’m asked to give a derivation I’m not sure what to provide because it seems a little trivial.
Last question, if I need to give the operation count for an algorithm and it’s really straightforward – roughly like
array1, array2, array3 of size n
for i in n:
array2[i] = sqrt(array1[i])
array3[i] = array1[i]^2
For ‘operation count’ am I just counting up all my arithmetical operations and figuring out which ones (like sqrt) count as multiple operations, etc… Or can I just write that it’s O(n)?
The algorithmic cost of a process is the costs of all the components of the process. For example, using your example, we can decompose the costs of everything
This takes n time for each array, so a total of 3n time, which is in O(n).
This means that everything in the loop is multiplies by n.
This takes O(1) time. Why? Accessing an array element is constant time. Taking the sqrt is constant time. And setting the value of an array element is constant time. So the whole operation is constant time.
This takes O(1) time, for the same reasons as the previous operation.
So the whole running time is 3n + n * ( 1 + 1) (using rough math here, not exact), which is just in O(n) time. Does that help?
As for an actual derivation, there are specific techniques for this. Did you learn the precise mathematical definition of big-Oh notation?
This link describes the formal definition of big-Oh notation, and provides of an example of how to prove this stuff.