August 2024
Intermediate to advanced
516 pages
11h 47m
English
This brings us to the central point of this chapter: recursion shines when implementing a top-down approach because going top-down offers a new mental strategy for tackling a problem. That is, a recursive top-down approach allows one to think about a problem in a completely different way.
Specifically, when we go top-down, we get to mentally “kick the problem down the road.” We can free our mind from some of the nitty-gritty details we normally have to think about when going bottom-up.
To see what I mean, let’s take another look at the key line from our top-down factorial implementation:
| | return number * factorial(number - 1); |
This line of code makes its calculation based on factorial(number - 1). When ...
Read now
Unlock full access