2
$\begingroup$

When analyzing the asymptotic running time of an algorithm where the tightest lower bound and upper bound are not the same, is it bad to denote the running time in theta notation? If an algorithm has a running time of $\Theta(n)$, is it safe to assume that the upper and lower bound are the same?

$\endgroup$
1

3 Answers 3

3
$\begingroup$

When analyzing the asymptotic running time of an algorithm where the tightest lower bound and upper bound are not the same, is it bad to denote the running time in theta notation?

Do you mean to say that we can only prove an $\Omega(f_1)$ and an $O(f_2)$ bound, respectively, on the same cost function (such as "worst-case running time)? Then yes: you can only use $\Theta(f_1) = \Theta(f_2)$ to combine the bounds if, well, $f_1 \in \Theta(f_2)$.

If you mean to say that best case and worst case have different growth rates, then that's a different issue: "lower bound" and "best case" as well as "upper bound" and "worst case" are not the same concepts! You can have $\Theta$-bounds for either case, but they still don't combine in a meaningful way since they are talking about different cost functions.

Also, if an algorithm has a running time of theta(n), is it safe to assume that the upper and lower bound are the same?

That's not a "safe assumption", that's the definition of $\Theta$.

I suggest you revisit the definitions of the different Landau symbols and the basics on how to use them in algorithm analysis. Maybe start reading at our reference question.

$\endgroup$
1
$\begingroup$

Often when describing running times of algorithms we leave out information that can usually be inferred. Typically you should include: Time Complexity (Landau Notation), Input Type (worst case, best case, average, etc.) and Machine Model (e.g. RAM). The last two are often inferred, but you should describe them in your case.

I suspect when you say "the asymptotic running time of an algorithm where the tightest lower bound and upper bound are not the same", what you really mean is "the asymptotic running time in the best case is not the same as the asymptotic running time in the worst case".

Imagine a simple function like this:

$$f(n) = c + n\cdot (n \bmod 2)$$

We can say the following:

  • $f(n) = O(n)$
  • $f(n) = \Omega(1)$

However, we could not concretely give a $\Theta(?)$ bound without more context. It would be more proper to say:

  • $f(n) = \Theta(n)$ in the worst case (or $f(n) = O(n)$ in the worst case)
  • $f(n) = \Theta(1)$ in the best case (or $f(n) = \Omega(n)$ in the best case)

The former of each statement is more precise and doesn't leave much room for error. The latter would also work but isn't as strict of an argument. I think this answer gives a good distinction on why a descriptive $\Theta(\cdot)$ should be preferred to an ambiguous $O(\cdot)$ or $\Omega(\cdot)$.

$\endgroup$
3
  • $\begingroup$ "I suspect when you say "the asymptotic running time of an algorithm where the tightest lower bound and upper bound are not the same", what you really mean is "the asymptotic running time in the best case is not the same as the asymptotic running time in the worst case"." -- why? Those are to very different statements. Unfortunately, I don't think your answer really explains why, if that's what you were intending. (The last list seems to support a popular misconception.) $\endgroup$
    – Raphael
    Commented Nov 8, 2017 at 6:53
  • $\begingroup$ On top of Raphael's comment, your function doesn't have the asymptotic behaviour you describe. $ f(n) = O(1) $ since it never grows above $ 1 $. $\endgroup$ Commented Nov 8, 2017 at 19:42
  • $\begingroup$ @cardobard_box, fixed it. I had the function imagined correctly in my head but wrote it down wrong. Basically it does $n$ work when $n$ is odd and constant work when $n$ is even. $\endgroup$
    – ryan
    Commented Nov 8, 2017 at 19:44
0
$\begingroup$

f(n) = ϴ(g(n)), if and only if:

  • f(n) = O(g(n)) (at the worst case f(n) performs an asymptotically equivalent of g(n) operations); and
  • f(n) = Ω(g(n)) (at the best case f(n) performs an asymptotically equivalent of g(n) operations)

So the answer to your second question is straightforward - yes, as it is the actual definition of the theta notation.

Regarding your first question, it would be inaccurate to denote the running time of such an algorithm in theta notation. In some cases, though, an algorithm may approximately perform as if it was bounded by a theta notation (meaning that only in extreme situations it performs otherwise). Still, you can't use the theta notation, unless your algorithm satisfies both conditions mentioned above.

$\endgroup$
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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