Is Recursion Efficient?
Calling a method involves certain overhead. Control must be transferred from the location of the call to the beginning of the method.
In addition, the arguments to the method and the address to which the method should return must be pushed onto an internal stack so that the method can access the argument values and know where to return.
If there are a large number of method calls as a result of a recursive method, it might be desirable to eliminate the recursion.
Another inefficiency is that memory is used to store all the intermediate arguments and return values on the system’s internal stack. This may cause problems if there is a large amount of data, leading to stack overflow.
Recursion is usually used because it simplifies a problem conceptually, not because it’s inherently more efficient.