Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any example of Mutual recursion?

Tags:

recursion

Are there any examples for a recursive function that calls an other function which calls the first one too ?

Example :

function1()
{    
    //do something 
    function2();
    //do something
}

function2()
{
    //do something 
    function1();
    //do something
}
like image 561
Hannoun Yassir Avatar asked Apr 27 '10 20:04

Hannoun Yassir


People also ask

Where are we most likely to find mutual recursion?

Mutual recursion is very common in functional programming, and is often used for programs written in LISP, Scheme, ML, and similar programming languages.

What is an example of recursion?

A classic example of recursionThe factorial of a number is computed as that number times all of the numbers below it up to and including 1. For example, factorial(5) is the same as 5*4*3*2*1 , and factorial(3) is 3*2*1 .

What are some examples of recursion in real life?

You do this in real life all the time. Imagine you have a whole box full of $100 bills and you need to count how much money you have. Since it's a lot, you might ask for the help of your friend, and you divide the stack in two. When you both finish counting, you add up your results and get the final number.

What is mutual recursion in Java?

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.

Which is an example of indirect recursion?

For instance, function A calls function B, which calls function C. If function C, under any circumstances, calls back to function A, this is a case of indirect recursion.


1 Answers

An example might be the minmax algorithm commonly used in game programs such as chess. Starting at the top of the game tree, the goal is to find the maximum value of all the nodes at the level below, whose values are defined as the minimum of the values of the nodes below that, whose values are defines as the maximum of the values below that, whose values ...

like image 181
I. J. Kennedy Avatar answered Oct 23 '22 21:10

I. J. Kennedy