2
$\begingroup$

I would like to know why the following statement

The running time of algorithm $A$ is at least $O(n^2)$

which means the best-case running time of $A$ is $O(n^2)$ is meaningless (CLRS page 53).

But the following is not

The worst-case running time of algorithm $A$ is $\Omega(n^2)$

(used in CLRS page 160).

$\endgroup$
  • 1
    $\begingroup$ "at least $O(...)$ never make sense. Also, I think you want to read this. $\endgroup$ – Raphael Mar 5 '17 at 9:02
8
$\begingroup$

First of all, both sentences are a slight abuse of notation. $\mathcal{O}(n^2)$ and $\Theta(n^2)$ are sets; strictly speaking you can't compare a running time with a set. Saying "$f$ is $\mathcal{O}(g(n))$" is actually a shorthand for "$f$ belongs to the set $\mathcal{O}(g(n))$"; with that in mind, we can rephrase the statements you quote as follows:

The running time of $A$ is at least $f(n)$ for some $f \in \mathcal{O}(n^2)$.

and:

The worst-case running time of $A$ is at least $f(n)$ for some $f \in \Omega(n^2)$.

Put in this form, the first statement is well-defined, but it's not really insightful. In fact, it is always true. Let $g$ be the constant function $0$. Certainly $g$ is a member of $\mathcal{O}(n^2)$, and whatever the running time of $A$ is on input of size $n$, it is at least $g(n)$.

Intuitively speaking, big-oh is an upper bound: if I tell you: "I have at least $100 or less", I didn't really give you any information at all.

On the other hand, the second statement guarantees that the worst-case running time of $A$ cannot be too low: it must grow at least quadratically.

$\endgroup$
  • $\begingroup$ @DavidRicherby True, I didn't mean to imply that it's a mistake to say so, but at the same time I felt it was important to unwind the intermediate step. It was a poor choice of words, I'll edit my answer. $\endgroup$ – quicksort Mar 6 '17 at 16:30
  • $\begingroup$ Fair enough -- no objection to the edited version. $\endgroup$ – David Richerby Mar 6 '17 at 16:46
1
$\begingroup$

Saying that

The running time of the algorithm is at least $O(n^2)$

is pointless since it does not describe what could be neither the average case nor the worst one. Hence you would classify in the same complexity class algorithms which have very different worst case behaviors say polynomial wrt. exponential. In the second statement saying

The worst-case running time is $\Omega(n^2)$

is precise since it allows to put in the same class only algorithms that are really uniform with respect to their computational complexity.

$\endgroup$
1
$\begingroup$

The short intuitive answer is that the big-O notation is used to express upper bounds on (e.g) runtime. Saying that the runtime is 'at least (some upper bound)' is peculiar and confusing - you are saying an upper bound is really a lower bound.

$\endgroup$

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.