August 2017
Intermediate to advanced
222 pages
5h 3m
English
While previous examples of the NASA countdown and calculating factorials can be solved with recursion, they can also be easily solved with classical loops. While recursion is interesting, it doesn’t really provide an advantage when solving these problems.
However, recursion is a natural fit in any situation where you find yourself having to repeat an algorithm within the same algorithm. In these cases, recursion can make for more readable code, as you’re about to see.
Take the example of traversing through a filesystem. Let’s say that you have a script that does something with every file inside of a directory. However, you don’t want the script to only deal with the files inside the one directory—you want it to act on all ...