Part II – Recursive Functions

--Originally published at TC101 – Peaz Cooper

Well well well! First of all! Ask yourself the following questions:

Do you know what recursive functions? I like squirtle! Together we will learn the answers to these awesome and mind-blowing questions!


Recursion is a way of programming or coding a problem, in which a function calls itself one or more times in its body. Usually, it is returning the return value of this function call. If a function definition fulfills the condition of recursion, we call this function a recursive function.

The adjective “recursive” originates from the Latin verb “recurrere”, which means “to run back”. And this is what a recursive definition or a recursive function does: It is “running back” or returning to itself. Most people who have done some mathematics, computer science or read a book about programming will have encountered the factorial, which is defined in mathematical terms as

n! = n * (n-1)!, if n > 1 and f(1) = 1

Example:
4! = 4 * 3!
3! = 3 * 2!
2! = 2 * 1

Replacing the calculated values gives us the following expression
4! = 4 * 3 * 2 * 1

Generally, we can say: Recursion in computer science is a method where the solution to a problem is based on solving smaller instances of the same problem.The possible combinations quickly multiply out to unimaginably large numbers. Indeed, the repertoire of sentences is theoretically infinite, because the rules of language use a trick called recursion. A recursive rule allows a phrase to contain an example of itself, as in She thinks that he thinks that they think that he knows and so on, ad infinitum. And if the number of sentences is infinite, the number of possible thoughts and intentions is infinite too, because virtually every sentence expresses a

thought or intention.”1

We have to stop our short excursion to recursion in natural languages to come back to recursion in computer science and finally to recursion in the programming language Python. (wiki)


If you follow these steps you’ll be coding like a bawse in no time!!!

#PeazCooperOut #TC101