The Recursive Paradigm
if (test for a simple case)
{
Compute and return the simple solution without using recursion.
}
else
{
Divide the problem into one or more subproblems that have the same form.
Solve each of the problems by calling this method recursively.
Return the solution from the results of the various subproblems.
}
Finding a recursive solution is mostly a matter of figuring out how to break it down so that it fits the paradigm.When you do so, you must do two things:
1. Identify simple cases that can be solved without recursion.
2. Find a recursive decomposition that breaks each instance of the problem into simpler sub problems of the sametype, which you can then solve by applying the method recursively.
No comments:
Post a Comment