I'm currently taking an algorithm class, and we're covering Big O notations and such. Last time, we talked about how
O (n^2 + 3n + 5) = O(n^2)
And I was wondering, if the same rules apply to this:
O(n^2) + O(3n) + O(5) = O(n^2)
Also, do the following notations hold ?
O(n^2) + n
or
O(n^2) + Θ (3n+5)
The later n is outside of O, so I'm not sure what it should mean. And in the second notation, I'm adding O and Θ .
What Big O notation doesn't tell you is the speed of the algorithm in seconds. There are way too many factors that influence the time an algorithm takes to run. Instead, you'll use Big O notation to compare different algorithms by the number of operations they make.
In Big-O notation we would say that the function is O ( n 2) (pronounced “O of n-squared”). We say that any algorithm with complexity O ( n c) where c is some constant with respect to n is polynomial time.
Algorithmic Complexity Made Simple — This Is NOT An Oxymoron! An algorithm’s performance depends on the number of steps it takes. Computer Scientists have borrowed the term ‘Big-O Notation’ from the world of mathematics to accurately describe an algorithm’s efficiency.
Assume the if statement, and the value assignment bounded by the if statement, takes constant time. Then we can find the big O notation for the SelectionSort function by analyzing how many times the statements are executed. First the inner for loop runs the statements inside n times.
At least for practical purposes, the Landau O(...)
can be viewed as a function (hence the appeal of its notation). This function has properties for standard operations, for example:
O(f(x)) + O(g(x)) = O(f(x) + g(x))
O(f(x)) * O(g(x)) = O(f(x) * g(x))
O(k*f(x)) = O(f(x))
for well defined functions f(x)
and g(x)
, and some constant k
.
Thus, for your examples,
Yes: O(n^2) + O(3n) + O(5) = O(n^2)
and:O(n^2) + n = O(n^2) + O(n) = O(n^2)
,O(n^2) + Θ(3n+5) = O(n^2) + O(3n+5) = O(n^2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With