Close
Register
Close Window

Show Source |    | About   «  7.1. Introduction   ::   Contents   ::   7.3. Code Completion Practice Exercises  »

7.2. Writing a recursive function

7.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.

Settings

Proficient Saving... Error Saving
Server Error
Resubmit

Now le’t see some different ways that we could write Sum recursively.

Settings

Proficient Saving... Error Saving
Server Error
Resubmit

   «  7.1. Introduction   ::   Contents   ::   7.3. Code Completion Practice Exercises  »

Close Window