11.1 The Basics of Recursion
TIARA
—TIARA is a recursive acronym.
The TTP Project
—DILBERT
It often turns out that a natural way to design an algorithm involves using the same algorithm on one or more subcases. For example, the following is an outline of an algorithm for searching for a name in a phone book: Open the phone book to the middle of the book. If the name is on that page, you are done. If the name is alphabetically before that page, search the first half of the book. If the name is alphabetically after that page, search the second half of the book. Searching half of the phone book is a smaller version of the original task of searching the entire phone book.
Whenever an algorithm has one subtask that is a smaller version of the entire ...
Get Java: An Introduction to Problem Solving and Programming, 8th 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.