7.6 Recursive Algorithms
When an algorithm uses its own name within itself, it is called a recursive algorithm. That is, if a task name at one level calls itself, the call is known as a recursive call. Recursion—the ability of an algorithm to call itself—is an alternative control structure to repetition (looping). Rather than use a looping statement to execute an algorithm segment, such an algorithm uses a selection statement to determine whether to repeat the algorithm by calling it again or to stop the process.
Each recursive algorithm has at least two cases: the base case and the general case. The base case is the one to which we have an answer; the general case expresses the solution in terms of a call to itself with a smaller version ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access