Fibonacci Numbers

Naive recursion (exponential) vs DP loop (O(n)) vs Fast doubling (O(log n))

Naive: O(φn) DP loop: O(n) Fast doubling: O(log n)
Result F(n)
-
Operations
0
Step
0 / 0
Method cost
-
pending / value computing done window / set bit repeated work

Recursion Tree

Explanation

Choose a method, set n, and press Run or Step.

Complexity Comparison

MethodTimeSpaceMults / bitUse when
Naive recursionO(φn)O(n)never (teaching)
DP loopO(n)O(1)n up to ~106
Matrix exponentiationO(log n)O(1)~8any linear recurrence
Fast doublingO(log n)O(log n)~3plain Fibonacci, huge n

Operation Log