6. Recursion

Recursion is a programming technique in which a method (function) calls itself. This may sound like a strange thing to do, or even a catastrophic mistake. Recursion is, however, one of the most interesting, and one of the most surprisingly effective, techniques in programming. Like pulling yourself up by your bootstraps (you do have bootstraps, don’t you?), recursion seems incredible when you first encounter it. However, it not only works, it also provides a unique conceptual framework for solving many problems.

In this chapter we’ll examine ...

Get Data Structures and Algorithms in Java, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.