computer-science/recursion-why-fib-30-makes-2-7-million-calls-and-how-a-notebook-fixes.md

Recursion: why fib(30) makes 2.7 million calls, and how a notebook fixes it

Computer science · 5 min read ·

A function that calls itself sounds like an endless loop, but it works when every call gets a smaller problem and one case is simple enough to answer directly.

Step through the calls of a Fibonacci function, see why computing fib(30) takes 2,692,537 calls, and watch a simple notebook of remembered answers cut that to 59.

A tree of circles showing every recursive call to fib(5), with repeated calls highlighted in orange

$ ls computer-science/

see all →