Skip to main content

Posts

Showing posts with the label Recursion in C

Recursion in C

Recursion is a method of solving problems that involves breaking a problem down into smaller and smaller sub problems until you get to a small enough problem that it can be solved trivially. Usually recursion involves a function calling itself. While it may not seem like much on the surface, recursion allows us to write elegant solutions to problems that may otherwise be very difficult to program. It is legal for one function to call another, and you have seen several examples of that. It is also legal for a function to call itself. It may not be obvious why that is a good thing, but it turns out to be one of the most magical and interesting things a program can do. A recursive function is one that calls itself directly or indirectly to solve a smaller version of its task until a final call which does not require a self call. What is needed for implementing recursion? Decomposition into smaller problem of same type. Recursive calls must diminish problem size. Necessity of base c