Recursion is one of the most famous concepts in computer science because it is quite fun.
In this article, I will explain recursion and its different types and show you some famous examples.
Recursion is when a function calls itself, but the input will usually change. So since the function calls itself, it is known as a recursive function.
Basically, you are breaking the problem into smaller problems, which are solved independently but add up step by step.
Virtually all recursive functions can be written in a loop format, but the recursive framework is usually much more elegant!
TO russian doll It can be considered a recursion, since each doll contains another doll, then that one contains another, etc.
Technically, recursion could continue forever, but there are often some stopping criteria that prevent this. Otherwise, the computer will quickly run out of memory.
In general, a recursive function does two things:
- base case — Terminal scenario that does not require recursion.