# ch18 - For some problems its useful to have a method call...

This preview shows pages 1–5. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
For some problems, it’s useful to have a method call itself. Known as a recursive method . Can call itself either directly or indirectly through another method. Figure 18.1 summarizes the recursion examples and exercises in this book.
When a recursive method is called to solve a problem, it actually is capable of solving only the simplest case(s), or base case(s) . If the method is called with a base case, it returns a result. If the method is called with a more complex problem, it typically divides the problem into two conceptual pieces a piece that the method knows how to do and a piece that it does not know how to do. To make recursion feasible, the latter piece must resemble the original problem, but be a slightly simpler or smaller version of it. Because this new problem looks like the original problem, the method calls a fresh copy of itself to work on the smaller problem this is a recursive call also called the recursion step

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
The recursion step normally includes a
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 18

ch18 - For some problems its useful to have a method call...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online