Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Examples of Recursive functions [closed]

Tags:

recursion

Can anybody suggest programming examples that illustrate recursive functions? There are the usual old horses such as Fibonacci series and Towers of Hanoi, but anything besides them would be fun.

like image 882
Codeslayer Avatar asked Sep 24 '08 12:09

Codeslayer


People also ask

What is the closed form of a recursive function?

Many recursive numerical formulas have a closed form, i.e. an equivalent expression that doesn't involve recursion (or summation or the like). Some- times you can find the closed form by working out the first few values of the function and then guessing the pattern.

Which is example of recursive function?

Simple examples of a recursive function include the factorial, where an integer is multiplied by itself while being incrementally lowered. Many other self-referencing functions in a loop could be called recursive functions, for example, where n = n + 1 given an operating range.


1 Answers

This illustration is in English, rather than an actual programming language, but is useful for explaining the process in a non-technical way:

 A child couldn't sleep, so her mother told a story about a little frog,   who couldn't sleep, so the frog's mother told a story about a little bear,      who couldn't sleep, so bear's mother told a story about a little weasel        ...who fell asleep.      ...and the little bear fell asleep;   ...and the little frog fell asleep; ...and the child fell asleep. 
like image 87
ConroyP Avatar answered Sep 21 '22 07:09

ConroyP