We call an object recursive if it contains itself, or if it is defined by itself. Recursion is a programming technique in which a method makes a call to itself to solve a particular problem. Such methods are called recursive.
The calculation of factorial is often given as an example when explaining the concept of recursion, but in this case, as in many others, recursion is not the best approach. Very often, if we are given a recurrent definition of the problem, the
recurrent solution is intuitive and not posing any difficulty, while iterative (consecutive) solution is not always obvious.
In this particular case the implementation of the iterative solution is as short and simple, but is a bit more efficient:
If the algorithm solving of the problem is recursive, the implementation of recursive solution can be much more readable and elegant than iterative solution to the same problem.
Note : Recursion is powerful programming technique, but we have to think carefully before using it. If used incorrectly, it can lead to inefficient and tough to understand and maintain solutions.
We adding new programming language tutorials very soon.
We make a Collaboration with HackIsOn YouTube Channel So, Please Subscribe Their Channel and keep supporting