Recursion is probably the most famous concepts in computer science since it’s quite fun!
In this text, I’ll explain recursion and its differing types and show you some famous examples.
Recursion is when a function calls itself, however the input will typically change. So, because the function is looking itself, it’s referred to as a recursive function.
You’re essentially breaking down the issue into more minor problems, that are solved independently but added together step-by-step.
Just about every recursive function may be written in a loop format, however the recursive framing is commonly rather more elegant!
A Russian Doll may be considered a recursion, as each doll incorporates one other doll, then that one incorporates one other etc.
Recursion could technically go on endlessly, but there are sometimes some stopping criteria that prevent this. Otherwise, the pc will quickly run out of memory!
On the whole, a recursive function has two things:
- Base Case — Terminating scenario that doesn’t require recursion.