Skip to content
DSA Visualizerpreview

Fibonacci 2: memoised recursion

Same recursion, but each answer is saved; a repeat call is a lookup instead of a subtree.

O(n) time · O(n) space

n5

fib(5) is not in the memo yet: recurse.

Call tree for fib(5) with a memo: 1 calls so far. Memo: empty.
  1. fib(5): not in the memo: recurse
  • compare
  • swap or write
  • settled

1 / 14

Speed

Space play · ← → step · Home End jump · drag the strip to scrub