COSC 2306: Data Programming - Recursive Branching Call Stack Visualizer
Default values match the exact execution tree shown on Slide 9.
Unlike the Factorial function, which makes a single linear line of recursive calls, this Fibonacci implementation
makes two recursive calls inside its general case: rFibNum(n-1) + rFibNum(n-2).
(n-1) until a base case is hit, before ever attempting the right branch (n-2).rFibNum(2,3,2) are evaluated multiple times! This redundancy leads to an exponential \(O(2^n)\) time complexity.cache dictionary prevents recalculating a node that has already been split and solved.
def rFibNum(a, b, n):
if n == 1:
return a
elif n == 2:
return b
else:
return rFibNum(a, b, n-1) + rFibNum(a, b, n-2)