Find a nondecreasing function that’s O(n^2), Omega(n), and where those bounds can’t be improved

Viewed 95

Is there a function f (possibly real-valued) such that f is

  1. O(n2),
  2. not o(n2),
  3. Ω(n),
  4. not ω(n), and
  5. nondecreasing?

(That is, f is big-O of n2, not little-o of n2, big-Omega of n, not little-omega of n, and nondecreasing).

1 Answers

Essentially, you’re looking for a function that

  1. has a tight quadratic upper bound,
  2. has a tight linear lower bound, and
  3. is nondecreasing.

Here’s one way to do this. Imagine drawing out the curves n and n2. Now, draw your function f by first following the curve n2 for some period of time, then drawing a horizontal line until you hit the curve n and tracing along that curve for a bit, then jump vertically to n2 and follow that curve for a bit, repeating this process out to infinity. That is, we're looking for something like this:

A function that moves vertically to hit n2, then horizontally to hit n, etc.

The net effect of this is the following:

  1. The n2 curve is a tight asymptotic upper bound on f. The curve infinitely often takes on the value of n2 and never exceeds n2. That makes f(n) = O(n2) but not o(n2).

  2. The n curve is a tight asymptotic lower bound on f. The curve infinitely often takes on the value of n but never drops below n. That makes f(n) = Ω(n) but not ω(n).

  3. The function is nondecreasing.

The tricky part here is finding an exact formula for such a curve. We can do this using a recursive definition. The basic idea is the following:

  1. Whenever f(n) = n (we’re hugging the bottom curve), we’ll set f(n+1) to (n+1)2 so that we jump to the top curve.
  2. Whenever f(n) > n, we’ll set f(n+1) = f(n). This corresponds to moving horizontally after hitting the top curve until we reach the bottom curve.

This gives us the following recursive definition:

f(0) = 0; f(n) = f(n-1) if n > 1 and f(n-1) > n-1; f(n) = n2 if n > 1 and f(n-1) = n-1.

Here’s the first few values taken on by this function:

0, 1, 4, 4, 4, 25, 25, 25, ..., 25, 676, 676, ...

This was a fun one to work through - hope this helps!

Related