Why is the complexity of a linear function the same as the quadratic equation

I am learning algorithms. So, I came up with something very interesting.

The asymptotic estimate of the linear equation ( (a*n)+b ) is O(n^2) .. for all a>0.

This is the same as not surprising. a* n^2 + b* n + c

Why?

+4
source share
1 answer

Because big-oh gives an upper bound. Your first function is also O(n^3), O(n^4), O(n^2012) , etc.

The definition of big-oh basically says that f(n) is O(g(n)) if there exists some k such that for all n > k we have g(n) > f(n) .

Check out big-theta for stronger / narrower boundaries.

+7
source

Source: https://habr.com/ru/post/1436969/


All Articles