Consider the following functions: f(n) = 3n√n g(n) = 2√n log₂ n h(n) = n!…
2000
Consider the following functions:
f(n) = 3n√n
g(n) = 2√n log₂ n
h(n) = n!
Which of the following is true?
Answer: D. f(n) is O(g(n)) — Concept. Big-O states an upper bound in the limit: t(n) is O(u(n)) exactly when constants c > 0 and n0 exist such that t(n) ≤ c·u(n) for every n ≥ n0. Two…
- A.
h(n) is O(f(n))
- B.
h(n) is O(g(n))
- C.
g(n) is not O(f(n))
- D.
f(n) is O(g(n))
Attempted by 14 students.
Show answer & explanation
Correct answer: D
Concept. Big-O states an upper bound in the limit: t(n) is O(u(n)) exactly when constants c > 0 and n0 exist such that t(n) ≤ c·u(n) for every n ≥ n0. Two consequences follow straight from that definition. A fixed positive constant factor never changes the bound, so if t(n) = k·u(n) for a constant k > 0, then each of the two functions is O of the other. And two powers of the same base are compared through their exponents, using axy = (ax)y together with 2log₂ n = n.
Application. The three functions are put on one common scale before any of the four statements is examined.
Rewrite g(n) as a power of n: 2√n log₂ n = 2log₂ n · √n = (2log₂ n)√n = n√n, because 2log₂ n = n.
Compare that with f(n): f(n) = 3n√n = 3·g(n), so the two differ by nothing more than the fixed factor 3.
Apply the constant-factor consequence: f(n) ≤ 3·g(n) for every n ≥ 1, so f(n) is O(g(n)) with c = 3 and n0 = 1; symmetrically g(n) ≤ f(n), so g(n) is O(f(n)) as well. The two functions are of the same order, f(n) = Θ(g(n)).
Put h(n) = n! on the same scale: by Stirling’s approximation log2(n!) = Θ(n·log2 n), while log2 g(n) = √n·log2 n exactly. The ratio of those two magnitudes is therefore Θ(√n), which grows without bound, so log2(n!) − log2 g(n) → ∞ and hence n!/g(n) → ∞. Since f(n) = 3g(n), n!/f(n) → ∞ as well.
Cross-check. Each of the four statements is now settled against those magnitudes.
Statement | Does it hold? | Why |
|---|---|---|
h(n) is O(f(n)) | No | n!/f(n) → ∞ by step 4, so no constant c keeps n! ≤ c·3n√n for all large n. |
h(n) is O(g(n)) | No | n!/g(n) → ∞ by step 4, so no constant c keeps n! ≤ c·n√n for all large n. |
g(n) is not O(f(n)) | No | g(n) = f(n)/3 ≤ f(n) for every n ≥ 1, so g(n) is O(f(n)) and the negation fails. |
f(n) is O(g(n)) | Yes | f(n) = 3g(n), so c = 3 with n0 = 1 satisfies the definition. |
Result. The single true statement is that f(n) is O(g(n)).
Common slip. The shape of g(n) looks exponential, which invites the reading that it outgrows the polynomial-looking f(n). Rewriting 2√n log₂ n as n√n removes that impression: its exponent √n·log2 n is a base-2 logarithm scaled by √n, not a constant multiple of n.
Explore the full course: Iocl Engineers Officers Grade A Paper 2