Algorithmic Sequences & Recursion

Deconstruct recursion, monitor executing call stacks in real time, and investigate memoization caching strategies.

Call Stack & Recursion Sandbox

Toggle between the **Fibonacci Call Tree** to inspect tree-size reduction via memoization, or **Towers of Hanoi** to study structural recurrence properties.

Puzzle Completed! 🎉

You successfully moved all disks in 0 moves.

Animation Speed 1x

Fibonacci Parameters

Target Term (N) 5
Enable Memoization

Dynamic Metric Log

Active Call Term: F(5) = ?
Total Call Count: 0

Active Call Stack

Shows function frames pushed/popped from stack:
  • Stack empty

Recurrence Mathematical Properties

Inspect recursive relationships, complexity scaling factors, and code mappings.

Recurrence Formulations


Fibonacci Sequence Recurrence:
F(n) = F(n-1) + F(n-2) ;   F(0)=0,   F(1)=1
Evaluating $F(n)$ requires solving two smaller subproblems. In naive recursion, this creates a recursive call tree that duplicates computational paths exponentially.
Towers of Hanoi Recurrence:
T(n) = 2T(n-1) + 1 ;   T(1)=1
Moving $n$ disks requires moving $n-1$ disks to the aux peg ($T(n-1)$), moving the largest disk to the destination ($1$), and moving the $n-1$ disks to the destination ($T(n-1)$). This yields a closed-form solution of $T(n) = 2^n - 1$.

Computational Complexities


Complexity Growth Matrix:
Algorithm Time Space (Stack)
Naive Fibonacci O(2n) O(n)
Memoized Fibonacci O(n) O(n)
Iterative Fibonacci O(n) O(1)
Towers of Hanoi O(2n) O(n)
Memoization improves time complexity by caching, at the expense of $O(n)$ space complexity for storage.

Recursion Conceptual Quiz

Assess your understanding of base cases, stack sizes, and algorithmic recurrences.

Question 1 of 5 Score: 0/0

What is the primary purpose of a recursion "base case"?

Correct Answer!

Focus Vocabulary


  • Base Case: The termination hook which bypasses recursion to return a static value directly.
  • Call Stack: The system memory stack frames containing local variables and return paths.
  • Memoization: Top-down caching algorithm storing solved subproblems to prevent recalculations.