5.2. Writing a recursive function¶
5.2.1. Writing a recursive function¶
Solving a “big” problem recursively means to solve one or more smaller versions of the problem, and using those solutions of the smaller problems to solve the “big” problem. In particular, solving problems recursively means that smaller versions of the problem are solved in a similar way. For example, consider the problem of summing values of an array. What’s the difference between summing the first 50 elements in an array versus summing the first 100 elements? You would use the same technique. You can even use the solution to the smaller problem to help you solve the larger problem.
Here are the basic four steps that you need to write any recursive function.
Now le’t see some different ways that we could write Sum
recursively.