Recursion & Backtracking
Learn how a function that calls itself really runs — the call stack, the call tree and the memory it costs — then use backtracking to explore every choice and solve the classic interview puzzles.
- 5 Lessons
- 20 Problems
- 46 Illustrations
What you will learn
- What recursion is: the base case, the recursive case and the leap of faith
- How a recursive call runs on the call stack, and how much memory recursion really uses
- The kinds of recursion — linear, tail, tree and divide and conquer — and the order a call tree is walked
- Backtracking as a depth-first walk of a decision tree: choose, explore, un-choose, and prune
- 5 patterns: recursion basics, recursive thinking, subsets and combinations, permutations, and grids and boards
- The recursion and backtracking interview questions asked most, from Fibonacci to Sudoku Solver
Why this course
Recursion solves a problem by solving smaller copies of the same problem. Backtracking uses recursion to try choices one at a time and undo the ones that don't lead anywhere — the engine behind every "generate all" and puzzle-solving interview question.
The introduction shows how recursion runs — the call stack, the call tree it walks, and the memory every call costs — and how backtracking explores a tree of choices, with a drawing and a simulator for each.
Then come 5 patterns, from easiest to hardest, each taught through the interview questions that use it, with code in four languages, the time and space of every approach and a simulator that draws the tree being explored.
Requirements
- Comfort writing functions, loops and conditionals in at least one language
- Arrays and strings basics; the Stack course helps for the call stack
- No prior recursion needed — it's built up from the first call
Course Contents
2. Pattern 1 · Recursion basics
3. Pattern 2 · Recursive thinking
4. Pattern 3 · Subsets and combinations
5. Pattern 4 · Permutations and building strings
6. Pattern 5 · Grids and boards
Related courses
- Dynamic ProgrammingTurning exponential brute force into polynomial time by remembering what you've already solved.5 lessons · 21 problems
- Binary TreeHierarchical structures for representing nested relationships and enabling fast search.5 lessons · 16 problems
- StackLast-in, first-out — the structure behind call stacks, undo history, and expression parsing.6 lessons · 13 problems
