
Recursion is a process that applies the same rule to a smaller or simpler problem of the same kind, then returns the results through the layers. To calculate the total size of a folder, we add the files it contains. When we meet a subfolder, we apply the same rule again. Only when a folder contains no further subfolders can the calculation begin to combine its way outwards.
This is not ordinary repetition. Repetition may perform the same action many times; recursion requires the current problem to contain a subproblem that can be handled in the same form. It also differs from a feedback loop, where a result changes the next action. Recursion concerns the way a problem is nested within itself.
Every recursive process needs a stopping condition, and each step must move closer to it. Otherwise it expands without end or exhausts its resources. The idea matters beyond programming. Family relations, linguistic syntax and layered reasoning can all contain the same relation at deeper levels. Recursion lets finite rules generate complex structures, but that complexity remains workable only because the layers have a boundary.
Discover more from Geoffrey Chen
Subscribe to get the latest posts sent to your email.