Dynamic Programming21 sections · 916 units
Open in Course

LeetCode 509 Fibonacci - Recursive Formula

Two calls

Here's the recursive formula: fib(n)=fib(n1)+fib(n2)fib(n) = fib(n-1) + fib(n-2). To find the nn-th Fibonacci number, you make two recursive calls and add their results. This creates a branching structure and each call spawns two more calls, which spawn two more, and so on. It matches the mathematical definition exactly.

However, this branching means your call tree grows exponentially. Let me show you what that looks like. The picture is worse than you think.