Java Reference
In-Depth Information
m1
m2
m3
m1
m2
m3
m1
m2
m3
FIGURE 12.4 Indirect recursion
SELF-REVIEW QUESTIONS (see answers in Appendix N)
SR 12.6
Is recursion necessary?
SR 12.7
When should recursion be avoided?
SR 12.8
Describe what is returned by the following recursive method.
private static int exercise ( int n)
{
if (n < 0)
return -1;
else
if (n < 10)
return 1;
else
return 1 + exercise (n/10);
}
SR 12.9 Write a recursive method that returns the value of 5 * n, where
n > 0. See Self-Review Question 12.5. Explain why you would not
normally use recursion to solve this problem.
SR 12.10 What is indirect recursion?
12.3 Using Recursion
Each of the following sections describes a particular recursive problem. For each
one, we examine exactly how recursion plays a role in the solution and how a
base case is used to terminate the recursion. As you examine these examples,
consider how complicated a non-recursive solution for each problem would be.
 
Search WWH ::




Custom Search