RECURSION
THEORY
To understand recursion, you must first understand recursion. It is the art of solving a large problem by solving smaller instances of the same problem.
The Stack
The Tower of Hanoi is the quintessential recursive problem. It cannot be solved easily with loops, but with recursion, the logic is elegant: Move $n-1$ disks out of the way, move the bottom disk, then move $n-1$ disks back on top.
Tower of Hanoi
The Base Case
Base Case
The stopping condition. Without this, the recursion continues forever (Infinite Loop) until the program crashes.
Recursive Step
The part of the function where it calls itself with a modified (usually smaller) input.
Call Stack
The memory structure that tracks active subroutines. Recursion pushes new layers onto the stack until the base case is reached.
Memoization
Optimization technique. Storing the results of expensive function calls so you don't have to recalculate them (e.g., caching Fibonacci numbers).