Recursion is a tool in programming used to replicate a similar action in a repetitive way. It will break the task down over and over until it is small enough to complete. These smaller tasks which once made up the bigger task will be easier to compute then added up again the bigger task is solved as well. Some examples that could make recursion very useful tools are problems like; the fibonacci sequence, factorials, and the tower of hanoi, amongst several others. All these problems involve breaking down big numeric problems into smaller tasks, then solving the smaller task. Though recursion does make these more complicated tasks easier to manage it does have its downsides. Recursion is not so easy to understand or write. Secondly there are things about the stack you have to worry about such as stack overflows and such.
Recursion is the act of repeating itself over an over, but this would seem to go on forever. The simple solution o this problem is a base case. The base case is an unchanging condition set in place for when the bigger problem gets broken down enough where it would not make any sense to go further. For an example we can use the factorial. The factorial formula is (n * (n - 1)*...*1). But we know that the special case for factorial is 0, since the factorial of 0 is 0. This would act as our base case in this instance. It will yield our small sections of the bigger problem to at the minimum 0. This giving us a recursive result.
This idea of recursion has been a great milestone in all programming over the ages. It gives people the ability to take great tasks and make them several small easy ones thus making them much asker to compute.
No comments:
Post a Comment