What is the time complexity of a recursive algorithm to compute the Fibonacci sequence?

Quick Overview

Asks for the running time of the direct recursive Fibonacci algorithm and how to improve it. Tests whether you can turn the call tree into a recurrence, give a tight bound, and explain what memoization or a bottom-up loop changes in time and space.

What is the time complexity of a recursive algorithm to compute the Fibonacci sequence?

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: easy

Interview Round: Other

What is the time complexity of a recursive algorithm to compute the Fibonacci sequence? Take the direct version that computes F(n) by calling itself on n - 1 and n - 2, with F(0) = 0 and F(1) = 1. Explain where the cost comes from, and how it can be reduced. ```hint Draw the call tree Sketch the calls made for a small n such as 5 and count how often each subproblem is computed. Then write a recurrence for the total number of calls. ``` ### What a Strong Answer Covers - The recurrence for the running time of the direct recursive version and how fast it grows - The difference between the loose upper bound and the tight bound - Why the work is wasted: the same subproblems are recomputed many times - What memoization or a bottom-up loop does to time and space - The space used by the recursion stack ### Follow-up Questions - How many calls exactly does the direct version make to compute F(n)? - Can you compute F(n) with fewer than O(n) arithmetic operations? - What happens in Python if you call the memoized recursive version with n = 100,000, and how would you avoid it? - F(n) grows to roughly 0.694n bits. How does that change the real cost of the linear loop?

Overview: Asks for the running time of the direct recursive Fibonacci algorithm and how to improve it. Tests whether you can turn the call tree into a recurrence, give a tight bound, and explain what memoization or a bottom-up loop changes in time and space.

General logo
General
Nov 24, 2026
easySoftware EngineerOtherSoftware Engineering Fundamentals
0
0

What is the time complexity of a recursive algorithm to compute the Fibonacci sequence?

Take the direct version that computes F(n) by calling itself on n - 1 and n - 2, with F(0) = 0 and F(1) = 1. Explain where the cost comes from, and how it can be reduced.

What a Strong Answer Covers Guidance

  • The recurrence for the running time of the direct recursive version and how fast it grows
  • The difference between the loose upper bound and the tight bound
  • Why the work is wasted: the same subproblems are recomputed many times
  • What memoization or a bottom-up loop does to time and space
  • The space used by the recursion stack

Follow-up Questions Guidance

  • How many calls exactly does the direct version make to compute F(n)?
  • Can you compute F(n) with fewer than O(n) arithmetic operations?
  • What happens in Python if you call the memoized recursive version with n = 100,000, and how would you avoid it?
  • F(n) grows to roughly 0.694n bits. How does that change the real cost of the linear loop?