Recursion
Although many programmers and even computer science students have a difficult time understanding recursion, the concept is actually quite simple. Plainly stated, recursion is repeatedly performing the same operation by having the method of that operation invoke itself. Therefore, any function that calls an instance of itself is a recursive function. As a matter of fact, if a function f()
calls another function g()
which in turn may call function f()
again, this is still a recursive function because f()
eventually calls itself. Recursion is an excellent tool for solving complex problems where the solution to the problem is based on the solution to smaller examples of the same problem.
The concept of recursion, or recursive functions, is so powerful that almost every modern computer language supports it by providing the ability for a method to call itself. However, before you define a recursive function, you should be aware any function that calls itself could very easily become...