Fibonacci
斐波那契数列
Two recursive calls per non-base call. The call tree explodes — but the code reads like the math.
Python · runnable
Why it's slow
Each call makes two recursive calls. The call tree for
fib(5) evaluates fib(3) twice and fib(1)
five times. For n = 30 the function makes over a million
calls; for n = 50, billions.
The iterative version — linear time