Reducible on YouTube · Open on YouTube
Foundations: programming and problem solving · Novice · Lesson 12 of 98 · 21 min video, then about 4 hours of practice
Recursion and thinking in smaller subproblems
After this you can write a recursive function with a correct base case and explain how the call stack unwinds.
Why it matters
Recursion is a function that solves a problem by calling itself on a smaller version of the same problem. It is the natural way to work with trees and nested data, which turn up everywhere: the DOM, file systems, JSON, comment threads. Focus on the method: define the base case, assume the recursive call works for a smaller input, and combine. Draw the call stack on paper for a small input until it stops feeling magical. Trap: forgetting the base case, or recursing on something that does not get smaller. Both give you a stack overflow.
How to use this resource
The best explanation of how to think about recursive problems rather than just what recursion is.