![]() |
VOOZH | about |
Mutual recursion is a variation recursion. Two functions are called mutually recursive if the first function makes a recursive call to the second function and the second function, in turn, calls the first one.
In software development, this concept is used in circular dependency which is a relation between two or more modules which either directly or indirectly depend on each other to function properly. Such modules are also known as mutually recursive.
A great example of mutual recursion would be implementing the Hofstadter Sequence.
Hofstadter Sequence
In mathematics, a Hofstadter sequence is a member of a family of related integer sequences defined by non-linear recurrence relations. In this example we are going to focus on Hofstadter Female and Male sequences:
Output:
F: 1 0 2 1 3 2 4 3 5 4 6 5 7 6 8 7 9 8 10 9 M: 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10
Disadvantages of Circular Dependency/Mutual Recursion:
References: Wikipedia