Recursion
A function that calls itself on a smaller input until a base case, each call parked as a frame until the one above it returns.
Decision · step 2 of 14The Call Stack: Summing a list recursively
The list starts with 3. Keep it, and call sum on the remaining 4 numbers. A smaller problem each time.
What you will see
CALL -> new frame -> ... -> BASE CASE -> RETURN -> frame pops, value flows up.
Cost
| Space | O(depth) |
|---|
How you work with it here
play it through, step one change at a time, scrub to any step, run it on your own input.
Screen readers: Each frame announces its function, arguments and depth; each step announces a call or a return with its value.
Reduced motion: Frames appear and disappear with crossfades instead of sliding.
Before this
Leads to
Topics that need this one first.
Taught by the same lesson
The Call Stack covers these too, in the same run.