This question is homework based (not using actual problem though)!

Say you have a function described as:

$$f(n) \in O(2n^2) \, .$$

Can you then go on the treat this as:

$$f(n) = 2n^2$$

and performs mathematics on it and keep its asymptotic meaning?

In the above case could I conjecture that $f(n) \in O(2n^2)$ implies $f(n) / 2 \in O(n^2)$ (assuming coefficients matter in this example)?

  • 6
    $\begingroup$ You would need to be very careful. Recall that O() is a set of functions. Taking one representative only might lead to false conclusions. $\endgroup$ – adrianN Sep 26 '16 at 15:00
  • 1
    $\begingroup$ "Can you then go on the treat this as:" -- no. "keep its asymptotic meaning" -- what do you mean by that? Some information carries over, some doesn't. "In the above case could I conjecture" -- you can conjecture whatever you want; what is interesting is whether you can prove anything. See here for how to prove asymptotic relations. You can also directly go to the definitions: what is the claim after unfolding $O$? What do you know about $f$ after unfolding $O$? Fill the space in between. $\endgroup$ – Raphael Sep 26 '16 at 16:12

For some operations, such as addition, multiplication, you can operate directly on the asymptotic notation. For example, if $\small g(n) = \mathcal{O}(n^2)$ and $\small f(n) = \mathcal{O}(n^2)$, then $\small g(n) + f(n) = \mathcal{O}(n^2)$ and $\small g(n) \cdot f(n) = \mathcal{O}(n^4)$. For some other operations, such as division, it depends then. For example, for $\small g(n) = \mathcal{O}(n^2)$ and $\small f(n) = \mathcal{O}(n^2)$, it is not correct to say $\small \frac{g(n)}{f(n)} = \mathcal{O}(1)$ (consider $\small g(n) = n^2$ and $\small f(n) = n$). However, if $c$ is a fixed constant, then $\small \frac{g(n)}{c} = \mathcal{O}(n^2)$.

| cite | improve this answer | |
  • $\begingroup$ is there some documentation on which operations are generally "allowed" for asymptotic notation? Or can you just infer that exponentiation is always allowed (multiplication), and logarithmic is dependent (division)? $\endgroup$ – Tyler Kelly Sep 26 '16 at 15:42
  • 3
    $\begingroup$ @user3470987 While there might be a list somewhere, you can also generate it on-the-fly. This is an excellent exercise. $\endgroup$ – Yuval Filmus Sep 26 '16 at 15:55
  • 1
    $\begingroup$ @user3470987 This is a matter of taste. People like me would advise you to never do this as it can easily lead to confusion and mistakes. $\endgroup$ – Raphael Sep 26 '16 at 16:13

To answer questions like your conjecture, use the definition of $O$. Paraphrasing from wikipedia at time of writing:

$f \in O(g)$ iff $f(x) \leq M\times g(x) $ for all $ x > x_0 $, for some constants $M$ and $x_0$.

So if $f(n) \in O(2n^2)$, then $f(n) \leq C \times 2n^2 \ \ \forall n > n_0$ for some constants $C$ and $n_0$ (I'm calling it $C$ instead of $M$ to avoid confusion later). You'll notice we can combine the $2C$ into one constant, which tells you $O(2n^2) = O(n^2)$.

What can we say about $f(n)/2$? We can now use normal algebra on the inequality, such as dividing both sides by 2 to get:

$f(n)/2 \leq Cn^2 \ \ \forall n > n_0$

Is this still $O(n^2)$? To check this, we need to find constants $M$ and $x_0$ such that the definition above holds. In this case, $M = C$ and $x_0 = n_0$ works. Notice that $M = 327.6C$ is also valid; you can use whatever method you want to find these constants, as long as you know they are constant.

In the real world you'll be able to "shortcut" most of this when doing your analysis, as NP-hard does in his answer, but those are just shortcuts for writing it out rigorously like this (which is what I would expect on homework specifically about $O$). If you're not sure whether it's valid, get the $O$s out by using the definition, perform algebra on the inequality, then get it back into $O$ by finding the appropriate constants (or simply showing that they do exist).

| cite | improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.