Another way of doing big O notation

2025-11-02·Alok Singh·548 words
Contents

I had a fun talk about this with an interviewer once when they asked me about the runtime complexity of some algorithm.

Let ff and gg be eventually positive functions from ℝ≥0\mathbb{R}_{\ge 0} to ℝ>0\mathbb{R}_{>0}. Pick an unlimited hypernatural H∈ℕ∗∖ℕH\in{}^*\mathbb{N}\setminus\mathbb{N} (we write H≫1H\gg 1 for short), and look directly at the ratio f∗(H)g∗(H).\frac{ {}^*f(H) }{ {}^*g(H) }.

Then the big O relations become simple checks on f∗(H)g∗(H)\frac{ {}^*f(H) }{ {}^*g(H) }, and we require that the condition holds for every unlimited HH:

We have f∈O(g)f\in O(g) if and only if there exists a standard constant C>0C>0 such that f∗(H)g∗(H)≤C\frac{ {}^*f(H) }{ {}^*g(H) } \le C. In math: f∈O(g)⟺∃standard C>0:f∗(H)g∗(H)≤C.f\in O(g)\ \iff\ \exists\ \text{standard } C>0:\ \frac{ {}^*f(H) }{ {}^*g(H) } \le C.

We have f∈Ω(g)f\in \Omega(g) if and only if there exists a standard constant c>0c>0 such that f∗(H)g∗(H)≥c\frac{ {}^*f(H) }{ {}^*g(H) } \ge c. In math: f∈Ω(g)⟺∃standard c>0:f∗(H)g∗(H)≥c.f\in \Omega(g)\ \iff\ \exists\ \text{standard } c>0:\ \frac{ {}^*f(H) }{ {}^*g(H) } \ge c.

We have f∈Θ(g)f\in \Theta(g) if and only if there exist standard constants 0<c≤C<∞0<c\le C<\infty such that c≤f∗(H)g∗(H)≤Cc\le \frac{ {}^*f(H) }{ {}^*g(H) } \le C. In math: f∈Θ(g)⟺∃0<c≤C<∞standard:c≤f∗(H)g∗(H)≤C.f\in \Theta(g)\ \iff\ \exists\ 0<c\le C<\infty\ \text{standard}:\ c\le \frac{ {}^*f(H) }{ {}^*g(H) } \le C.

We have f∈o(g)f\in o(g) if and only if f∗(H)g∗(H)≈0\frac{ {}^*f(H) }{ {}^*g(H) } \approx 0 (that is, the ratio is infinitesimal). In math: f∈o(g)⟺f∗(H)g∗(H)≈0.f\in o(g)\ \iff\ \frac{ {}^*f(H) }{ {}^*g(H) } \approx 0.

We have f∈ω(g)f\in \omega(g) if and only if f∗(H)g∗(H)\frac{ {}^*f(H) }{ {}^*g(H) } is unlimited. In math: f∈ω(g)⟺f∗(H)g∗(H) is unlimited.f\in \omega(g)\ \iff\ \frac{ {}^*f(H) }{ {}^*g(H) } \text{ is unlimited}.

Examples

For f(x)=x2f(x)=x^2 and g(x)=x3g(x)=x^3, we compute f∗(H)g∗(H)=1/H\frac{ {}^*f(H) }{ {}^*g(H) } = 1/H, which is infinitesimal. Therefore x2∈o(x3)x^2\in o(x^3). In math: f(x)=x2,g(x)=x3:f∗(H)g∗(H)=1/H≈0⇒x2∈o(x3).f(x)=x^2,\ g(x)=x^3:\ \frac{ {}^*f(H) }{ {}^*g(H) } = 1/H\approx 0\ \Rightarrow\ x^2\in o(x^3).

For f(x)=x3f(x)=x^3 and g(x)=x2g(x)=x^2, we compute f∗(H)g∗(H)=H\frac{ {}^*f(H) }{ {}^*g(H) } = H, which is unlimited. Therefore x3∈ω(x2)x^3\in \omega(x^2), and hence x3∈Ω(x2)x^3\in\Omega(x^2). In math: f(x)=x3,g(x)=x2:f∗(H)g∗(H)=Hunlimited⇒x3∈ω(x2)⊆Ω(x2).f(x)=x^3,\ g(x)=x^2:\ \frac{ {}^*f(H) }{ {}^*g(H) } = H\ \text{unlimited}\ \Rightarrow\ x^3\in \omega(x^2)\subseteq\Omega(x^2).

For f(x)=x+cf(x)=x+c, where cc is any standard real number, and g(x)=xg(x)=x, we compute f∗(H)g∗(H)=1+cH\frac{ {}^*f(H) }{ {}^*g(H) } = 1+\tfrac{c}{H}. Since cH\tfrac{c}{H} is infinitesimal, we have f∗(H)g∗(H)≈1\frac{ {}^*f(H) }{ {}^*g(H) } \approx 1. Therefore x+c∈Θ(x)x+c\in\Theta(x). In math: f(x)=x+c,g(x)=x:f∗(H)g∗(H)=1+cH≈1⇒x+c∈Θ(x).f(x)=x+c,\ g(x)=x:\ \frac{ {}^*f(H) }{ {}^*g(H) } = 1+\tfrac{c}{H}\approx 1\ \Rightarrow\ x+c\in\Theta(x).

The "for every unlimited HH" condition encodes the usual "for all sufficiently large xx" via transfer. A single infinite index can be fooled by oscillations; checking every unlimited HH gives you the uniformity you need.

For example, let g(x)=xg(x)=x and define ff by parity of the integer part:

  • if ⌊x⌋\lfloor x\rfloor is even, set f(x)=xf(x)=x;
  • if ⌊x⌋\lfloor x\rfloor is odd, set f(x)=xlog⁡(x+2)f(x)=\dfrac{x}{\log(x+2)}.

Then ff is eventually positive, and the ratio f(x)g(x)\dfrac{f(x)}{g(x)} oscillates between 11 (on even blocks) and 1log⁡(x+2)\dfrac{1}{\log(x+2)} (on odd blocks). A single check at an even unlimited HH gives f∗(H)g∗(H)=1\dfrac{ {}^*f(H) }{ {}^*g(H) } = 1 and could tempt you to say f∈Θ(g)f\in\Theta(g). But along odd unlimited HH we have f∗(H)g∗(H)=1log⁡(H+2)≈0\dfrac{ {}^*f(H) }{ {}^*g(H) } = \dfrac{1}{\log(H+2)}\approx 0, so f∉Ω(g)f\notin\Omega(g) and hence f∉Θ(g)f\notin\Theta(g), even though f∈O(g)f\in O(g). In math: along even HH, f∗(H)g∗(H)=1\frac{ {}^*f(H) }{ {}^*g(H) } = 1; along odd HH, f∗(H)g∗(H)=1/log⁡(H+2)≈0\frac{ {}^*f(H) }{ {}^*g(H) } = 1/\log(H+2)\approx 0. Requiring the condition for every unlimited HH prevents this mistake.