CHAPTER 9

Mutual Recursion

Alone we can do so little, together we can do so much.

—Helen Keller

A method that invokes itself directly within its body is recursive, by definition. However, a recursive method does not necessarily have to call itself. It may call another one that in turn calls it back. Thus, invoking the method can provoke multiple calls to it. This type of recursion is called mutual or indirect.

In general, several methods are mutually recursive when they invoke themselves in a cyclical order. For instance, consider a set of methods { f 1 , f 2 , , f n } . If f 1 calls f 2 , f 2 calls f 3 , and so on, and finally f n calls back f 1 , then the methods are said to be mutually recursive. ...

Get Introduction to Recursive 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.