A Common-Sense Guide to Data Structures and Algorithms, Second Edition, 2nd Edition
by Jay Wengrow
Recursive Category: Repeatedly Execute
Over the course of tackling various recursive problems, I began to find that there are various “categories” of problems. Once I learned an effective technique for a certain category, when I found another problem that belonged to the same category, I was able to apply the same technique to solve it.
The category that I found to be the easiest was one in which the goal of the algorithm was to repeatedly execute a task.
The NASA spacecraft countdown algorithm from the previous chapter is a great example of this. The code prints a number such as 10, and then 9, then 8, all the way down to 0. While the number the function prints is different each time, we boil down the code’s essence to the fact that it is repeatedly ...
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