Summary
Today we learned about recursion and discussed its advantages and disadvantages. We explored memoization as a way to make recursive code remember past results, thus speeding it up dramatically in some situations.
Remember, recursion is your friend. Faced with a journey of a great distance, the iterative thinker says “This is going to take a lot of steps,” but the recursive thinker says “I will take one step, then start a brand-new journey that is slightly shorter than this one.” Guess who suffers less stress.
When you have a knotty logic problem in front of you, be on the lookout for ways to divide it into a recurrence relation (what “one step” in the solution should look like) and a base case (how you can recognize when the task is almost ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access