terminology relating to o(1)

58 Views Asked by At

If someone says, for example, "I have an algorithm that runs in time $n^2+\varepsilon$ for any constant $\varepsilon>0$", the interpretation for this statement seems to be that for any constant $\varepsilon>0$, there is an integer $N$ such that for all $n>N$, the algorithm runs in time at most $n^2+\varepsilon$. This means that there is a sequence $\varepsilon_1=1/2$, $\varepsilon_2=1/4$, $\varepsilon_3=1/8$, etc along with associated integers $N_1 \leq N_2 \leq N_3 \leq...$

But does this not mean that the algorithm is $n^2 +o(1)$?

1

There are 1 best solutions below

8
On

Suppose $f(n) = O(n^{2+\epsilon})$ as $n \to \infty$ for all $\epsilon > 0$. Then $g(n) = f(n)/n^2 = O(n^\epsilon)$ for all $\epsilon > 0$; that is, for all $\epsilon > 0$ we can find $M_\epsilon, C_\epsilon > 0$ such that

$$ 0 \leq g(n) \leq C_\epsilon n^\epsilon \qquad \text{for } n \geq M_\epsilon $$

if we assume that $g(n) \geq 0$ for $n$ large enough. If we further assume that $g(n) \geq 1$ for $n$ large enough then we can find $N_\epsilon > 0$ such that

$$ 0 \leq \log_n g(n) \leq \log_n C_\epsilon + \epsilon \leq 2\epsilon \qquad \text{for } n \geq N_\epsilon. $$

Since $\epsilon$ was arbitrary we must have $h(n) = \log_n g(n) = o(1)$ as $n \to \infty$.

Now $g(n) = n^{h(n)}$, so we can write $g(n) = n^{o(1)}$ and hence $f(n) = n^{2+o(1)}$.

It should be noted that the assumption that eventually $f(n)/n^2 \geq 1$ is sufficient but not necessary to obtain this result.


We can obtain a slightly weaker statement using $O$ if we only assume that $f(n) \geq 0$ eventually, which I assume is the case you will be encountering when analyzing algorithms.

Let $N_1$ be the set of all $n$ such that $g(n) \geq 1$, and let $N_2$ be the set for which $0 \leq g(n) < 1$. Then

$$ g(n) \leq n^{\hat{h}(n)}, $$

where

$$ \hat{h}(n) = \begin{cases} \log_n g(n) & \text{if } n \in N_1, \\ 0 & \text{if } n \in N_2. \end{cases} $$

By the argument above we have $\hat{h}(n) = o(1)$ as $n \to \infty$, so we can write $g(n) \leq n^{o(1)}$. Thus

$$ f(n) \leq n^{2+o(1)} \qquad \text{as } n \to \infty, $$

or if you prefer, $f(n) = O(n^{2+o(1)})$ as $n \to \infty$.