Master recursive thinking, base cases, and the call stack before tackling trees and graphs.
Recursion is a function that calls itself to solve a smaller version of the same problem. Every recursive solution has a base case (the simplest input that can be answered directly) and a recursive case (breaking the problem into smaller pieces). Most tree and graph problems are naturally recursive.
Depends on number of recursive calls and work per call
O(d) where d is the maximum recursion depth
Learn the core patterns in this topic. Each block explains when to use the pattern, the intuition behind it, and a compact code example.
the stopping condition; without it the function runs forever
call the same function with a smaller/simpler input
each call adds a frame; too many calls causes a stack overflow
assume the recursive call works correctly on smaller input
draw the call tree to understand execution order
define the function as "given this input, return this output"
cache results to avoid recomputing the same sub-problems
any recursion can be converted to iteration using an explicit stack