Esc
  • Loading…
↑ ↓ to moveEnter to openEsc to close

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