The result of O(f(n)) - O(f(n))

194 Views Asked by At

My question is in the field of the big-O-notation and complexity/asymptotic functions:

Probably something that I'm missing, but I've couldn't find any well explained solution for the following: What would be the result of:

(1) $O(f(n))-O(f(n))$?

Also, is the solution of $O(f(n))+O(f(n))$ is based on the same idea/rules of (1)

2

There are 2 best solutions below

0
On

The big-O classes are closed under addition/subtraction of functions, which is what I assume you mean (i.e. if two functions $g$ and $h$ are both $O(n^2)$ say, then so is $g+h$ and $g-h$ in general).

0
On

Typically in math, $O(f(n))$ is taken to be a set of functions. In this context, $O(f(n))-O(f(n))$ would be set-difference, which would obviously be $\emptyset$.

I feel like what you really meant to ask was, "If $f,g \in $O(h)$, is f-g \in O(h)$?" The answer is yes, which is simple to show:

$$f \le M*h \;\text{and}\; g \le N*h$$ $$f-g \le (M-N)*h$$

Note that if we change $O$ to $\Theta$, the answer is 'no,' since $f-g = 0$ when $g=f$