Subtraction of functions with BigO

4.3k Views Asked by At

When trying to assess the Big $O$ of two functions that are added together, we take the max of the two. What happens if there is subtraction instead of addiiton?

for instance: $$f(n) = O(n^3) $$ $$ \text{and} $$ $$g(n) = O(n^3)$$ then $$ (f-g)(n)$$

1

There are 1 best solutions below

0
On

Note that the sign of a function doesn't matter in $O $-notation:

If $f(n)\in O (h(n)) $ then $-f(n)\in O (h(n))$ follows directly from the definition of the $O $-Notation.

For two functions $f (n)\in O (h_1 (n)) $ and $g (n)\in O (h_2 (n))$ you know $$f(n)+g (n)\in O (\max (h_1 (n), h_2 (n))). $$ where in this case $\max (h_1 (n), h_2 (n))=h_1(n)$ means that $h_2 (n)\in O ( h_1 (n))$ respectively $\max (h_1 (n), h_2 (n))=h_2(n)$ means that $h_1 (n)\in O ( h_2 (n))$ .

Therefore, you can follow $$f (n)-g (n)=f (n)+ (-g (n))\in O (\max (h_1 (n), h_2 (n)))$$ since $-g (n)\in O (h_2 (n))$, too.