Recursion
Data that contains smaller copies of itself, nested as deep as it likes: folders, menus, replies to replies. Every one of these is solved by a function that calls itself on a smaller piece and knows when to stop, and every one has a way to get the stopping wrong.
—Exercises
9 exercises
Flatten a list of lists of lists
recursion, base case
~20 min
Add up numbers hidden at any depth
recursion, base case
~15 min
How deep does it go?
recursion, max of the answers
~15 min
Every way to choose from a list
recursion that branches, building new lists
~25 min
Every order the letters can go in
permutations, recursion that branches
~25 min
Find it in a sorted list by halving
binary search, recursion on a range
~25 min
How much space is this folder using?
recursion over a tree, two kinds of node
~20 min
Move the tower, one disc at a time
recursion with two calls, trusting the smaller call
~25 min
Sort a list by splitting it in half
divide and conquer, merging two sorted lists
~30 min