Types of recursion
There are several different recursion types and terms. These include:
- Direct recursion: This is typified by the factorial implementation where the methods call itself.
- Mutual recursion: This happens where one method, say method A, calls another method B, which then calls method A. This involves two or more methods that eventually create a circular call sequence.
- Multi-recursion: Multiple recursive calls are made in the method.
- Head recursion: The recursive call is made at the beginning of the method.
- Tail recursion: The recursive call is the last statement.
Direct recursion is the most common form of recursion. Head and tail recursion are specialized terms for direct and mutual recursion.
Mutual recursion is not as common as other ...
Get Learning Java Functional Programming 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.