2

I am thinking about the worst-case space complexity of an algorithm.

Obviously, if $f \in O(nm)$ then $f \in O(n+nm)$. But is the converse true?

$O(m)+O(nm) = O(m+nm) = O(m(1+n)) = O(m)O(1+n) = O(m)O(n) = O(nm)$

If that were true then $O(n+nm) = O(m+nm)$

Raphael
  • 72,336
  • 29
  • 179
  • 389
David
  • 33
  • 1
  • 6
  • 1
    Yes all that you have written is true including $O(n+nm)=O(m+nm)$ as $f\in O(n)\implies f\in O(nm)$ – User Not Found Jul 13 '17 at 03:58
  • If you are allowed to assume that $n,m \geq 1$, then all of these classes are equivalent. The fact that $f$ measures the worst-case space complexity of an algorithm is completely spurious here, however. – Yuval Filmus Jul 13 '17 at 05:25
  • 2
    Two-parameter Landau symbols are notoriously ill-defined and basically broken. Unless $n$ and $m$ have some functional relationship, i.e. you can look at only one limit process, the semantics are not at all clear, per se. – Raphael Jul 13 '17 at 05:31
  • 2
    @Raphael Would you mind adding a reference? I found a link to some paper by Howell, but it does not seem to have been published in a major CS journal or conference proceedings... – Mr Tsjolder from codidact Jul 13 '17 at 07:57
  • @MrTsjolder Some thoughts and references are given here and here. – Raphael Jul 13 '17 at 08:57
  • @Raphael, but they are used often enough. At least in graphs. – rus9384 Jul 13 '17 at 16:51
  • @rus9384 Yup, and most people (even profs) have no idea what they are doing there, trust me. If you would take an exam among TCS researchers about the intricacies of Landau notation, I'd expect F-rates similar to TCS exams they post for students. – Raphael Jul 13 '17 at 17:06
  • @Raphael, of course we could put $|V|^2$ instead of $|E|$ but it's not good. Using both $|V|$ and $|E|$ gives more info. And in this question answer is obvious, since $m,~n\in \mathbb{N}$. – rus9384 Jul 13 '17 at 18:32
  • @rus9384 It would give more info, if the notion would be well-defined. Notation without definition does not give any (rigorous) information. In the context of graphs, specifically, things can be saved. Generally, a case distinction over different relationships between the parameter helps (and are what people have in mind with multi-parameter O-s): $m = cn$, $m = c\sqrt{n}$, $m = cn^2$, and so on are ultimately different input scenarios; catching all of them in a plain $O$ is a fruitless endeavour. (Damn, I do need to write that book!) – Raphael Jul 13 '17 at 18:37
  • @rus9384 Anyway, I recommend you check out the questions I linked for MrTsjolder. In particular, Rutanen's work explains in much detail what goes wrong with $O$ in general; it's not the most easy read, though. – Raphael Jul 13 '17 at 18:37
  • @YuvalFilmus Thank you, it’s important to note $n,m \geq 1$. Thinking about space complexity I imagined our concern would be when the input values $n, m$ grow larger and larger in absolute values. When I wrote ‘$f$’ I meant a function defined with and algorithm. – David Jul 14 '17 at 21:49

1 Answers1

1

As mentioned in the question, obviously $O(nm) \subseteq O(n + nm)$ as $n,m \rightarrow \infty $.

The reverse is also true when $n, m$ grow ever larger:

For all $n,m \geq 1 : m +nm \leq nm+nm = 2nm$ and so: $O(m+nm) \subseteq O(nm+nm) = O(2nm) = O(nm)$ as $n,m \rightarrow \infty$.

$O(2nm) = O(nm)$ as $n,m \rightarrow \infty$ is a property of big-O that follows directly from the definition.

With respect to the penultimate line in the question (the long sequence of equalities), there is some unusual notation. To make sense there, the product of two sets must be an element-wise product such as $O(n) \cdot O(m) =\{fg ∣ f∈O(n), g∈O(m)\}$. The ‘$+$’ sign before the first equal sign probably means the Minkowski sum A+B={a+b ∣ a∈A and b∈B} instead of A∪B, but in both cases the first equality would hold.

David
  • 33
  • 1
  • 6
  • "O(nm) ⊆ O(n + nm) as n,m→∞" -- which definition makes this a meaningful statement? The common O has only one limiting process. – Raphael Jul 15 '17 at 07:31