Recursion
11. Recursion#
Engineer is problem solving at heart. When we discussed functions, we were approaching problem-solving by breaking a problem into smaller pieces, each problem was solved in a function. Each function solved a different problem, and eventually integrating the functions together lead to a solution to the bigger problem.
In recursion, we break a problem into a smaller version of the same problem repeatedly till the problem is small enough to be solved easily. Solutions to smaller problems can be combined easily to form the solution of the bigger problem. For this to happen, we will observe a function calling itself but on a smaller problem/input. We discuss in this chapter what is recursion, why we need recursive functions, and how to write a recursive function.