Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you do addition/multiplication with Big O notations?

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 Θ .

like image 932
ThunderBalls Avatar asked May 11 '15 13:05

ThunderBalls


People also ask

What does Big O notation tell you about an algorithm?

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.

What is Big-O notation for polynomial time?

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.

Is Big-O notation an oxymoron?

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.

How do you find the Big O notation for the selectionsort function?

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.


1 Answers

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)

like image 157
DilithiumMatrix Avatar answered Sep 24 '22 19:09

DilithiumMatrix