Algorithm Analysis
Last updated
Was this helpful?
Last updated
Was this helpful?
It is called as "f(n) is big-Oh of g(n)".
For example
is
is
is
is
initialization: O(1)
loop: O(n)
return: O(1)
To sum up, this algorithm has O(n) time complexity.
The running time of prefix_average1 is
This big-Oh notation is used widely to characterize running times and space bounds in terms of some parameter n. (prefix_average2 is also )
The above expression only has time complexity.
len(data): O(1)
data[j]: O(1)
Python's lists are implemented as array-based sequences.