Example of a function according to Big-Oh rules

I am having difficulty understanding the Big-Oh rules. For example , here is a question :

Find example of functions ( which are not negative ) $d(n),f(n),e(n),g(n)$ such that $d(n)$ is $O(f(n))$ and $e(n)$ is $O(g(n))$, but $d(n)-e(n)$ is not $O(f(n)-g(n))$.

can someone please explain how to solve such a problem?

-

Let $f(n)=3n^2 + n$ and $g(n)=3n^2$.

Take $d(n)= 2n^2= O(f(n))$ and $e(n)=n^2= O(g(n))$ as $n \to \infty$.

However, $d(n)-e(n)=n^2$ whereas $f(n)-g(n)=n$.

Therefore, $d(n)-e(n)$ is not $O(f(n)-g(n))$ as $n \to \infty$.

-
thanks , this is very clear and understandable –  Andy M Jan 24 '13 at 7:25
you are welcome! –  беркай Jan 24 '13 at 11:26

Try $d = n, e = 1, f = n, g =n$

-

Make the highest-order terms in $f(n)$ and $g(n)$ cancel. For example, $d(n) = 2n$, $e(n) = f(n) = g(n) = n$.

-