Mutual_recursion Mutual_recursion

Mutual recursion - Definition and Overview

Mutual recursion is a form of recursion where two mathematical or computational functions are defined in terms of each other.

For instance, consider two functions A(x) and B(x) defined as follows:

 A(x) = 1         (when x≤1)
 A(x) = B(x + 2)  (when x>1)
 B(x) = A(x - 3) + 4

Mutual recursion is very common in the functional programming style, and is often used for programs written in LISP, Scheme, ML, and similar languages. In languages such as Prolog, mutual recursion is almost unavoidable.

Some programming styles discourage mutual recursion, claiming that it can be confusing to distinguish the conditions which will return an answer from the conditions that would allow the code to run forever without producing an answer.

Example Usage of recursion

p11e: RT @ideamonk Take care of recursion limits while doing programming contest problems in Python http://is.gd/56LfX | use sys.setrecursionli..
ideamonk: Take care of recursion limits while doing programming contest problems in Python http://is.gd/56LfX | use sys.setrecursionlimit( ... )
julianflores: To understand recursion, one must first understand recursion. http://www.google.com/search?hl=en&q=recursion
Copyright 2009 WordIQ.com - Privacy Policy  :: Terms of Use  :: Contact Us  :: About Us
This article is licensed under the GNU Free Documentation License. It uses material from the this Wikipedia article.