Data Structures & AlgorithmsHardTCS NQT Digital · Product Company SDE

Problem: A function has T(n) = T(n − 1) + T(n − 2) + O(1) without memoisation. What is its growth?

  1. A. Θ(n²)
  2. B. Θ(φⁿ) ≈ Θ(1.618ⁿ) – exponential
  3. C. Θ(2ⁿ) exactly
  4. D. Θ(n log n)

Correct answer: B. Θ(φⁿ) ≈ Θ(1.618ⁿ) – exponential

The call tree has fib(n)-many leaves, which grows like φⁿ. It is O(2ⁿ) as an upper bound, but the tight bound is φⁿ. Memoisation turns it into Θ(n).

More Coding Interview Problems questions

Exams that ask this topic