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 ...

Get Sams Teach Yourself Ruby in 21 Days now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.